SpeechRecognitionEngine Constructor (RecognizerInfo)

Microsoft Speech Platform SDK 11

Collapse imageExpand ImageCopy imageCopyHover image

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

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

Syntax

Visual Basic (Declaration)
Public Sub New ( _
	recognizerInfo As RecognizerInfo _
)
Visual Basic (Usage)
Dim recognizerInfo As RecognizerInfo

Dim instance As New SpeechRecognitionEngine(recognizerInfo)
C#
public SpeechRecognitionEngine(
	RecognizerInfo recognizerInfo
)

Parameters

recognizerInfo
Type: Microsoft.Speech.Recognition..::..RecognizerInfo

The information for the specific speech recognizer.

Remarks

You can create an instance of this class for any of the installed speech recognition engines. To get information about which speech recognition engines are installed, use the InstalledRecognizers()()()() method. See SpeechRecognitionEngine(CultureInfo) for information about downloading additional speech recognition engines for specific languages.

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:

Examples

The following example uses the InstalledRecognizers()()()() method to query for installed recognition engines that support English. The results of the query populate a RecognizerInfo object, which is used to initialize the SpeechRecognitionEngineobject.

 Copy imageCopy Code
using System;
using Microsoft.Speech.Recognition;

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

      // Select a speech recognizer that supports English.
      RecognizerInfo info = null;
      foreach (RecognizerInfo ri in SpeechRecognitionEngine.InstalledRecognizers())
      {
        if (ri.Culture.TwoLetterISOLanguageName.Equals("en"))
        {
          info = ri;
          break;
        }
      }
      if (info == null) return;

      // Create the selected recognizer.
      using (SpeechRecognitionEngine recognizer =
        new SpeechRecognitionEngine(info))
      {

        // Create a grammar, construct a Grammar object, and load it to the recognizer.
        Choices animals = new Choices(new string[] { "cow", "pig", "goat" });
        GrammarBuilder farm = new GrammarBuilder("On this farm he had a");
        farm.Append(animals);

        Grammar farmAnimals = new Grammar(farm);
        farmAnimals.Name = "Farm";

        recognizer.LoadGrammar(farmAnimals);

        // 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);
    }
  }
}

See Also