Grammar.SpeechRecognized Event

Raised when a SpeechRecognitionEngine instance performs recognition using the Grammar object.

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


Public Event SpeechRecognized As EventHandler(Of SpeechRecognizedEventArgs)
Dim instance As Grammar
Dim handler As EventHandler(Of SpeechRecognizedEventArgs)

AddHandler instance.SpeechRecognized, handler
public event EventHandler<SpeechRecognizedEventArgs> SpeechRecognized


The SpeechRecognitionEngine object also raises a SpeechRecognized event when it recognizes input. The Grammar object's SpeechRecognized event is raised prior to the SpeechRecognitionEngine's SpeechRecognized event . For more information, see the RecognizeCompleted events.

Any tasks specific to a particular grammar should always be handled by handlers for the Grammar object's SpeechRecognized event.


The following example shows the use of an event handler for the Grammar object's SpeechRecognized event. It outputs the recognition results to the console.

public partial class Form1 : Form
  SpeechRecognitionEngine sre;

  public Form1()

  // Create an in-process speech recognizer.
  sre = new SpeechRecognitionEngine();

  // Configure input to the speech recognizer.

  // Create a simple grammar and load it.
  Grammar testGrammar = new Grammar(new GrammarBuilder("testing"));

  // Add a handler for the grammar's speech recognized event.
  testGrammar.SpeechRecognized += new EventHandler<SpeechRecognizedEventArgs>(testGrammar_SpeechRecognized);

  // Start asynchronous speech recognition.

  // Handle the grammar's SpeechRecognized event, output the recognized text.
  void testGrammar_SpeechRecognized(object sender, SpeechRecognizedEventArgs e)
    Console.WriteLine("Recognized text: " + e.Result.Text);

See Also


Grammar Class

Grammar Members

Microsoft.Speech.Recognition Namespace