2

我想使用这样的语法:这是 + name

代码是:

GrammarBuilder grammar = new GrammarBuilder();
grammar.Append("This is");
gammar.Append(new Choices("Bangalore", "Sanjay", "Cindy",...));
_recognizer.LoadGrammar(new Grammar(grammar));

我的问题是,我可以在引擎识别This is时发送事件,并在引擎识别名称时发送另一个事件吗?

这个怎么做?

4

1 回答 1

0

我认为您可以通过使用短语来做到这一点

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); 
于 2014-10-09T16:50:23.240 回答