0

I am using c# and the windows speech recognition in order to communicate with my program. The only word to be recognized is "Yes", this works fine in my program the only problem is that since the speech recognition is activated it will type in what ever I am saying is there a way to limit the speech recognition program to only recognize one word, in this case the word "yes"?

Thank you

user541597
  • 4,247
  • 11
  • 59
  • 87

2 Answers2

3

What do you mean "since the speech recognition is activated it will type in what ever I am saying"? Are you saying that the desktop recognizer continues to run and handle commands? Perhaps you should be using an inproc recognizer rather than the shared recognizer (see Using System.Speech.Recognition opens Windows Speech Recognition)

Are you using a dictation grammar? If you only want to recognize a limited set of words or commands, do not use the dictation grammar. Use a GrammarBuilder (or similar) and create a simple grammar. See http://msdn.microsoft.com/en-us/library/hh361596

There is a very good article that was published a few years ago at http://msdn.microsoft.com/en-us/magazine/cc163663.aspx. It is probably the best introductory article I’ve found so far. It is a little out of date, but very helfpul. (The AppendResultKeyValue method was dropped after the beta.) Look at the examples of how they build the grammars for ordering Pizza.

One thing to keep in mind, a grammar with one word may show many false positives (since the recognizer will try to match to something in your grammar). You may want to put in at lest Yes and No so it can have something to compare to.

Community
  • 1
  • 1
Michael Levy
  • 13,097
  • 15
  • 66
  • 100
0

If your code is similar to the following:

SpeechRecognitionEngine recognitionEngine = new SpeechRecognitionEngine();
recognitionEngine.SetInputToDefaultAudioDevice();
recognitionEngine.SpeechRecognized += (s, args) =>
{
    foreach (RecognizedWordUnit word in args.Result.Words)
    {
        Console.WriteLine(word.Text);
    }
};
recognitionEngine.LoadGrammar(new DictationGrammar());

Just use an if statement:

foreach (RecognizedWordUnit word in args.Result.Words)
{
    if (word.Text == "yes")
        Console.WriteLine(word.Text);
}

Note that the recognitionEngine.SpeechRecognized is an event handler that happens whenever it recognizes a word and can be used in other ways such as:

{
    recognitionEngine.SpeechRecognized += new EventHandler<SpeechRecognizedEventArgs>(recognizer_SpeechRecognized);
}
//this method is static because I called it from a console main method. It can be changed.
static void recognizer_SpeechRecognized(object sender, SpeechRecognizedEventArgs e)
{
     Console.WriteLine(e.Result.Text);
}

My examples are in a Console but it works the same for GUI.

SuperPrograman
  • 1,814
  • 17
  • 24