Grammar.SpeechRecognized Event

Definition

Raised when a speech recognizer performs recognition using the Grammar object.

C#
public event EventHandler<System.Speech.Recognition.SpeechRecognizedEventArgs> SpeechRecognized;

Event Type

Examples

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.

C#
public partial class Form1 : Form
{
  SpeechRecognitionEngine sre;

  public Form1()
  {
  InitializeComponent();

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

  // Configure input to the speech recognizer.
  sre.SetInputToDefaultAudioDevice();

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

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

  // Start asynchronous speech recognition.
  sre.RecognizeAsync();
  }

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

Remarks

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

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

Applies to

Tuote Versiot
.NET 8 (package-provided), 9 (package-provided), 10 (package-provided)
.NET Framework 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0 (package-provided)

See also