Creating your own custom Grammar, and filtering recognition based on confidence
January 08, 2009
This follows on from an earlier post, Speech Recognition and the System.Speech namespace, where I was trying to find out roughly what the the topic of a given set of unannotated lectures was. As expected, using the DictationGrammar
didn’t help too much, in fact some of the results from the recogniser were pretty funny! So I set out to add some extra functionality whereby the forms application would let you input a CSV list of words constituting a grammar, and furthermore, only areas where the recognition was over a certain confidence level would be marked down, along with the position in the movie file.
Creating a custom grammar was pretty straightforward, and something like this:
GrammarBuilder builder = new GrammarBuilder(); builder.Culture = new CultureInfo(“en-US”); builder.Append(new Choices(textBoxCustomGrammar.Text.Split(’,’))); //choices constructor takes in array of strings corresponding to a list of words in my custom grammar gram = new Grammar(builder); recog.LoadGrammar(gram);
The next thing was that I only wanted a recognition result only when the recogniser above a certain confidence I had stored in the confidence
variable. A simple update of the SpeechRecognised
event helped me here.
void recog_SpeechRecognized(object sender, SpeechRecognizedEventArgs e) { if (e.Result.Confidence >= confidence && radioButtonCustom.Checked) // custom grammar { textBoxRecognition.Invoke(new UpdateTextDelegate(UpdateTextBox),e.Result.Confidence+” “+e.Result.Audio.AudioPosition+”: “+e.Result.Text+”\r\n”); }
else if (radioButtonDict.Checked) //dictation grammar{textBoxRecognition.Invoke(new UpdateTextDelegate(UpdateTextBox), e.Result.Text);}}
This gave me something I could work with a little bit more. The fact I knew what field the lectures was in helped, as I could pre-load it with terms I wanted to search for effectively. Hope it helps someone!