Launching your WP8 application by voice and navigating to another page

Users can launch an app by using voice i.e speak out the name of the application to start it or lead to another page. For eg. You can enable your app to do this by tapping the start button for a bit long and saying out ‘name of the app’ + ‘start’ to launch it or you can also make it open another page within the app by saying ‘ name of app show page name’. You can use different words as required to perform these actions. You define these commands etc. in a file. The voice command shall always starts with a command and then the next part (start or show) is defined by you. Following are the steps to launch an application by voice:

1. First of all, create a Voice Command Definition (VCD) file by right clicking your project name in solution explorer and selecting add->new item->VCD (under Visual C#), rename it to VoiceCommands and click Add.

VCD1

2. Next, expand the properties in your solution explorer and open WMAppManifest.xml file. Click on the capabilities tab and enable ID_CAP_SPEECH_RECOGNITION, ID_CAP_MICROPHONE, and ID_CAP_NETWORKING to use the voice commands in your app.

3. In the Properties window, set Build action to Content, and then set Copy to output directory to Copy if newer.

4. The default VCD file looks like this:

VCD25. The CommandPrefix is optional but can be set to if we localize our app so that we can initiate the app with the CommandPrefix set according to each language that our app supports.

  • The CommandPrefix should always be pronounceable. For eg. If your app name consists of ‘3’ or ‘_’ etc, you shall not include them in the CommandPrefix.
  • The CommandPrefix’s subset cannot be matched with what you speak. For eg. If you CommandPrefix is VoiceDemo, you cannot say Voice [Phrase] or Demo [Phrase]. But VoiceDemo [phrase] is recognizeable.

6. <ListenFor> tag contains words that are used to initiate the action in the Command element. <Feedback> tag is what will be shown in text while the voice commands is processed. The <Navigate> tag tells where the user will be directed.

7. Hence, our VCD file will have the following code inside Voice command tag:

VCD3

8. Next, initialize the VCD file to register the commands with the system to be listened for. Write the following code in the app.xaml.cs file in the Application_Launching event (Make it an async method):

await VoiceCommandService.InstallCommandSetsFromFileAsync(new Uri(“ms- appx:///VoiceCommands.xml”));

Also add this at the top:

using Windows.Phone.Speech.VoiceCommands;

9. Now when you run the app, press the start button to goto start screen, then again press and hold the start button until ‘Listening…’ screen appears. Say ‘VCD Demo Start’ to navigate directly to main page or say ‘VCD Demo show Page 2’ to navigate to page 2.

And that’s all. Just a few simple steps to launch your app by voice! Happy coding 🙂