1
votes

I have an application where I use dictation grammar and a grammar I defined to recognize speech. I need the user defined grammar to have more precedence than the dictation grammar so that the speech recognition engine will only look into dictation grammar if the word is not available in user defined grammar. Please give any ideas you may have to make this work.

1

1 Answers

2
votes

Grammar class has two properties Weight and Priority. You can assign higher weight to the grammar you created and lower weight to dictation grammar you use. Or if you have multiple user defined grammars, you can use priority property to indicate that one grammar has priority over another. See following example;

// 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);