Giter VIP home page Giter VIP logo

james's Introduction

James

A voice controlled electronic butler

Requirements

  • OSX
  • MacRuby (install rvm, rvm install macruby)

Installation

gem install james (OSX only)

Basics

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.

Examples

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

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.

Short Version

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

Extended Version

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

Contributions are in the /examples folder.
Sending dialogue gists is appreciated. Thanks!

Running the specs

rspec spec

Roadmap

  • Make James (e.g. voice, core dialogue) configurable.
  • Add more useful dialogues made by YOU :)

Ideas

  1. Put it on a Mac Mini, attach a few microphones, distribute in the house.
  2. Create a few useful dialogues, like a train timetable, or similar.
  3. Sit on your sofa, and talk to James out loud.
  4. Send us your dialogues :)

MIT License

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.

james's People

Contributors

alloy avatar floere avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.