在 Visual Studio 中,我正在创建使用语音识别进行应用程序控制的应用程序。
我想向您寻求有关如何将语音命令分配给方法的最佳方法的帮助。
我正在使用语法生成器和选择:
//Create Grammar Builder with Choices
GrammarBuilder slovnik = new GrammarBuilder();
slovnik.Append(new Choices("stop", "go"));
如果我想将选项中的一个词分配给(语音命令)到方法(例如 - 显示消息框) - 在事件处理程序中我使用 if 命令:
void recognizer_SpeechRecognized(object sender, SpeechRecognizedEventArgs e)
{
if (e.Result.Text == "stop")
{
MessageBox.Show("Some message, that the voice command works");
}
}
我的问题是 - If 子句是如何将单词/短语从语法连接到方法/事件的最佳方式,还是有更好(更清洁)的解决方案如何做到这一点?我正在使用C#和System.Speech.Recognition.SpeechRecognitionEngine。
非常感谢!