Grammar.SpeechRecognized 事件

定义

当语音识别器执行使用 Grammar 对象的标识时引发。Raised when a speech recognizer performs recognition using the Grammar object.

public:
 event EventHandler<System::Speech::Recognition::SpeechRecognizedEventArgs ^> ^ SpeechRecognized;
public event EventHandler<System.Speech.Recognition.SpeechRecognizedEventArgs> SpeechRecognized;
member this.SpeechRecognized : EventHandler<System.Speech.Recognition.SpeechRecognizedEventArgs> 
Public Event SpeechRecognized As EventHandler(Of SpeechRecognizedEventArgs) 

示例

下面的示例演示如何将事件处理程序用于 @no__t 0 对象的 @no__t 1 事件。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()  
  {  
  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);  
  }  
}  

注解

语音识别器还会在识别输入时引发 @no__t 0 事件。The speech recognizer also raises a SpeechRecognized event when it recognizes input. 在语音识别器 @no__t 2 事件之前,将引发 Grammar 对象的 @no__t。The Grammar object's SpeechRecognized event is raised prior to the speech recognizer's SpeechRecognized event . 有关详细信息,请参阅 SpeechRecognizer.SpeechRecognizedSpeechRecognitionEngine.SpeechRecognized 和 @no__t 2 事件。For more information, see the SpeechRecognizer.SpeechRecognized, SpeechRecognitionEngine.SpeechRecognized, and RecognizeCompleted events.

特定于特定语法的任何任务应始终由 Grammar 对象的 @no__t 1 事件的处理程序处理。Any tasks specific to a particular grammar should always be handled by handlers for the Grammar object's SpeechRecognized event.

适用于

另请参阅