1

我有一个应用程序,我在其中使用听写语法和我定义的用于识别语音的语法。我需要用户定义的语法比听写语法具有更高的优先级,以便语音识别引擎仅在用户定义的语法中没有该单词时才查看听写语法。请给出您可能需要的任何想法来完成这项工作。

4

1 回答 1

2

语法类有两个属性WeightPriority。您可以为您创建的语法分配更高的权重,为您使用的听写语法分配较低的权重。或者,如果您有多个用户定义的语法,您可以使用 priority 属性来指示一种语法优先于另一种语法。请参见以下示例;

// Create a Grammar for recognizing numeric digits.
Grammar digitsGrammar = CreateDigitsGrammar();
digitsGrammar.Name = "Digits Grammar";
digitsGrammar.Priority = 2;
digitsGrammar.Weight = 0.6f;

// Create a Grammar for recognizing fractions.
Grammar fractionsGrammar = CreateFractionsGrammar();
fractionsGrammar.Name = "Fractions Grammar";
fractionsGrammar.Priority = 1;
fractionsGrammar.Weight = 1f;

// Create an in-process speech recognizer.
SpeechRecognitionEngine recognizer = new SpeechRecognitionEngine();

recognizer.SpeechRecognized +=new EventHandler<SpeechRecognizedEventArgs>(
recognizer_SpeechRecognized);

// Load the digits and fractions Grammar objects.
 recognizer.LoadGrammar(digitsGrammar);
 recognizer.LoadGrammar(fractionsGrammar);

 // Start recognition.
 recognizer.SetInputToDefaultAudioDevice();
 recognizer.RecognizeAsync(RecognizeMode.Multiple);
于 2013-08-29T19:51:41.517 回答