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)
事件類型
範例
下列範例顯示物件事件的事件處理常式 GrammarSpeechRecognized 用法。 它會將辨識結果輸出至 主控台。
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 處理。