Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Export (0) Print
Expand All

SpeechRecognitionEngine Constructor (String)

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

Namespace:  System.Speech.Recognition
Assembly:  System.Speech (in System.Speech.dll)

public SpeechRecognitionEngine(
	string recognizerId
)

Parameters

recognizerId
Type: System.String

The token name of the speech recognizer to use.

ExceptionCondition
ArgumentException

No speech recognizer with that token name is installed, or recognizerId is the empty string ("").

ArgumentNullException

recognizerId is null.

The token name of the recognizer is the value of the Id property of the RecognizerInfo object returned by the RecognizerInfo property of the recognizer. To get a collection of all the installed recognizers, use the static InstalledRecognizers method.

Before the speech recognizer can begin recognition, you must load at least one speech recognition grammar and configure the input for the recognizer.

To load a grammar, call the LoadGrammar or LoadGrammarAsync method.

To configure the audio input, use one of the following methods:

The following example shows part of a console application that demonstrates basic speech recognition, and creates an instance of the Speech Recognizer 8.0 for Windows (English - US).

using System;
using System.Speech.Recognition;

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

      // Create an instance of the Microsoft Speech Recognizer 8.0 for
      // Windows (English - US).
      using (SpeechRecognitionEngine recognizer =
        new SpeechRecognitionEngine("MS-1033-80-DESK"))
      {

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

        // Add a handler for the speech recognized event.
        recognizer.SpeechRecognized += new EventHandler(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.6, 4.5, 4, 3.5, 3.0

.NET Framework Client Profile

Supported in: 4
Show:
© 2015 Microsoft