public
Description: voice commanded servant
Homepage:
Clone URL: git://github.com/floere/james.git
Click here to lend your support to: james and make a donation at www.pledgie.com !
Florian Hanke (author)
Mon Mar 31 11:29:51 -0700 2008
james / configurator.rb
100644 38 lines (30 sloc) 0.786 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# TODO all
 
# configures
class Configurator
  def self.configure
 
  end
end
 
require 'osx/cocoa'
 
...
 
def initialize
  # get and configure a recognizer interface
  @recognizer = OSX::NSSpeechRecognizer.alloc.init
  @recognizer.setDelegate(self)
  @recognizer.startListening
  # get a synthesizer interface
  @synthesizer = OSX::NSSpeechSynthesizer.alloc.init
end
 
# callback method from the speech interface
def speechRecognizer_didRecognizeCommand( sender, command )
  # do something with the command
  # command needs to be converted to a proper ruby string: command.to_s
end
 
def speak(text)
  # say something using the speech synthesizer
  @synthesizer.startSpeakingString(text)
end
 
state :to, {
  'back' => :from,
  'next train' => :result,
  'nowhere' => :result
}.merge(CITIES)