Add support for variable hear input #10

blatyo opened this Issue Jul 18, 2011 · 5 comments

3 participants


It would be useful if what james could hear wasn't static. For example, imagine you could ask james a question:

    hear "What time will it be in (x)" => :time # What time will it be in 2 hours
    state :time do |time_delta|
        into do
          delta, delta_type = time_delta.split(' ') # => "2", "hours"
          time = delta.to_i.send(delta_type.to_sym).from_now # 2.hours.from_now
          "It will be #{time} in #{time_delta}"

Hi Allen,

I think so too – however, at the moment you are limited to something like this:

hear "Calculate time" => :time

state :time do
  10.downto(1).each do |i|
    hear "What time will it be in #{i} hours?" => (->() do
      "It will be #{i.hours.from_now} in #{i} hours."

For one of the immediate next versions, I will add into/exit block arguments, where the heard phrase is passed in.



Is it possible to have a drill down type of listening with a wildcard speech to text option? I know the evals shouldn't be used here, but its the simplest way to portray my idea. And I'm not familiar with james at all other than the example code. This is just an example usage that programmatically could be very useful


hear "What time will it be in" => :time

state :time do
    hear 2.words => :time_input
    state :time_input do |num, time_period|
        "It will be #{eval("num.#{time_period}.from_now")} in #{num} #{time_period}"

Hi Kelly,

I am afraid not (yet). Currently, the thing you can do is enumerate all possibilities, as with the example code in my last response. It enumerates all 10 options in a succinct way.

Does this help a bit?



Sorry i should have phrased it a bit better. I was asking the question as in do you think it would be possible in the future with development based solely on the current tools? Or would it take different libraries to make that type of implementation possible.


Thanks for the clarification!
No, I am afraid not. Using the current underlying library, I cannot arrive at variable hear input other that using static definitions.

However, with the possible arrival of Siri, and possible related libraries, it might be possible in the future. If yes, I am happy for any input (and notification that it is possible), and will update James' API accordingly.

Sidenote: It was once possible using the Carbon API, but as voice recognition was quite shaky, they didn't carry it over to Cocoa (that is my assumption based on trying it 7 years ago, when James was "born").


Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment