我想使用这样的语法:这是+名称。
代码是:
GrammarBuilder grammar = new GrammarBuilder();
grammar.Append("This is");
gammar.Append(new Choices("Bangalore", "Sanjay", "Cindy",...));
_recognizer.LoadGrammar(new Grammar(grammar));
我的问题是,我可以在引擎识别出该事件时发送事件,并在引擎识别出该名称时发送另一个事件吗?
这该怎么做?
最佳答案
我认为您也许可以通过使用短语来做到这一点
GrammarBuilder thisIsPhrase = new GrammarBuilder("This is");
Choices choices = new Choices("Dog, Cat");
GrammarBuilder endPhrase = new GrammarBuilder(choices);
Choices both = new Choices(new GrammarBuilder[] { thisIsPhrase, endPhrase });
Grammar dictationGrammar = new Grammar((GrammarBuilder)both);
请参见MSDN。
我还不能测试它。
更新:选择短语似乎不起作用。
GrammarBuilder thisIsPhrase = new GrammarBuilder("This is");
GrammarBuilder endPhrase = new GrammarBuilder("Dog"); //repeat creating phrases
Choices both = new Choices(new GrammarBuilder[] { thisIsPhrase, endPhrase });//also need to add phrases here
Grammar dictationGrammar = new Grammar((GrammarBuilder)both);