How to mix Grammer (Rules) & Dictation (Free speech) with SpeechRecognizer in C#

Posted by Lee Englestone on Stack Overflow See other posts from Stack Overflow or by Lee Englestone
Published on 2010-06-15T16:07:47Z Indexed on 2010/06/15 16:12 UTC
Read the original article Hit count: 211

I really like Microsofts latest speech recognition (and SpeechSynthesis) offerings.

http://msdn.microsoft.com/en-us/library/ms554855.aspx

http://estellasays.blogspot.com/2009/04/speech-recognition-in-cnet.html

However I feel like I'm somewhat limited when using grammers.

Don't get me wrong grammers are great for telling the speech recognition exactly what words / phrases to look out for, however what if I want it to recognise something i've not given it a heads up about? Or I want to parse a phrase which is half pre-determined command name and half random words?

For example..

Scenario A - I say "Google [Oil Spill]" and I want it to open Google with search results for the term in brackets which could be anything.

Scenario B - I say "Locate [Manchester]" and I want it to search for Manchester in Google Maps or anything else non pre-determined

I want it to know that 'Google' and 'Locate' are commands and what comes after it are parameters (and could be anything).

Question : Does anyone know how to mix the use of pre-determined grammers (words the speech recognition should recognise) and words not in its pre-determined grammer?

Code fragments..

using System.Speech.Recognition;

...
...

SpeechRecognizer rec = new SpeechRecognizer();
rec.SpeechRecognized += rec_SpeechRecognized;

var c = new Choices();
c.Add("search");

var gb = new GrammarBuilder(c);
var g = new Grammar(gb);
rec.LoadGrammar(g);
rec.Enabled = true; 

...
...

void rec_SpeechRecognized(object sender, SpeechRecognizedEventArgs e)
{
    if (e.Result.Text == "search")
    {
        string query = "How can I get a word not defined in Grammer recognised and passed into here!";

        launchGoogle(query);
    }
}

...
...


private void launchGoogle(string term)
{
    Process.Start("IEXPLORE", "google.com?q=" + term);
}

© Stack Overflow or respective owner

Related posts about c#

Related posts about speech-recognition