Export (0) Print
Expand All

SpeechRecognitionEngine.SpeechHypothesized Event

Raised when the SpeechRecognitionEngine has recognized a word or words that may be a component of multiple complete phrases in a grammar.

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

public event EventHandler<SpeechHypothesizedEventArgs> SpeechHypothesized

The SpeechRecognitionEngine generates numerous SpeechHypothesized events as it attempts to identify an input phrase. You can access the text of partially recognized phrases in the Result property of the SpeechHypothesizedEventArgs object in the handler for the SpeechHypothesized event. Typically, handling these events is useful only for debugging.

SpeechHypothesizedEventArgs derives from RecognitionEventArgs.

For more information see the EndSilenceTimeoutAmbiguous property and the Recognize, RecognizeAsync, EmulateRecognize, and EmulateRecognizeAsync methods.

When you create a SpeechHypothesized 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". The example uses the SpeechHypothesized event to display incomplete phrase fragments in the console as they are recognized.

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 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 the list of");
        mediaMenu.Append(listTypes);
        mediaMenu.Append("in the");
        mediaMenu.Append(genres);
        mediaMenu.Append("category.");

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

        // Attach event handlers.
        recognizer.LoadGrammarCompleted +=
          new EventHandler<LoadGrammarCompletedEventArgs>(recognizer_LoadGrammarCompleted);
        recognizer.SpeechRecognized +=
          new EventHandler<SpeechRecognizedEventArgs>(recognizer_SpeechRecognized);
        recognizer.SpeechHypothesized +=
          new EventHandler<SpeechHypothesizedEventArgs>(recognizer_SpeechHypothesized);

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

        // Set the input to the recognizer.
        recognizer.SetInputToDefaultAudioDevice();

        // Start asynchronous recognition.
        recognizer.RecognizeAsync();

        // Keep the console window open.
        Console.ReadLine();
      }
    }

    // Handle the SpeechHypothesized event.
    static void recognizer_SpeechHypothesized(object sender, SpeechHypothesizedEventArgs e)
    {
      Console.WriteLine("Speech hypothesized: " + e.Result.Text);
    }

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

    // Handle the SpeechRecognized event.
    static void recognizer_SpeechRecognized(object sender, SpeechRecognizedEventArgs e)
    {
      Console.WriteLine(); 
      Console.WriteLine("Speech recognized: " + e.Result.Text);
    }
  }
}

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

Community Additions

ADD
Show:
© 2014 Microsoft