This speech recognition sample demonstrates how to define and use a custom grammar for speech recognition. The grammar is a static XAML document that complies with the Speech Recognition Grammar Specification (SRGS) Version 1.0. This grammar schema provides a powerful set of tools that allow you to create grammars for speech recognition scenarios ranging from basic to complex. For more info about this grammar schema, see SRGS Grammars for Windows Phone 8. This sample uses a grammar that contains four alternate paths and demonstrates the full range of grammar complexity that can be used by your app. To use the sample, tap the mic and speak a phrase to change colors for the background, border and text of the box displayed in the UI. For example, saying ”blue background” will change the background color of the box to blue. Saying “blue background, red border, white text” will change the background color to blue, the border of the box to red and the text in the box to white. This sample shows you how to:

  • How to create alternate paths in a grammar

  • Check recognition confidence

  • Confirm user input

  • Use the EndSilenceTimeout property to allow users to pause when speaking longer phrases

The grammar for this sample is defined in the Colors.grxml file in the project and defines four alternate grammar paths. These are:

  • Level 1: This demonstrates simple matching of one phrase from a list of alternatives. This is a simple grammar that defines 3 colors and facilitates changing the background color of a text box. For example, tapping the mic button and saying “blue” will change the color of the text in the box to blue.

  • Level 2: This demonstrates how to process semantics in the recognition result. This grammar has 2 rules and some rule references with semantics that facilitates changing the color of the background, border, and text. The color choices must be made in order, i.e. the user must say "blue background, yellow border, red text".

  • Level 3: This grammar path introduces repeats, nesting elements, uses special GARBAGE and NULL rules and contains rules for which one or more phrases can be spoken to match the grammar.

  • Level 4: Accepts phrase syntaxes that place the text box feature before the color selection. For example, a user could say: "Make the background blue, the border green, and the text orange".

This sample uses the Windows.Phone.Speech.Recognition Windows Phone Runtime API. For more info about the speech feature in Windows Phone 8, see Speech for Windows Phone 8.

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

  • 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.

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. Press and hold the Start button, press 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