我需要编写一个使用语音识别引擎的应用程序。
如何在 C# 中通过语音在多个文本框中输入不同的值?
我可以在单个文本框中输入值,但不能在第二个文本框中输入值。我有以下代码用于在单个文本框中输入值。
private SpeechRecognitionEngine rec;
private void voice()
{
rec = new SpeechRecognitionEngine();
rec.SetInputToDefaultAudioDevice();
Choices choice = new Choices("apple","Orange","Onion");
GrammarBuilder gr = new GrammarBuilder(choice);
Grammar grammar = new Grammar(gr);
rec.LoadGrammar(grammar);
rec.SpeechRecognized +=
new EventHandler<SpeechRecognizedEventArgs>(rec_SpeechRecogonized);
rec.RecognizeAsync(RecognizeMode.Multiple);
}
void rec_SpeechRecogonized(object sender, SpeechRecognizedEventArgs e)
{
foreach (RecognizedWordUnit word in e.Result.Words)
{
textBox1.Text = word.Text;
}
}