SpeechRecognitionEngine Constructor (CultureInfo)

Microsoft Speech Platform SDK 11

Collapse image Expand Image Copy image CopyHover image

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

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

Syntax

Visual Basic (Declaration)
Public Sub New ( _
	culture As CultureInfo _
)
Visual Basic (Usage)
Dim culture As CultureInfo

Dim instance As New SpeechRecognitionEngine(culture)
C#
public SpeechRecognitionEngine(
	CultureInfo culture
)

Parameters

culture
Type: System.Globalization..::..CultureInfo

The locale that the speech recognizer must support.

Remarks

If the system does not support the locale defined by culture, an exception will be generated on construction.

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 Microsoft Speech Platform Runtime 11 and Microsoft Speech Platform SDK 11 do not include any engines for speech recognition in a specific language. You must download a language pack (an engine for speech recognition in a specific language) for each language in which you want to perform speech recognition.

The language packs are different for each version of the Speech Platform Runtime. You must download the language pack version that matches the version of the Speech Platform Runtime that you have installed. The language packs for the Speech Platform SDK 11 are for server-based applications and are different than the languages that ship with Windows Vista or Windows 7. Use the following links to download the version of the server language packs that match your Speech Platform Runtime version:

See Language Support for a list of languages for which you can download language packs.

Examples

The following example initializes a SpeechRecognitionEngine object that selects the default speech recognition engine for US English (en-US).

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

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

      // Create a SpeechRecognitionEngine instance that selects 
      // the default speech recognition engine for US English.
      using (SpeechRecognitionEngine recognizer =
         new SpeechRecognitionEngine(new System.Globalization.CultureInfo("en-US")))
      {

        // Create a grammar.
        // Create lists of alternative choices.
        Choices listTypes = new Choices(new string[] { "albums", "artists" });
        Choices genres = new Choices(new string[] { 
          "blues", "classical", "gospel", "jazz", "rock" });

        // Create a GrammarBuilder object and assemble the grammar components.
        GrammarBuilder mediaMenu = new GrammarBuilder("Display");
        mediaMenu.Append("the list of", 0, 1);
        mediaMenu.Append(listTypes);
        mediaMenu.Append("in the", 0, 1);
        mediaMenu.Append(genres);
        mediaMenu.Append("category", 0, 1);

        // Build a Grammar object from the GrammarBuilder.
        Grammar mediaMenuGrammar = new Grammar(mediaMenu);
        mediaMenuGrammar.Name = "Media Chooser";

        // Load the Grammar object to the SpeechRecognitionEngine.
        recognizer.LoadGrammarAsync(mediaMenuGrammar);

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