2 out of 2 rated this helpful - Rate this topic

SpeechRecognitionEngine Class

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

System.Object
  System.Speech.Recognition.SpeechRecognitionEngine

Namespace:  System.Speech.Recognition
Assembly:  System.Speech (in System.Speech.dll)
public class SpeechRecognitionEngine : IDisposable

The SpeechRecognitionEngine type exposes the following members.

  Name Description
Public method SpeechRecognitionEngine() Initializes a new instance of the SpeechRecognitionEngine class using the default speech recognizer for the system.
Public method SpeechRecognitionEngine(CultureInfo) Initializes a new instance of the SpeechRecognitionEngine class using the default speech recognizer for a specified locale.
Public method SpeechRecognitionEngine(RecognizerInfo) Initializes a new instance of the SpeechRecognitionEngine using the information in a RecognizerInfo object to specify the recognizer to use.
Public method SpeechRecognitionEngine(String) Initializes a new instance of the SpeechRecognitionEngine class with a string parameter that specifies the name of the recognizer to use.
Top
  Name Description
Public property AudioFormat Gets the format of the audio being received by the SpeechRecognitionEngine.
Public property AudioLevel Gets the level of the audio being received by the SpeechRecognitionEngine.
Public property AudioPosition Gets the current location in the audio stream being generated by the device that is providing input to the SpeechRecognitionEngine.
Public property AudioState Gets the state of the audio being received by the SpeechRecognitionEngine.
Public property BabbleTimeout Gets or sets the time interval during which a SpeechRecognitionEngine accepts input containing only background noise, before finalizing recognition.
Public property EndSilenceTimeout Gets or sets the interval of silence that the SpeechRecognitionEngine will accept at the end of unambiguous input before finalizing a recognition operation.
Public property EndSilenceTimeoutAmbiguous Gets or sets the interval of silence that the SpeechRecognitionEngine will accept at the end of ambiguous input before finalizing a recognition operation.
Public property Grammars Gets a collection of the Grammar objects that are loaded in this SpeechRecognitionEngine instance.
Public property InitialSilenceTimeout Gets or sets the time interval during which a SpeechRecognitionEngine accepts input containing only silence before finalizing recognition.
Public property MaxAlternates Gets or sets the maximum number of alternate recognition results that the SpeechRecognitionEngine returns for each recognition operation.
Public property RecognizerAudioPosition Gets the current location of the SpeechRecognitionEngine in the audio input that it is processing.
Public property RecognizerInfo Gets information about the current instance of SpeechRecognitionEngine.
Top
  Name Description
Public method Dispose() Disposes the SpeechRecognitionEngine object.
Protected method Dispose(Boolean) Disposes the SpeechRecognitionEngine object and releases resources used during the session.
Public method EmulateRecognize(String) Emulates input of a phrase to the speech recognizer, using text in place of audio for synchronous speech recognition.
Public method 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.
Public method 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.
Public method EmulateRecognizeAsync(String) Emulates input of a phrase to the speech recognizer, using text in place of audio for asynchronous speech recognition.
Public method 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.
Public method 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.
Public method Equals(Object) Determines whether the specified Object is equal to the current Object. (Inherited from Object.)
Protected method Finalize Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Inherited from Object.)
Public method GetHashCode Serves as a hash function for a particular type. (Inherited from Object.)
Public method GetType Gets the Type of the current instance. (Inherited from Object.)
Public method Static member InstalledRecognizers Returns information for all of the installed speech recognizers on the current system.
Public method LoadGrammar Synchronously loads a Grammar object.
Public method LoadGrammarAsync Asynchronously loads a speech recognition grammar.
Protected method MemberwiseClone Creates a shallow copy of the current Object. (Inherited from Object.)
Public method QueryRecognizerSetting Returns the values of settings for the recognizer.
Public method Recognize() Performs a synchronous speech recognition operation.
Public method Recognize(TimeSpan) Performs a synchronous speech recognition operation with a specified initial silence timeout period.
Public method RecognizeAsync() Performs a single, asynchronous speech recognition operation.
Public method RecognizeAsync(RecognizeMode) Performs one or more asynchronous speech recognition operations.
Public method RecognizeAsyncCancel Terminates asynchronous recognition without waiting for the current recognition operation to complete.
Public method RecognizeAsyncStop Stops asynchronous recognition after the current recognition operation completes.
Public method RequestRecognizerUpdate() Requests that the recognizer pauses to update its state.
Public method RequestRecognizerUpdate(Object) Requests that the recognizer pauses to update its state and provides a user token for the associated event.
Public method RequestRecognizerUpdate(Object, TimeSpan) Requests that the recognizer pauses to update its state and provides an offset and a user token for the associated event.
Public method SetInputToAudioStream Configures the SpeechRecognitionEngine object to receive input from an audio stream.
Public method SetInputToDefaultAudioDevice Configures the SpeechRecognitionEngine object to receive input from the default audio device.
Public method SetInputToNull Disables the input to the speech recognizer.
Public method SetInputToWaveFile Configures the SpeechRecognitionEngine object to receive input from a Waveform audio format (.wav) file.
Public method SetInputToWaveStream Configures the SpeechRecognitionEngine object to receive input from a stream that contains Waveform audio format (.wav) data.
Public method ToString Returns a string that represents the current object. (Inherited from Object.)
Public method UnloadAllGrammars Unloads all Grammar objects from the recognizer.
Public method UnloadGrammar Unloads a specified Grammar object from the SpeechRecognitionEngine instance.
Public method UpdateRecognizerSetting(String, Int32) Updates the specified setting for the SpeechRecognitionEngine with the specified integer value.
Public method UpdateRecognizerSetting(String, String) Updates the specified speech recognition engine setting with the specified string value.
Top
  Name Description
Public event AudioLevelUpdated Raised when the SpeechRecognitionEngine reports the level of its audio input.
Public event AudioSignalProblemOccurred Raised when the SpeechRecognitionEngine detects a problem in the audio signal.
Public event AudioStateChanged Raised when the state changes in the audio being received by the SpeechRecognitionEngine.
Public event EmulateRecognizeCompleted Raised when the SpeechRecognitionEngine finalizes an asynchronous recognition operation of emulated input.
Public event LoadGrammarCompleted Raised when the SpeechRecognitionEngine finishes the asynchronous loading of a Grammar object.
Public event RecognizeCompleted Raised when the SpeechRecognitionEngine finalizes an asynchronous recognition operation.
Public event RecognizerUpdateReached Raised when a running SpeechRecognitionEngine pauses to accept modifications.
Public event SpeechDetected Raised when the SpeechRecognitionEngine detects input that it can identify as speech.
Public event SpeechHypothesized Raised when the SpeechRecognitionEngine has recognized a word or words that may be a component of multiple complete phrases in a grammar.
Public event SpeechRecognitionRejected Raised when the SpeechRecognitionEngine receives input that does not match any of its loaded and enabled Grammar objects.
Public event SpeechRecognized Raised when the SpeechRecognitionEngine receives input that matches any of its loaded and enabled Grammar objects.
Top

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 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.

The following example shows part of a console application that demonstrates basic speech recognition. Because this example uses the Multiple mode of the RecognizeAsync(RecognizeMode) 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);
    }
  }
}

.NET Framework

Supported in: 4, 3.5, 3.0

.NET Framework Client Profile

Supported in: 4

Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.
Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.
Did you find this helpful?
(1500 characters remaining)
Community Content Add
Annotations FAQ
Example in VB using Forms
Public Class Form1
    Private WithEvents OutputListBox As New ListBox With {.Dock = DockStyle.Fill, .IntegralHeight = False}
    Private WithEvents SpeechEngine As New System.Speech.Recognition.SpeechRecognitionEngine(System.Globalization.CultureInfo.GetCultureInfo("en-US"))

    Private Sub Form1_FormClosing(sender As Object, e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
        SpeechEngine.RecognizeAsyncCancel()
        SpeechEngine.Dispose()
    End Sub

    Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
        Controls.Add(OutputListBox)
        SpeechEngine.LoadGrammar(New System.Speech.Recognition.DictationGrammar)
        SpeechEngine.SetInputToDefaultAudioDevice()
        SpeechEngine.RecognizeAsync(Speech.Recognition.RecognizeMode.Multiple)
    End Sub

    Private Sub SpeechEngine_SpeechRecognized(sender As Object, e As System.Speech.Recognition.SpeechRecognizedEventArgs) Handles SpeechEngine.SpeechRecognized
        OutputListBox.Items.Add("You said: " & e.Result.Text)
    End Sub
End Class