SpeechRecognitionEngine SpeechRecognitionEngine SpeechRecognitionEngine SpeechRecognitionEngine Class

Definition

Provides the means to access and manage an in-process speech recognition engine.

public ref class SpeechRecognitionEngine : IDisposable
public class SpeechRecognitionEngine : IDisposable
type SpeechRecognitionEngine = class
    interface IDisposable
Public Class SpeechRecognitionEngine
Implements IDisposable
Inheritance
SpeechRecognitionEngineSpeechRecognitionEngineSpeechRecognitionEngineSpeechRecognitionEngine
Implements

Examples

The following example shows part of a console application that demonstrates basic speech recognition. Because this example uses the Multiple mode of the RecognizeAsync method, it performs recognition until you close the console window or stop debugging.

using System;  
using System.Speech.Recognition;  

namespace SpeechRecognitionApp  
{  
  class Program  
  {  
    static void Main(string[] args)  
    {  

      // Create an in-process speech recognizer for the en-US locale.  
      using (  
      SpeechRecognitionEngine recognizer =  
        new SpeechRecognitionEngine(  
          new System.Globalization.CultureInfo("en-US")))  
      {  

        // Create and load a dictation grammar.  
        recognizer.LoadGrammar(new DictationGrammar());  

        // Add a handler for the speech recognized event.  
        recognizer.SpeechRecognized +=   
          new EventHandler<SpeechRecognizedEventArgs>(recognizer_SpeechRecognized);  

        // Configure input to the speech recognizer.  
        recognizer.SetInputToDefaultAudioDevice();  

        // Start asynchronous, continuous speech recognition.  
        recognizer.RecognizeAsync(RecognizeMode.Multiple);  

        // Keep the console window open.  
        while (true)  
        {  
          Console.ReadLine();  
        }  
      }  
    }  

    // Handle the SpeechRecognized event.  
    static void recognizer_SpeechRecognized(object sender, SpeechRecognizedEventArgs e)  
    {  
      Console.WriteLine("Recognized text: " + e.Result.Text);  
    }  
  }  
}  

Remarks

You can create an instance of this class for any of the installed speech recognizers. To get information about which recognizers are installed, use the static InstalledRecognizers method.

This class is for running speech recognition engines in-process, and provides control over various aspects of speech recognition, as follows:

The SpeechRecognitionEngine object is for the sole use of the process that instantiated the object. By contrast, the SpeechRecognizer shares a single recognizer with any application that wants to use it.

Note

Always call Dispose before you release your last reference to the speech recognizer. Otherwise, the resources it is using will not be freed until the garbage collector calls the recognizer object's Finalize method.

Constructors

SpeechRecognitionEngine() SpeechRecognitionEngine() SpeechRecognitionEngine() SpeechRecognitionEngine()

Initializes a new instance of the SpeechRecognitionEngine class using the default speech recognizer for the system.

SpeechRecognitionEngine(CultureInfo) SpeechRecognitionEngine(CultureInfo) SpeechRecognitionEngine(CultureInfo) SpeechRecognitionEngine(CultureInfo)

Initializes a new instance of the SpeechRecognitionEngine class using the default speech recognizer for a specified locale.

SpeechRecognitionEngine(RecognizerInfo) SpeechRecognitionEngine(RecognizerInfo) SpeechRecognitionEngine(RecognizerInfo) SpeechRecognitionEngine(RecognizerInfo)

Initializes a new instance of the SpeechRecognitionEngine using the information in a RecognizerInfo object to specify the recognizer to use.

SpeechRecognitionEngine(String) SpeechRecognitionEngine(String) SpeechRecognitionEngine(String) SpeechRecognitionEngine(String)

Initializes a new instance of the SpeechRecognitionEngine class with a string parameter that specifies the name of the recognizer to use.

Properties

AudioFormat AudioFormat AudioFormat AudioFormat

Gets the format of the audio being received by the SpeechRecognitionEngine.

AudioLevel AudioLevel AudioLevel AudioLevel

Gets the level of the audio being received by the SpeechRecognitionEngine.

AudioPosition AudioPosition AudioPosition AudioPosition

Gets the current location in the audio stream being generated by the device that is providing input to the SpeechRecognitionEngine.

AudioState AudioState AudioState AudioState

Gets the state of the audio being received by the SpeechRecognitionEngine.

BabbleTimeout BabbleTimeout BabbleTimeout BabbleTimeout

Gets or sets the time interval during which a SpeechRecognitionEngine accepts input containing only background noise, before finalizing recognition.

EndSilenceTimeout EndSilenceTimeout EndSilenceTimeout EndSilenceTimeout

Gets or sets the interval of silence that the SpeechRecognitionEngine will accept at the end of unambiguous input before finalizing a recognition operation.

EndSilenceTimeoutAmbiguous EndSilenceTimeoutAmbiguous EndSilenceTimeoutAmbiguous EndSilenceTimeoutAmbiguous

Gets or sets the interval of silence that the SpeechRecognitionEngine will accept at the end of ambiguous input before finalizing a recognition operation.

Grammars Grammars Grammars Grammars

Gets a collection of the Grammar objects that are loaded in this SpeechRecognitionEngine instance.

InitialSilenceTimeout InitialSilenceTimeout InitialSilenceTimeout InitialSilenceTimeout

Gets or sets the time interval during which a SpeechRecognitionEngine accepts input containing only silence before finalizing recognition.

MaxAlternates MaxAlternates MaxAlternates MaxAlternates

Gets or sets the maximum number of alternate recognition results that the SpeechRecognitionEngine returns for each recognition operation.

RecognizerAudioPosition RecognizerAudioPosition RecognizerAudioPosition RecognizerAudioPosition

Gets the current location of the SpeechRecognitionEngine in the audio input that it is processing.

RecognizerInfo RecognizerInfo RecognizerInfo RecognizerInfo

Gets information about the current instance of SpeechRecognitionEngine.

Methods

Dispose() Dispose() Dispose() Dispose()

Disposes the SpeechRecognitionEngine object.

Dispose(Boolean) Dispose(Boolean) Dispose(Boolean) Dispose(Boolean)

Disposes the SpeechRecognitionEngine object and releases resources used during the session.

EmulateRecognize(RecognizedWordUnit[], CompareOptions) EmulateRecognize(RecognizedWordUnit[], CompareOptions) EmulateRecognize(RecognizedWordUnit[], CompareOptions) EmulateRecognize(RecognizedWordUnit[], CompareOptions)

Emulates input of specific words to the speech recognizer, using text in place of audio for synchronous speech recognition, and specifies how the recognizer handles Unicode comparison between the words and the loaded speech recognition grammars.

EmulateRecognize(String) EmulateRecognize(String) EmulateRecognize(String) EmulateRecognize(String)

Emulates input of a phrase to the speech recognizer, using text in place of audio for synchronous speech recognition.

EmulateRecognize(String, CompareOptions) EmulateRecognize(String, CompareOptions) EmulateRecognize(String, CompareOptions) EmulateRecognize(String, CompareOptions)

Emulates input of a phrase to the speech recognizer, using text in place of audio for synchronous speech recognition, and specifies how the recognizer handles Unicode comparison between the phrase and the loaded speech recognition grammars.

EmulateRecognizeAsync(RecognizedWordUnit[], CompareOptions) EmulateRecognizeAsync(RecognizedWordUnit[], CompareOptions) EmulateRecognizeAsync(RecognizedWordUnit[], CompareOptions) EmulateRecognizeAsync(RecognizedWordUnit[], CompareOptions)

Emulates input of specific words to the speech recognizer, using an array of RecognizedWordUnit objects in place of audio for asynchronous speech recognition, and specifies how the recognizer handles Unicode comparison between the words and the loaded speech recognition grammars.

EmulateRecognizeAsync(String) EmulateRecognizeAsync(String) EmulateRecognizeAsync(String) EmulateRecognizeAsync(String)

Emulates input of a phrase to the speech recognizer, using text in place of audio for asynchronous speech recognition.

EmulateRecognizeAsync(String, CompareOptions) EmulateRecognizeAsync(String, CompareOptions) EmulateRecognizeAsync(String, CompareOptions) EmulateRecognizeAsync(String, CompareOptions)

Emulates input of a phrase to the speech recognizer, using text in place of audio for asynchronous speech recognition, and specifies how the recognizer handles Unicode comparison between the phrase and the loaded speech recognition grammars.

Equals(Object) Equals(Object) Equals(Object) Equals(Object)

Determines whether the specified object is equal to the current object.

(Inherited from Object)
GetHashCode() GetHashCode() GetHashCode() GetHashCode()

Serves as the default hash function.

(Inherited from Object)
GetType() GetType() GetType() GetType()

Gets the Type of the current instance.

(Inherited from Object)
InstalledRecognizers() InstalledRecognizers() InstalledRecognizers() InstalledRecognizers()

Returns information for all of the installed speech recognizers on the current system.

LoadGrammar(Grammar) LoadGrammar(Grammar) LoadGrammar(Grammar) LoadGrammar(Grammar)

Synchronously loads a Grammar object.

LoadGrammarAsync(Grammar) LoadGrammarAsync(Grammar) LoadGrammarAsync(Grammar) LoadGrammarAsync(Grammar)

Asynchronously loads a speech recognition grammar.

MemberwiseClone() MemberwiseClone() MemberwiseClone() MemberwiseClone()

Creates a shallow copy of the current Object.

(Inherited from Object)
QueryRecognizerSetting(String) QueryRecognizerSetting(String) QueryRecognizerSetting(String) QueryRecognizerSetting(String)

Returns the values of settings for the recognizer.

Recognize() Recognize() Recognize() Recognize()

Performs a synchronous speech recognition operation.

Recognize(TimeSpan) Recognize(TimeSpan) Recognize(TimeSpan) Recognize(TimeSpan)

Performs a synchronous speech recognition operation with a specified initial silence timeout period.

RecognizeAsync() RecognizeAsync() RecognizeAsync() RecognizeAsync()

Performs a single, asynchronous speech recognition operation.

RecognizeAsync(RecognizeMode) RecognizeAsync(RecognizeMode) RecognizeAsync(RecognizeMode) RecognizeAsync(RecognizeMode)

Performs one or more asynchronous speech recognition operations.

RecognizeAsyncCancel() RecognizeAsyncCancel() RecognizeAsyncCancel() RecognizeAsyncCancel()

Terminates asynchronous recognition without waiting for the current recognition operation to complete.

RecognizeAsyncStop() RecognizeAsyncStop() RecognizeAsyncStop() RecognizeAsyncStop()

Stops asynchronous recognition after the current recognition operation completes.

RequestRecognizerUpdate() RequestRecognizerUpdate() RequestRecognizerUpdate() RequestRecognizerUpdate()

Requests that the recognizer pauses to update its state.

RequestRecognizerUpdate(Object) RequestRecognizerUpdate(Object) RequestRecognizerUpdate(Object) RequestRecognizerUpdate(Object)

Requests that the recognizer pauses to update its state and provides a user token for the associated event.

RequestRecognizerUpdate(Object, TimeSpan) RequestRecognizerUpdate(Object, TimeSpan) RequestRecognizerUpdate(Object, TimeSpan) RequestRecognizerUpdate(Object, TimeSpan)

Requests that the recognizer pauses to update its state and provides an offset and a user token for the associated event.

SetInputToAudioStream(Stream, SpeechAudioFormatInfo) SetInputToAudioStream(Stream, SpeechAudioFormatInfo) SetInputToAudioStream(Stream, SpeechAudioFormatInfo) SetInputToAudioStream(Stream, SpeechAudioFormatInfo)

Configures the SpeechRecognitionEngine object to receive input from an audio stream.

SetInputToDefaultAudioDevice() SetInputToDefaultAudioDevice() SetInputToDefaultAudioDevice() SetInputToDefaultAudioDevice()

Configures the SpeechRecognitionEngine object to receive input from the default audio device.

SetInputToNull() SetInputToNull() SetInputToNull() SetInputToNull()

Disables the input to the speech recognizer.

SetInputToWaveFile(String) SetInputToWaveFile(String) SetInputToWaveFile(String) SetInputToWaveFile(String)

Configures the SpeechRecognitionEngine object to receive input from a Waveform audio format (.wav) file.

SetInputToWaveStream(Stream) SetInputToWaveStream(Stream) SetInputToWaveStream(Stream) SetInputToWaveStream(Stream)

Configures the SpeechRecognitionEngine object to receive input from a stream that contains Waveform audio format (.wav) data.

ToString() ToString() ToString() ToString()

Returns a string that represents the current object.

(Inherited from Object)
UnloadAllGrammars() UnloadAllGrammars() UnloadAllGrammars() UnloadAllGrammars()

Unloads all Grammar objects from the recognizer.

UnloadGrammar(Grammar) UnloadGrammar(Grammar) UnloadGrammar(Grammar) UnloadGrammar(Grammar)

Unloads a specified Grammar object from the SpeechRecognitionEngine instance.

UpdateRecognizerSetting(String, Int32) UpdateRecognizerSetting(String, Int32) UpdateRecognizerSetting(String, Int32) UpdateRecognizerSetting(String, Int32)

Updates the specified setting for the SpeechRecognitionEngine with the specified integer value.

UpdateRecognizerSetting(String, String) UpdateRecognizerSetting(String, String) UpdateRecognizerSetting(String, String) UpdateRecognizerSetting(String, String)

Updates the specified speech recognition engine setting with the specified string value.

Events

AudioLevelUpdated AudioLevelUpdated AudioLevelUpdated AudioLevelUpdated

Raised when the SpeechRecognitionEngine reports the level of its audio input.

AudioSignalProblemOccurred AudioSignalProblemOccurred AudioSignalProblemOccurred AudioSignalProblemOccurred

Raised when the SpeechRecognitionEngine detects a problem in the audio signal.

AudioStateChanged AudioStateChanged AudioStateChanged AudioStateChanged

Raised when the state changes in the audio being received by the SpeechRecognitionEngine.

EmulateRecognizeCompleted EmulateRecognizeCompleted EmulateRecognizeCompleted EmulateRecognizeCompleted

Raised when the SpeechRecognitionEngine finalizes an asynchronous recognition operation of emulated input.

LoadGrammarCompleted LoadGrammarCompleted LoadGrammarCompleted LoadGrammarCompleted

Raised when the SpeechRecognitionEngine finishes the asynchronous loading of a Grammar object.

RecognizeCompleted RecognizeCompleted RecognizeCompleted RecognizeCompleted

Raised when the SpeechRecognitionEngine finalizes an asynchronous recognition operation.

RecognizerUpdateReached RecognizerUpdateReached RecognizerUpdateReached RecognizerUpdateReached

Raised when a running SpeechRecognitionEngine pauses to accept modifications.

SpeechDetected SpeechDetected SpeechDetected SpeechDetected

Raised when the SpeechRecognitionEngine detects input that it can identify as speech.

SpeechHypothesized SpeechHypothesized SpeechHypothesized SpeechHypothesized

Raised when the SpeechRecognitionEngine has recognized a word or words that may be a component of multiple complete phrases in a grammar.

SpeechRecognitionRejected SpeechRecognitionRejected SpeechRecognitionRejected SpeechRecognitionRejected

Raised when the SpeechRecognitionEngine receives input that does not match any of its loaded and enabled Grammar objects.

SpeechRecognized SpeechRecognized SpeechRecognized SpeechRecognized

Raised when the SpeechRecognitionEngine receives input that matches any of its loaded and enabled Grammar objects.

Applies to

See Also