SpeechRecognitionEngine.Recognize Method ()


Performs a synchronous speech recognition operation.

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

public RecognitionResult Recognize()

Return Value

Type: System.Speech.Recognition.RecognitionResult

The recognition result for the input, or null if the operation is not successful or the recognizer is not enabled.

This method performs a single recognition operation. The recognizer performs this operation against its loaded and enabled speech recognition grammars.

During a call to this method, the recognizer can raise the following events:

The recognizer does not raise the RecognizeCompleted event when using this method.

The Recognize() method returns a RecognitionResult object, or null if the operation is not successful.

A synchronous recognition operation can fail for the following reasons:

  • Speech is not detected before the timeout intervals expire for the BabbleTimeout or InitialSilenceTimeout properties.

  • The recognition engine detects speech but finds no matches in any of its loaded and enabled Grammar objects.

To perform asynchronous recognition, use one of the RecognizeAsync methods.

The following example shows part of a console application that demonstrates basic speech recognition. The example creates a DictationGrammar, loads it into an in-process speech recognizer, and performs one recognition operation.

using System;
using System.Speech.Recognition;

namespace SynchronousRecognition
  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());

        // Configure input to the speech recognizer.

        // Modify the initial silence time-out value.
        recognizer.InitialSilenceTimeout = TimeSpan.FromSeconds(5);

        // Start synchronous speech recognition.
        RecognitionResult result = recognizer.Recognize();

        if (result != null)
          Console.WriteLine("Recognized text = {0}", result.Text);
          Console.WriteLine("No recognition result available.");

      Console.WriteLine("Press any key to continue...");

.NET Framework
Available since 3.0
Return to top