Skip to content
Browse files

+ prototyping

  • Loading branch information...
1 parent 5d75520 commit 77e03fe09dbaa4ec6ae0033f0161075d5a104443 @floere committed May 10, 2011
Showing with 25 additions and 24 deletions.
  1. +15 −2 examples/time_dialogue.rb
  2. +1 −1 james.gemspec
  3. +6 −7 lib/james/controller.rb
  4. +1 −1 lib/james/dialogue_api.rb
  5. +1 −1 lib/james/inputs/audio.rb
  6. +1 −12 test_project/time_dialogue.rb
View
17 examples/time_dialogue.rb
@@ -11,9 +11,22 @@
#
# How could you enhance it to answer "What date is it?" ?
#
-class TimeDialogue
+# class TimeDialogue
+#
+# include James::Dialogue
+#
+# hear 'What time is it?' => :time
+# state :time do
+# hear ['What time is it?', 'What time is it now?'] => :time
+# into do
+# time = Time.now
+# "It is currently #{time.hour} #{time.min}."
+# end
+# end
+#
+# end
- include James::Dialogue
+James.dialogue do
hear 'What time is it?' => :time
state :time do
View
2 james.gemspec
@@ -5,7 +5,7 @@ Gem::Specification.new do |s|
s.platform = Gem::Platform::CURRENT
s.name = 'james'
- s.version = '0.0.4'
+ s.version = '0.0.5'
s.author = 'Florian Hanke'
s.email = 'florian.hanke+james@gmail.com'
View
13 lib/james/controller.rb
@@ -15,6 +15,9 @@ class Controller
attr_reader :visitor
+ # This puts together the core dialogue and the user
+ # ones that are hooked into it.
+ #
def initialize
user_visitor = initialize_dialogues.visitor
system_visitor = Visitor.new CoreDialogue.new.state_for(:awake)
@@ -23,7 +26,6 @@ def initialize
def applicationDidFinishLaunching notification
load_voices
-
start_output
start_input
end
@@ -48,11 +50,10 @@ def load_voices
# male: com.apple.speech.synthesis.voice.Bruce
end
+ # Initialize and "parse" the
+ # dialogues.
+ #
def initialize_dialogues
- # Create the main dialogue.
- #
- # Everybody hooks into this, then.
- #
dialogues = Dialogues.new
dialogues.resolve
dialogues
@@ -106,8 +107,6 @@ def listen
# window.display
# window.orderFrontRegardless
- app.delegate.applicationDidFinishLaunching nil
-
app.run
end
# Simply put, if there is a controller, it is listening.
View
2 lib/james/dialogue_api.rb
@@ -19,7 +19,7 @@ module Dialogue; end
class << self
def dialogue &block
- dialogue = Class.new { include Dialogue }
+ dialogue = Class.new { include James::Dialogue }
dialogue.class_eval &block
dialogue
end
View
2 lib/james/inputs/audio.rb
@@ -9,12 +9,12 @@ def initialize controller
@recognizer = NSSpeechRecognizer.alloc.init
@recognizer.setBlocksOtherRecognizers true
@recognizer.setListensInForegroundOnly false
- recognize_new_commands
@recognizer.setDelegate self
end
def listen
@recognizer.startListening
+ recognize_new_commands
end
def heard command
super
View
13 test_project/time_dialogue.rb
@@ -9,15 +9,4 @@ class TimeDialogue
into { time = Time.now; "It is currently #{time.hour} #{time.min}." }
end
-end
-
-# James.dialogue do
-#
-# end
-#
-# equals
-#
-# Class.new do
-# include James::Dialogue
-#
-# end
+end

0 comments on commit 77e03fe

Please sign in to comment.
Something went wrong with that request. Please try again.