我有一个应用程序,我使用听写语法和我定义的语法来识别语音。我需要用户定义的语法具有比听写语法更多的优先级,这样语音识别引擎只会在用户定义的语法中没有这个词的情况下查看听写语法。请提供您可能需要的任何想法。
答案 0 :(得分:2)
Grammar类有两个属性权重和优先级。您可以为您创建的语法分配更高的权重,并降低您使用的口述语法的权重。或者,如果您有多个用户定义的语法,则可以使用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);