This sample demonstrates how to modify voice commands and phrase lists at runtime using a ScheduledTask. A phrase list is a list of phrases that an app recognizes to initiate a command. Updating this list at runtime is useful for cases in which the voice command is specific to a task involving updated data such as a user’s favorites list or updated app data. In this sample, you ask the app whether a particular team is playing by saying a phrase such as “Background App, Are the Tigers playing today?”. The voice command prefix Background App is specified in the app’s Voice Command Definition (VCD) file, which is named BackgroundAppVCD.xml in this project. The list of teams are defined in two phrase lists in the VCD, one for teams that are playing today and one for teams that are not playing today. When you tap Start/Restart Background Update, a background agent is scheduled to run periodically to change the list of teams in the playing and non-playing phrase lists. Asking “Background App, Are the Tigers playing today?” when the background agent has updated the phrase lists, may return a different result depending on whether or not the team Tigers is in the list of teams playing today. The phrase lists are updated directly within the background agent. This is for demonstration purposes only. In a real app, the agent would typically call a web service to get updated data. This sample shows you how to:

 

This sample uses the Windows.Phone.Speech.VoiceCommands Windows Phone Runtime API.

Build the sample

  1. Start Visual Studio Express 2012 for Windows Phone and select File > Open > Project/Solution.

  2. Go to the directory in which you unzipped the sample. Double-click the Visual Studio Express 2012 for Windows Phone solution (.sln) file.

  3. Use Build > Rebuild Solution to build the sample.

Run the sample

  1. To debug the app and then run it, press F5 or use Debug > Start Debugging. To run the app without debugging, press Ctrl+F5 or use Debug > Start Without Debugging.

  2. When the app runs, tap the Install CommandSets button to install the voice commands associated with this app.

  3. Tap and hold the Start button. If the speech privacy policy is displayed, tap accept and then say one of the commands installed with the app. For example, say ”Background App Are the Lions playing today?”

  4. You should hear the app say “Let me check” and then it will return a Yes or No answer. If the app cannot understand what you have said, it will also display No.

  5. To schedule updates to the phrase list that the app can interpret, tap Start/Restart Background Update. To see background updates in operation, stop running the app by either stopping the debugger or exiting the app using the hardware Back button.

  6. After approximately 5 seconds, you should see a toast notification on the main screen of the phone or emulator that reads: VoiceCommandsBackgroundApp Updated Phraselists Successfully!

  7. The app will continue to be updated approximately every 30 minutes and a toast notification will be displayed. To stop background updates you can uninstall the app or tap Stop Background Update in the app or go to Settings | applications | background tasks tap on the sdkSpeechBackgroundAgentWP8CS entry and select block. Note that the system will automatically disable updates from this app if the app hasn’t been run in two weeks.

Notes

  • This sample can run on the Windows Phone 8 Emulator and on a Windows Phone 8 device.

  • When running the sample, make sure the microphone is working.

  • To run this sample, you must accept the speech privacy policy. Tap and hold the Start button, tap the accept button, and then say “What Can I say?”. If you are taken to the “What can I Say screen” and hear text to speech readout of the page, then both the microphone and audio out are working properly. Alternatively, you can manually set the policy via the checkbox under Settings | speech | Enable Speech Recognition Service. Note that you must accept the policy each time you start the emulator.

See also