In addition to the SpeechRecognizerUI Settings
property, the SpeechRecognizer
also provides a Settings
property that allows you to adjust how it responds to the silence or the absence of recognizable input during speech recognition.
The SpeechRecognizerSettings
class provides the following three properties:
InitialSilenceTimeout
is a Timespan
that represents the amount of time that the speech recognizer will remain waiting when all it hears is silence. If the speech recognizer does not detect recognizable speech before the interval expires, it finalizes the recognition operation. The default value is 5 seconds. In some cases, you may want to increase this value when you want to give the user more time to think about a response.
BabbleTimeout
is a Timespan
representing the amount of time that the speech recognizer continues to listen while it receives only nonspeech input, such as background noise. Babble includes any speech that does not match any active rule in the grammars currently loaded and activated by the speech recognizer.
If the recognizer receives only nonspeech input for the duration of the BabbleTimeout
value, it finalizes that recognition operation. The default setting is 0 seconds, which means that the feature is not activated by default. Set the property to a value greater than 0 to activate it.
EndSilenceTimeout
is a Timespan
representing the amount of time that the speech recognizer waits to finalize the recognition operation, after speech has finished and only silence is being received as input. This timeout is reached when the speech recognizer has received speech input, but has not matched any of the rules in the active grammars. The default value is 150 milliseconds.
Note
InitialSilenceTimeout
, BabbleTimeout
, and EndSilenceTimeout
have no effect when using the dictation or web search grammars.
The following excerpt demonstrates how to set the values of the SpeechRecognizerSettings
following the creation of a SpeechRecognizerUI
instance:
async Task<SpeechRecognizerUI> GetSpeechRecognizerUI()
{
if (recognizerUI == null)
{
recognizerUI = new SpeechRecognizerUI();
SpeechRecognizer recognizer = recognizerUI.Recognizer;
string path = Path.Combine(Package.Current.InstalledLocation.Path,
@"SpeechVoicePaintSrgsVoicePaintGrammar.xml");
Uri uri = new Uri(path, UriKind.Absolute);
recognizer.Grammars.AddGrammarFromUri("CoreGrammar", uri);
SpeechRecognizerSettings settings = recognizer.Settings;
settings.InitialSilenceTimeout = TimeSpan.FromSeconds(5.0);
settings.BabbleTimeout = TimeSpan.FromSeconds(3.0);
settings.EndSilenceTimeout = TimeSpan.FromSeconds(1.4);
await recognizerUI.Recognizer.PreloadGrammarsAsync();
}
return recognizerUI;
}
Timeout
settings pertain to a single instance of the SpeechRecognizer
and persist while the instance is active. A new instance of the SpeechRecognizer
class or the SpeechRecognizerUI
class has its timeout values set to the default values.
18.117.11.240