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

    by  • January 8, 2009 • .net, c#, grammar, speech recognition • 0 Comments

    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

    Web Developer for MRM Meteorite. Awarded a PhD in research into novel techniques to detect misbehaviour in peer-to-peer wireless networks. Experienced C# and ASP.net developer, with an interest in SOA, RIA and moble app development.

    http://www.paulkiddie.com

    Leave a Reply

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