SpeechRecognizer.SpeechHypothesized Event

Occurs when the recognizer 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)

member SpeechHypothesized : IEvent<EventHandler<SpeechHypothesizedEventArgs>,
    SpeechHypothesizedEventArgs>

The shared recognizer can raise this event when the input is ambiguous. For example, for a speech recognition grammar that supports recognition of either "new game please" or "new game", "new game please" is an unambiguous input, and "new game" is an ambiguous input.

When you create a delegate for a SpeechHypothesized event, 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 a shared speech recognition engine.
    {
      using (SpeechRecognizer recognizer =
         new SpeechRecognizer())
      {

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

        // 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);
    }

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

.NET Framework

Supported in: 4.5, 4, 3.5, 3.0

.NET Framework Client Profile

Supported in: 4

Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

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

Was this page helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft