【发布时间】:2014-03-11 17:28:45
【问题描述】:
我们已经开始使用 SpeechRecognitionEngine,并基于我们在堆栈溢出中发现的应用构建了一个非常基本的应用。代码如下:-
public partial class Form1 : Form
{
SpeechRecognitionEngine sr = new SpeechRecognitionEngine(new System.Globalization.CultureInfo("en-US"));
public Form1()
{
InitializeComponent();
// Create an in-process speech recognizer for the en-US locale.
}
private void BeginSpeach()
{
//Create grammar
Choices words = new Choices();
words.Add("Hi");
words.Add("No");
words.Add("Yes");
Grammar wordsList = new Grammar(new GrammarBuilder(words));
wordsList.SpeechRecognized += new EventHandler<SpeechRecognizedEventArgs>(rec_SpeechRecognized);
sr.LoadGrammar(wordsList);
sr.SetInputToDefaultAudioDevice();
sr.RecognizeAsync();
}
void rec_SpeechRecognized(object sender, RecognitionEventArgs e)
{
MessageBox.Show(e.Result.Text);
}
private void Form1_Load(object sender, EventArgs e)
{
BeginSpeach();
}
}
这似乎工作得很好。唯一的问题是,一旦它检测到“hi”这个词,它就不会再叛逃了。 有没有办法让这个总是听?所以我可以说“嗨”,然后“不”,然后“是”。
我们希望以此为基础创建命令列表
感谢您的建议
【问题讨论】:
-
RecognizeCompleted 事件也会发生同样的情况?
-
这指向了我在下面发布代码的答案,谢谢
标签: c# .net winforms speech-recognition