james icon indicating copy to clipboard operation
james copied to clipboard

Add support for variable hear input

Open blatyo opened this issue 13 years ago • 5 comments

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}"
        end
    end

blatyo avatar Jul 18 '11 12:07 blatyo

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."
    end)
  end
end

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

Cheers

floere avatar Jul 19 '11 05:07 floere

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

Example:

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}"
    end
end

KellyMahan avatar Oct 17 '11 19:10 KellyMahan

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?

Cheers,

floere avatar Oct 17 '11 21:10 floere

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.

KellyMahan avatar Oct 17 '11 21:10 KellyMahan

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").

Cheers!

floere avatar Oct 17 '11 22:10 floere