How can I use voice commands to control my Windows Phone game?

Is it possible to use simple voice commands like "run right", "run left", "jump", "stop", "attack", "defend", "finish" to control the player in a Windows Phone 8 game?

How can I implement voice recognition and some voice commands in my game?

• Cons: reflex speed, people have to talk to their phone in public, it's awkward in general, speech recognition failure. May 30 '14 at 14:37
• Please don't make this the only way to play. May 30 '14 at 14:39
• The "pros and cons" of doing this is a list-generation question, and your question about difficulty is opinion-based (both considered a poor fit for this site). I've edited them out of your question so as to focus on the main interesting query.
– user1430
May 30 '14 at 15:21

Yes, you can use voice commands in Windows Phone 8 applications. It's relatively straightforward, you need to create an XML file that maps spoken commands to actions (a VCD file) and then add the code to initialize the speech subsystem with your definitions file and handle the triggered actions. The definition file contains XML like:

<Command Name="RunDirection">
<Example>Run right</Example>
<ListenFor>Run {direction}</ListenFor>
<Feedback>Running {direction}!</Feedback>
<Navigate Target="/run.xaml"/>
</Command>


(Full reference for the XML schema is available here.)

You then call InstallCommandSetsFromFileAsync to register the commands file, and you accept commands via the OnNavigatedTo hander:

if (NavigationContext.QueryString.ContainsKey("voiceCommandName")) {
if (command == "RunDirection") {

m_player.SetDirection(direction); // ...or whatever.
}
}


Far more complete overviews are available at the MSDN and via this MSDN magazine article.

Note that the system is not well suited to real-time iterative direction like you are suggesting; you invoke the voice commands by hitting the Start button, and saying something like ", run right" (although the prefix is optional).

Further, if the system fails to understand you it may come up with a disambiguation prompt, which will interrupt the action (this may be optional too, I haven't explored it deeply enough).

It's probably not a very good mechanism to control the actual gameplay, although you may be able to use it for things like showing high scores, starting a new game, and so on.

• Is it not possible to use the voice commands without hitting the Start button every time? I don't want to interrupt the game if I want to speak to my character. May 30 '14 at 17:09
• As far as I know, no. But I don't know that much about it (I've only dabbled with them), so it's possible somebody more knowledgeable will know of a way to get around that. If you use a third-party API (I know of none), you may also be able to avoid it.
– user1430
May 30 '14 at 17:14

Yes, it's possible. First find a suitable voice recognition library or use the "built in" option. Then map commands from the voice recognition library to input commands in your game.

As for design implementation, you can look at an existing game, There came an echo. Implementing commands like "run right" or "jump" are likely going to be too challenging to use, since those types of commands are highly dependent on timing.