[英]winforms SpeechRecognitionEngine
we have started to play about with the speechRecognitionEngine, and built a very basic app based on one that we found on stack overflow. 我们已经开始使用SpeechRecognitionEngine,并基于我们在堆栈溢出时发现的应用程序构建了一个非常基本的应用程序。 Code below:-
代码如下:
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();
}
}
This seems to work great. 这看起来很棒。 The only issue is that once it has detected the word "hi", thats is, it won't defect any more.
唯一的问题是,一旦它检测到单词“ hi”,那就不再有缺陷。 Is there a way to get this to always listen?
有没有办法让这个总是听? so i can say "hi", then "no", then "yes".
所以我可以说“嗨”,然后说“不”,然后说“是”。
We hope to build on this to create a list of commands 我们希望以此为基础创建命令列表
Thank you for any advice 谢谢你的任何建议
Came to the conclusion from tweellt. 从推特得出结论。
sr.RecognizeCompleted += new EventHandler<RecognizeCompletedEventArgs>(rec_test);
and then calling this again 然后再次调用
private void rec_test(object sender, RecognizeCompletedEventArgs e)
{
sr.RecognizeAsync();
}
You could just change 你可以改变
sr.RecognizeAsync();
in BeginSpeach()
to 在
BeginSpeach()
中
sr.RecognizeAsync(RecognizeMode.Multiple);
This will detect everything you say... 这将检测到您所说的一切...
RecognizeAsync() - Performs a single, asynchronous speech recognition operation. RecognizeAsync() -执行单个异步语音识别操作。
RecognizeAsync(RecognizeMode) - Performs one or more asynchronous speech recognition operations. RecognizeAsync(RecognizeMode) -执行一个或多个异步语音识别操作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.