Grammar.SpeechRecognized 事件
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
当语音识别器执行使用 Grammar 对象的标识时引发。
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 Custom Event SpeechRecognized As EventHandler(Of SpeechRecognizedEventArgs)
Public Event SpeechRecognized As EventHandler(Of SpeechRecognizedEventArgs)
事件类型
示例
以下示例演示如何对 Grammar 对象的 SpeechRecognized 事件使用事件处理程序。 它将识别结果输出到 控制台。
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);
}
}
注解
语音识别器在识别输入时也会引发 SpeechRecognized
事件。 对象的 GrammarSpeechRecognized 事件在语音识别器 SpeechRecognized
的事件 之前引发。 有关详细信息, SpeechRecognizer.SpeechRecognized请参阅 、 SpeechRecognitionEngine.SpeechRecognized和 RecognizeCompleted 事件。
特定于特定语法的任何任务应始终由对象的 SpeechRecognized 事件的处理程序Grammar处理。