iDevGames Forums

Full Version: NSSpeechRecognizer
You're currently viewing a stripped down version of our content. View the full version with proper formatting.

mdavis1982

Hi guys...

First, excuse me if this is in the wrong thread. I'm still pretty new here, and this may affect me entering the 'blind' competition on http://www.createmacgames.org, so I put it in the game development thread!

Anyway...

I have successfully implemented NSSpeechRecognizer into my application. It works with the predefined commands I've set up in the code. This all works fine. My question is this:

In the Apple docs it mentions responding to commands such as "Schedule a meeting with John and Adam tomorrow at 10 o'clock". Now, I don't think you would specifiy a command of that nature in the code. Suppose you had a contact list of 1000 people from which to schedule meetings!

So, how do I get my command to take a parameter? For example, say I had a command called "Say the word", the user may say "Say the word cat". Obviously if they said this the application wouldn't respond because it isn't a defined command!

So, I'm stuck!

Any ideas or clues would be greatly appreciated!

Cheers,

Matt
I don't have the actual code on it right now, but here is how I think it could be done. Instead of defining each and every commands, break up what commands do into parts. Say for your game, you have the command 'look'. When the user says look, the computer automatically changes the available commands to 'look left', 'look right', 'look forward', 'look behind you'. Left, right, forward, behind you are all predefined values, modifiers that tell the game whatever action you are doing is in that direction. Now, look is of course, the action, it's what you are doing.

When you say look, the game knows you want to look at something, so it finds the array of modifiers available for look (for the sake of this example, only the directions and a gun (called at gun) are in this array). So your game creates new commands by adding all these modifiers to look, in different strings (look at gun, look left, ect), and then changes the currently set commands (the Apple docs say that this happens instantly, so it should take place before the user can finish his command).

Now, when your user says look left, the computer should understand look, and the modifier will tell it how to change the behavior of look.
Unfortunately the functionality you want is only available through the Carbon Speech Recognition Manager. Eventually (no time soon) I plan to write a Cocoa wrapper for it, though if you want this now, you'll have to get your hands dirty and learn some Carbon.
Davis, you may very well have to give up the idea of dynamic commands, if only for now, and just hard-code all your commands. As Kelvin said, you could do it in Carbon (or write a wrapper), but considering the time length of the project, I wouldn't suggest it.

mdavis1982

Okay...

Thanks for the all the help. In Justin's example, I don't think that would work, because wouldn't the user have to say: "Look", then the commands would be changed, then the user would have to say "Look Left" or whatever?

The Apple Docs definitely say that this is possible using the Cocoa NSSpeechRecognizer, it just doesn't give examples on how to do it.

But, I'll take your advice and leave it for the minute!

Cheers,

Matt
Reference URL's