SpeechRecognitionEngine.Recognize Method (TimeSpan)


Performs a synchronous speech recognition operation with a specified initial silence timeout period.

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

public RecognitionResult Recognize(
	TimeSpan initialSilenceTimeout


Type: System.TimeSpan

The interval of time a speech recognizer accepts input containing only silence before finalizing recognition.

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.

If the speech recognition engine detects speech within the time interval specified by initialSilenceTimeout argument, Recognize(TimeSpan) performs a single recognition operation and then terminates. The initialSilenceTimeout parameter supersedes the recognizer's InitialSilenceTimeout property.

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 for the initialSilenceTimeout parameter.

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

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

        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