-
Notifications
You must be signed in to change notification settings - Fork 430
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
138 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
from kivy.app import App | ||
from kivy.uix.boxlayout import BoxLayout | ||
from plyer import stt | ||
from kivy.lang import Builder | ||
Builder.load_string(''' | ||
<STTDemo>: | ||
Button: | ||
text: "Start listening" | ||
on_release: root.start() | ||
Button: | ||
text: "Stop listening" | ||
on_release: root.stop() | ||
Button: | ||
text: "Set Commands" | ||
on_release: root.set_command() | ||
Button: | ||
text: "commands title" | ||
on_release: root.commands_title() | ||
Button: | ||
text: "commands" | ||
on_release: root.commands() | ||
''') | ||
|
||
|
||
class STTDemo(BoxLayout): | ||
|
||
def start(self): | ||
stt.start_listening() | ||
|
||
def stop(self): | ||
stt.stop_listening() | ||
|
||
def set_command(self): | ||
stt.set_commands() | ||
|
||
def commands_title(self): | ||
print stt.display_commands_title() | ||
|
||
def commands(self): | ||
print stt.display_commnds() | ||
|
||
|
||
class SpeechToTextApp(App): | ||
def build(self): | ||
return STTDemo() | ||
|
||
if __name__ == '__main__': | ||
SpeechToTextApp().run() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
from plyer.facades import STT | ||
from pyobjus import autoclass, objc_arr, objc_str, protocol, selector | ||
from pyobjus.dylib_manager import load_framework, INCLUDE | ||
|
||
load_framework(INCLUDE.AppKit) | ||
|
||
NSSpeechRecognizer = autoclass('NSSpeechRecognizer') | ||
NSString = autoclass('NSString') | ||
|
||
|
||
class SpeechToText(STT): | ||
|
||
def _ns(self, x): | ||
NSString.alloc().initWithUTF8String_(x) | ||
|
||
def _start_listening(self, **kwargs): | ||
self.obj = NSSpeechRecognizer.alloc() | ||
self.obj.init() | ||
# self.obj_delegate = NSSpeechRecognizerDelegate | ||
self.obj.commands = ["a", "b", "c"] | ||
self.obj.setDelegate_(self) | ||
self.obj.startListening() | ||
|
||
# foo(NSSpeechRecognizerDelegate, "") | ||
|
||
@protocol('NSSpeechRecognizerDelegate') | ||
def speechRecognizer_didRecognizeCommand_(self, sender, command): | ||
print command | ||
try: | ||
cnt = command.allObjects().count() | ||
for i in range(cnt): | ||
print command.allObjects().objectAtIndex_(i).UTF8String() | ||
except: | ||
pass | ||
|
||
def _set_commands(self): | ||
self.obj.commands = ["a", "b", "c"] | ||
self.obj.setCommands_ = ["a", "b", "c"] | ||
|
||
def _display_commands_title(self): | ||
return self.obj.delegate | ||
# return self.obj.displayedCommandsTitle | ||
|
||
def _display_commnds(self): | ||
return self.obj.commands | ||
|
||
def _stop_listening(self, **kwargs): | ||
self.obj.stopListening() | ||
print "Not Listening" | ||
|
||
|
||
def foo(name, string): | ||
matching = [] | ||
matching = [s for s in dir(name) if "{}".format(string) in s] | ||
for m in matching: | ||
print m | ||
|
||
|
||
def instance(): | ||
return SpeechToText() |