Export (0) Print
Expand All

SpeechRecognizedEventArgs Class

System.Object
  System.EventArgs
    System.Speech.Recognition.RecognitionEventArgs
      System.Speech.Recognition.SpeechRecognizedEventArgs

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

[SerializableAttribute]
public class SpeechRecognizedEventArgs : RecognitionEventArgs

The SpeechRecognizedEventArgs type exposes the following members.

  NameDescription
Public propertyResultGets the recognition result data associated with the speech recognition event. (Inherited from RecognitionEventArgs.)
Top

  NameDescription
Public methodEquals(Object)Determines whether the specified Object is equal to the current Object. (Inherited from Object.)
Protected methodFinalizeAllows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Inherited from Object.)
Public methodGetHashCodeServes as a hash function for a particular type. (Inherited from Object.)
Public methodGetTypeGets the Type of the current instance. (Inherited from Object.)
Protected methodMemberwiseCloneCreates a shallow copy of the current Object. (Inherited from Object.)
Public methodToStringReturns a string that represents the current object. (Inherited from Object.)
Top

A SpeechRecognized event is raised by the Grammar, SpeechRecognizer and SpeechRecognitionEngine classes.

SpeechRecognized events are generated when one or more of the alternates from a recognition operation have a high enough confidence score to be accepted. To obtain detailed information about a recognized phrase, access the Result property in the handler for the event.

SpeechRecognizedEventArgs derives from the RecognitionEventArgs class.

The following example is part of a console application that loads a speech recognition grammar and demonstrates speech input to the shared recognizer, the associated recognition results, and the associated events raised by the speech recognizer. If Windows Speech Recognition is not running, then starting this application will also start Windows Speech Recognition.

Spoken input such as "I want to fly from Chicago to Miami" will trigger a SpeechRecognized event. Speaking the phrase "Fly me from Houston to Chicago " will not trigger a SpeechRecognized event.

The example uses a handler for the SpeechRecognized event to display successfully recognized phrases and the semantics they contain in the console.

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 SemanticResultValue objects that contain cities and airport codes.
        SemanticResultValue chicago = new SemanticResultValue("Chicago", "ORD");
        SemanticResultValue boston = new SemanticResultValue("Boston", "BOS");
        SemanticResultValue miami = new SemanticResultValue("Miami", "MIA");
        SemanticResultValue dallas = new SemanticResultValue("Dallas", "DFW");

        // Create a Choices object and add the SemanticResultValue objects, using
        // implicit conversion from SemanticResultValue to GrammarBuilder
        Choices cities = new Choices();
        cities.Add(new Choices(new GrammarBuilder[] { chicago, boston, miami, dallas }));

        // Build the phrase and add SemanticResultKeys.
        GrammarBuilder chooseCities = new GrammarBuilder();
        chooseCities.Append("I want to fly from");
        chooseCities.Append(new SemanticResultKey("origin", cities));
        chooseCities.Append("to");
        chooseCities.Append(new SemanticResultKey("destination", cities));

        // Build a Grammar object from the GrammarBuilder.
        Grammar bookFlight = new Grammar(chooseCities);
        bookFlight.Name = "Book Flight";

        // Add a handler for the LoadGrammarCompleted event.
        recognizer.LoadGrammarCompleted +=
          new EventHandler<LoadGrammarCompletedEventArgs>(recognizer_LoadGrammarCompleted);

        // Add a handler for the SpeechRecognized event.
        recognizer.SpeechRecognized += 
          new EventHandler<SpeechRecognizedEventArgs>(recognizer_SpeechRecognized);

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

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

    // 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("Speech recognized:  " + e.Result.Text);
      Console.WriteLine();
      Console.WriteLine("Semantic results:");
      Console.WriteLine("  The flight origin is " + e.Result.Semantics["origin"].Value);
      Console.WriteLine("  The flight destination is " + e.Result.Semantics["destination"].Value);
    }
  }
}

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

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Community Additions

ADD
Show:
© 2014 Microsoft