A voice controlled electronic butler
- OSX
- MacRuby (install rvm,
rvm install macruby
)
gem install james
(OSX only)
James consists of dialog(ue)s that are modeled as state machines. You navigate through these dialog(ue)s by talking to James.
He will then take action (looking up timetables, checking the weather etc.) and inform you. Or maybe just tell a joke.
All examples can be found in /examples.
Create a file called time_dialogue.rb
(or time_dialog.rb
, James doesn’t mind Americans ;) ):
class TimeDialogue
include James::Dialogue
hear 'what time is it?' => :time
state :time do
hear ['What time is it?', 'And now?'] => :time
into { time = Time.now; "It is currently #{time.hour} #{time.min}." }
exit {} # Optional, listed for completeness.
end
end
This says that if James hears (hear
) "What time is it?"
that it should enter this conversation into state :time
.
If he then hears “What time is it?” again, it will return to state :time
.
When he enters (into
), James executes the block in the dialogue’s context. Whatever is returned from the block, James will say out lout. Everything else he will just think. (So it’s like Sinatra in rendering, just that James renders audio)
Here, he will just say the current time when entering the :time
state.
Running it is easy. Either use
require 'rubygems'
require 'james'
# Your dialogue goes here.
James.listen
in your script, and call it by using
ruby time_dialogue.rb
Or else, in the terminal, just call
$ james
and it will include all dialogues (files called _dialog{ue,}.rb
) in this directory and subdirectories. E.g. joke_dialog.rb
, newsfeed_dialogue.rb
, or social_media/tweets_dialog.rb
.
You can select dialogues using their first file name part
$ james time joke twitter
and it will include the time dialogue, the joke dialogue, and the twitter dialogue.
Note: The james
executable looks for files called and includes them.
There is a short, anonymous dialogue version, using James.dialogue
aka James.dialog
.
James.dialogue do
hear 'what time is it?' => :time
state :time do
hear ['What time is it?', 'And now?'] => :time
into { time = Time.now; "It is currently #{time.hour} #{time.min}." }
end
end
Or there is an extended version, using initialize to set up some important stuff that needs other stuff for doing stuff, you know?
require 'james'
class TwitterDialogue
include James::Dialogue
def initialize
@client = Twitter.new 'user', 'password'
end
hear 'What are the birds tweeting?' => :newsfeed
state :newsfeed do
hear 'Who mentions me?' => :mentions
into do
# Complicated feed loading
"People are saying this: #{@client.newsfeed(10).join(' ... ')}"
end
end
state :mentions do
hear ['What is generally said?', 'Back to newsfeed!'] => :newsfeed
into do
# Complicated feed loading
"People are saying this: #{@client.mentions(10).join(' ... ')}"
end
end
end
Contributions are in the /examples folder.
Sending dialogue gists is appreciated. Thanks!
rspec spec
- Make James (e.g. voice, core dialogue) configurable.
- Add more useful dialogues made by YOU :)
- Put it on a Mac Mini, attach a few microphones, distribute in the house.
- Create a few useful dialogues, like a train timetable, or similar.
- Sit on your sofa, and talk to James out loud.
- Send us your dialogues :)
Copyright © 2011 Florian Hanke
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.