Class: James::Inputs::Audio
Instance Attribute Summary
Attributes inherited from Base
Instance Method Summary collapse
- #heard(command) ⇒ Object
-
#initialize(controller) ⇒ Audio
constructor
A new instance of Audio.
- #listen ⇒ Object
- #recognize_new_commands ⇒ Object
-
#speechRecognizer(sender, didRecognizeCommand: command) ⇒ Object
Callback method from the speech interface.
Methods inherited from Base
Constructor Details
#initialize(controller) ⇒ Audio
Returns a new instance of Audio.
7 8 9 10 11 12 13 |
# File 'lib/james/inputs/audio.rb', line 7 def initialize controller super controller @recognizer = NSSpeechRecognizer.alloc.init @recognizer.setBlocksOtherRecognizers true @recognizer.setListensInForegroundOnly false @recognizer.setDelegate self end |
Instance Method Details
#heard(command) ⇒ Object
19 20 21 22 23 24 25 |
# File 'lib/james/inputs/audio.rb', line 19 def heard command super # Set recognizable commands. # recognize_new_commands end |
#listen ⇒ Object
15 16 17 18 |
# File 'lib/james/inputs/audio.rb', line 15 def listen @recognizer.startListening recognize_new_commands end |
#recognize_new_commands ⇒ Object
34 35 36 37 38 39 40 41 |
# File 'lib/james/inputs/audio.rb', line 34 def recognize_new_commands possibilities = controller.expects puts "Possibilities:\n" possibilities.each_with_index do |possibility, index| puts "#{index + 1}) #{possibility}" end @recognizer.setCommands possibilities end |
#speechRecognizer(sender, didRecognizeCommand: command) ⇒ Object
Callback method from the speech interface.
Note: Uses a MacRuby only form.
31 32 33 |
# File 'lib/james/inputs/audio.rb', line 31 def speechRecognizer sender, didRecognizeCommand: command heard command end |