【发布时间】:2016-01-29 07:12:29
【问题描述】:
我正在尝试使用 c#(windows form) 制作语音识别应用程序。
这是我正在使用的代码
//recognizing speech
SpeechRecognitionEngine r = new SpeechRecognitionEngine();
//then load the grammar
r.LoadGrammar(new Grammar(new GrammarBuilder
(new Choices("hello","how are you","nice to meet you")))
{ Name = "speechGrammar" });
r.SetInputToDefaultAudioDevice(); // set the input of the speech recognizer to the default audio device
r.RecognizeAsync(RecognizeMode.Multiple); // recognize speech asynchronous
//adding a event handler
r.SpeechRecognized += r_SpeechRecognized;
//then create a method for that
void r_SpeechRecognized(object sender, SpeechRecognizedEventArgs e)
{
if (e.Result.Text == "test") // e.Result.Text contains the recognized text
{
SpeechSynthesizer s = new SpeechSynthesizer();
s.Speak("hello");
MessageBox.Show("Hi User");
s.Dispose();
}
}
所以我希望程序将文本框的文本更改为说出但不在语法中的单词/短语。
前
send a mail to xyz
该句子不在语法列表中
所以当它被说出来时,我想要
textbox1.text = spokenword;
我应该对此结果的代码进行哪些更改。
【问题讨论】:
-
如果您特别想要无法识别的文本,那么
SpeechRecognized事件不是您所需要的。其他活动可用..? -
@stuartd 我想要计算机听到但语法列表中不存在的文本。那我应该使用哪个事件
-
@stuard 我应该使用哪个事件??
标签: c# winforms speech-recognition