This documentation is archived and is not being maintained.

SpeechRecognitionEngine.RecognizeCompleted Event

Raised when the SpeechRecognitionEngine finalizes an asynchronous recognition operation.

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

public event EventHandler<RecognizeCompletedEventArgs> RecognizeCompleted

The SpeechRecognitionEngine object's RecognizeAsync method initiates an asynchronous recognition operation. When the recognizer finalizes the asynchronous operation, it raises this event.

Using the handler for the RecognizeCompleted event, you can access the RecognitionResult in the RecognizeCompletedEventArgs object. If recognition was not successful, RecognitionResult will be null. To determine whether a timeout or an interruption in audio input caused recognition to fail, you can access the properties for InitialSilenceTimeout, BabbleTimeout, or InputStreamEnded.

See the RecognizeCompletedEventArgs class for more information.

To obtain details on the best rejected recognition candidates, attach a handler for the SpeechRecognitionRejected event.

When you create a RecognizeCompleted delegate, you identify the method that will handle the event. To associate the event with your event handler, add an instance of the delegate to the event. The event handler is called whenever the event occurs, unless you remove the delegate. For more information about event-handler delegates, see Events and Delegates.

The following example recognizes phrases such as "Display the list of artists in the jazz category" or "Display albums gospel". The example uses a handler for the RecognizeCompleted event to display information about the results of recognition in the console.

using System;
using System.Speech.Recognition;

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

    // Initialize an in-process speech recognition engine.
      using (SpeechRecognitionEngine recognizer =
         new SpeechRecognitionEngine())

        //  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("in the", 0, 1);
        mediaMenu.Append("category.", 0, 1);

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

        // Attach event handlers.
        recognizer.RecognizeCompleted +=
          new EventHandler<RecognizeCompletedEventArgs>(recognizer_RecognizeCompleted);
        recognizer.LoadGrammarCompleted += 
          new EventHandler<LoadGrammarCompletedEventArgs>(recognizer_LoadGrammarCompleted);

        // Load the grammar object to the recognizer.

        // Set the input to the recognizer.

        // Start asynchronous, continuous recognition.

        // Keep the console window open.

    // Handle the RecognizeCompleted event.
    static void recognizer_RecognizeCompleted(object sender, RecognizeCompletedEventArgs e)
      if (e.Error != null)
          "RecognizeCompleted, error occurred during recognition: {0}", e.Error);

      if (e.InitialSilenceTimeout || e.BabbleTimeout)
          "RecognizeCompleted: BabbleTimeout({0}), InitialSilenceTimeout({1}).",
          e.BabbleTimeout, e.InitialSilenceTimeout);

      if (e.InputStreamEnded)
          "RecognizeCompleted: AudioPosition({0}), InputStreamEnded({1}).",
          e.AudioPosition, e.InputStreamEnded);

      if (e.Result != null)
        Console.WriteLine("  Grammar: " + e.Result.Grammar.Name);
        Console.WriteLine("  Recognized text: " + e.Result.Text);
        Console.WriteLine("  Confidence score: " + e.Result.Confidence);
        Console.WriteLine("  Audio position: " + e.AudioPosition);

        Console.WriteLine("RecognizeCompleted: No result.");

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

    // Handle the LoadGrammarCompleted event.
    static void recognizer_LoadGrammarCompleted(object sender, LoadGrammarCompletedEventArgs e)
      Console.WriteLine("Grammar loaded:  " + e.Grammar.Name);

.NET Framework

Supported in: 4, 3.5, 3.0

.NET Framework Client Profile

Supported in: 4

Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.