Customizing speech recognizer settings for Windows Phone 8

[ This article is for Windows Phone 8 developers. If you’re developing for Windows 10, see the latest documentation. ]

You can adjust the settings of the speech recognizer that control how it responds to the absence of input or to the absence of recognizable input when speech is expected. These settings affect how recognition behaves while it waits for expected speech input at the onset or the conclusion of a speech recognition operation.

This topic contains the following sections.

Speech Recognizer settings

The following table lists and describes the Speech Recognizer settings.

Setting

Description

SpeechRecognizerSettingsInitialSilenceTimeout()()()

The time span that the speech recognizer will wait for speech input if the only input is silence. If the recognizer doesn’t receive recognizable speech before the interval expires, it finalizes the recognition operation. The default setting is 5 seconds.

For example, you may want to adjust the value for the SpeechRecognizerSettingsInitialSilenceTimeout()()() setting to have more or less time elapse while your app waits for a user to begin speaking after a recognition operation has started.

SpeechRecognizerSettingsBabbleTimeout()()()

The time interval during which the speech recognizer will continue to listen while it receives only non-speech input such as background noise. Background noise includes any non-speech input that doesn’t match any active rule in the grammars currently loaded and activated by the speech recognizer.

If the recognizer receives only non-speech input within the babble timeout interval, then it finalizes that recognition operation. The default setting is 0 seconds (the feature is not activated).

SpeechRecognizerSettingsEndSilenceTimeout()()()

The time interval during which the speech recognizer will wait to finalize the recognition operation, after speech has finished and only silence is being received as input. The recognizer has received speech input, but it doesn’t completely match any of the rules in currently loaded and activated grammars. The default setting is 150 milliseconds. Apps typically use the default value for this setting.

Customizing Speech Recognizer settings

The following code example shows how to specify the settings for SpeechRecognizerSettingsInitialSilenceTimeout()()() and SpeechRecognizerSettingsBabbleTimeout()()(). An app typically won’t modify the setting for SpeechRecognizerSettingsEndSilenceTimeout()()().

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

private async void Reco1_Click(object sender, RoutedEventArgs e)
{

  // Initialize the SpeechRecognizerUI object.
  SpeechRecognizerUI recoWithUI = new SpeechRecognizerUI();

  // Set timeout settings.
  recoWithUI.Recognizer.Settings.InitialSilenceTimeout = TimeSpan.FromSeconds(6.0);
  recoWithUI.Recognizer.Settings.BabbleTimeout = TimeSpan.FromSeconds(4.0);
  recoWithUI.Recognizer.Settings.EndSilenceTimeout = TimeSpan.FromSeconds(1.2);


  // Create a string array to use in a grammar. 
  string[] genre = { "rock", "jazz", "classical", "world", "gospel", "Brazilian" };

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

  // Display text to prompt the user's input.
  recoWithUI.Settings.ListenText = "What kind of music?";

  // Give an example of ideal speech input.
  recoWithUI.Settings.ExampleText = " 'rock', 'jazz', 'classical' ";
            
  // Load the grammar set and start recognition.
  SpeechRecognitionUIResult recoResult = await recoWithUI.RecognizeWithUIAsync();
}

Timeout settings apply to a single instance of SpeechRecognizer or SpeechRecognizerUI, and persist while the instance is active. A new instance of SpeechRecognizer or SpeechRecognizerUI will have its timeouts set to the default values.

Warning

Timeout settings have no effect when using the predefined dictation or web search grammars.

See Also

Other Resources

Speech recognition for Windows Phone 8

Speech for Windows Phone 8