Initialize and Manage a Speech Recognition Engine
The System.Speech.Recognition namespace provides applications with access to two types of speech recognition engine. The SpeechRecognizer class provides access only to the shared recognition engine resident in Windows. The SpeechRecognitionEngine class provides access to any installed speech recognition engine.
Use the SpeechRecognizer class to extend or augment existing speech or audio behavior provided by the shared recognition on a user's computer. Implementations of the shared recognizer are subject to the recognizer's state and the constraints placed by other consumers of the shared speech recognition resident in Windows.
Use the SpeechRecognitionEngine class for applications that need exclusive control of speech recognition, running in-process with the application, that is independent of the shared speech recognition resident in Windows.
Using the Shared Recognizer
The constructor of the SpeechRecognizer class provides access to the shared recognizer in Windows, which performs speech recognition for any Windows application.
Not all of the configuration options of the shared recognizer are under control of the application. For example, applications managing the shared recognizer with a SpeechRecognizer instance do not configure its audio input; the user does this in the Windows Control Panel. Also, applications do not have control over the properties of the shared recognizer that affect recognition, such as confidence thresholds. These properties are stored as user settings in the Windows registry and should not be modified by an application.
To prepare the SpeechRecognizer instance to perform recognition, load a grammar into the recognizer using the LoadGrammar(Grammar) or LoadGrammarAsync(Grammar) method and set the recognizer’s Enabled property. The recognizer is now listening for speech. Your application can register for events and implement event handlers that receive notification of the outcome of recognition operations, including whether speech was recognized or rejected. See Use Speech Recognition Events.
Speech recognition operations produce multiple recognition result candidates, evaluate the accuracy of each result candidate with respect to the spoken input, and return the recognition candidate that most likely matches the received speech. You can set the number of alternate recognitions to return using the MaxAlternates property.
You can pause a SpeechRecognizer instance while it is running, for example to load or unload a grammar, using one of the RequestRecognizerUpdate() methods.
The shared recognition engine normalizes textual recognition results to display in accordance with cultural conventions, see the ReplacementText class.
For more information about using the shared recognizer, see Determine Whether a Speech Recognizer Is Running and Overriding Built-in Commands.
Using an In-Process Recognizer
Use an in-process recognizer to gain additional control over recognizer configuration and recognition operations. An in-process recognizer is for the sole use of the process that instantiated the object.
You can use the parameters provided by constructors of the SpeechRecognitionEngine class to select a recognizer that matches specific criteria, such as language-culture, the recognizer name, and other attributes.
Take the following basic steps to prepare a SpeechRecognitionEngine instance for a recognition operation:
Set the type of input to receive, see Audio Input for Recognition.
Load a grammar using the LoadGrammar(Grammar) or LoadGrammarAsync(Grammar) methods.
Register for recognition events and create handlers for the events, see Use Speech Recognition Events.
Start recognition using the Recognize() or RecognizeAsync() methods.
To stop an asynchronous recognition operation, use the RecognizeAsyncCancel() or RecognizeAsyncStop() methods. You can pause a running SpeechRecognitionEngine instance to update its configuration or to load and unload grammars using one of the RequestRecognizerUpdate() methods.
To fine-tune how the recognizer responds to background noise and silence that accompanies speech input, set the values of the BabbleTimeout, EndSilenceTimeout, and EndSilenceTimeoutAmbiguous properties.
You can control the number of alternate recognition results that the speech engine returns by setting the MaxAlternates property. You can also query the settings of a speech recognition engine that affect recognition, such as confidence thresholds, using the QueryRecognizerSetting(String) method and modify those settings with one of the UpdateRecognizerSetting() methods.