• Creating your own custom Grammar, and filtering recognition based on confidence

    by  • January 8, 2009 • .net, c#, grammar, speech recognition • 1 Comment

    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!

    About

    .NET developer at thetrainline.com, previously web developer at MRM Meteorite. Awarded a PhD in misbehaviour detection in wireless ad-hoc networks.A keen C# ASP.net developer bridging the gap with APIs and JavaScript frameworks, one web app at a time.

    http://www.paulkiddie.com

    One Response to Creating your own custom Grammar, and filtering recognition based on confidence

    1. vips
      March 4, 2012 at 10:19 am

      hello i want to build custom grammar which can recognize terms like “mumbai” , ” thane”,”dombivali” etc…plzz help

    Leave a Reply

    Your email address will not be published. Required fields are marked *