Export (0) Print
Expand All
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

Selecting a speech recognizer for Windows Phone 8

Applies to: Windows Phone 8 and Windows Phone Silverlight 8.1 only

Windows Phone 8 includes speech recognizers for a variety of languages. Each speech recognizer performs recognition in a single language, as spoken in a specific country/region. After you create a SpeechRecognizer or SpeechRecognizerUI object, you can specify the language of the speech recognizer to load. A SpeechRecognizer or SpeechRecognizerUI instance can load any voice that is installed on the phone and use it to recognize speech. If no language is specified, the API will load a recognizer that matches the language that the user selected in Settings/Speech on the phone.

The following code example creates an instance of a speech recognizer and sets its language with the help of a LINQ query. The LINQ query searches through the SpeechRecognizerInformation objects that describe each of the installed recognizers to find one with a language property with a value of "fr-FR", which indicates the French language as spoken in France. The variable frenchRecognizers is implicitly typed as a SpeechRecognizerInformation object. The argument to the SetRecognizer(SpeechRecognizerInformation) method specifies an index for the recognizers returned by the LINQ query.

// Declare the SpeechRecognizerUI object at the class level.
SpeechRecognizerUI recoWithUI;

// Handle the button click event.
private async void SpeakFrench_Click_1(object sender, RoutedEventArgs e)
  // Initialize the SpeechRecognizerUI object.
  recoWithUI = new SpeechRecognizerUI();

  // Query for a recognizer that recognizes French as spoken in France.
  IEnumerable<SpeechRecognizerInformation> frenchRecognizers = from recognizerInfo in InstalledSpeechRecognizers.All
                          where recognizerInfo.Language == "fr-FR"
                          select recognizerInfo;
  // Set the recognizer to the top entry in the query result.

  // Create a string array of French numbers.
  string[] nombres = { "un", "deux", "trois", "quatre", "cinq", 
                         "six", "sept", "huit", "neuf", "dix" };

  // Create a list grammar from the string array and add it to the grammar set.
  recoWithUI.Recognizer.Grammars.AddGrammarFromList("frenchNumbers", nombres);

  // Display text to prompt the user's input.
  recoWithUI.Settings.ListenText = "Say a French number";

  // Give an example of ideal speech input.
  recoWithUI.Settings.ExampleText = " 'un', 'deux', 'trois', 'quatre' ";

  // Load the grammar set and start recognition.
  SpeechRecognitionUIResult recoResult = await recoWithUI.RecognizeWithUIAsync();

You can also use the SpeechRecognizerInformation object to set a speech recognizer that matches other property values of installed speech recognizers, such as SpeechRecognizerInformationDescription(), SpeechRecognizerInformationDisplayName(), and SpeechRecognizerInformationId().

© 2015 Microsoft