如何使用GrammarBuilder允许各种选择顺序

时间:2011-10-28 21:09:13

标签: c# speech-recognition system.speech.recognition

我正在开发一个简单的语音识别应用程序。我需要GrammarBuilder的一些帮助。这是我尝试过的:

Choices choice1 = new Choices(....);
Choices choice2 = new Choices(....);
Choices choice3 = new Choices(....);

GrammarBuilder gb = new GrammarBuilder();
gb.Append(choice1);
gb.Append(choice2);
gb.Append(choice3);

Grammar grammar = new Grammar(gb);
recognitionEngine.LoadGrammar(grammar);

此代码要求用户从choice1然后选择select2然后按顺序说出choice并且效果很好。但是我希望代码期望choice1然后是choice2然后是choice2和choice3的任意组合。我不知道如何实现这一点。

1 个答案:

答案 0 :(得分:1)

您可以添加2到3的所有选择。然后将该组合添加两次到GrammarBuilder。 (那么你有4个选择。) 我确信有一个更好的解决方案,因为这可能看起来像一个循环。

我自己,我正在使用静态SRGS-xml文件。我认为它有比Choices类更多的选项。

您也可以动态地执行此操作,请查看此示例。 http://gotspeech.net/forums/thread/5206.aspx

相关问题