Question

I'm trying to recognize simple english words, but no recognition occur.

private void Form1_Load(object sender, EventArgs e)
    {
        SpeechRecognitionEngine srEngine = new SpeechRecognitionEngine();

        // Create a simple grammar that recognizes "twinkle", "little", "star"
        Choices song_00 = new Choices();
        song_00.Add(new string[] {"twinkle", "little", "star"});

        // Create a GrammarBuilder object and append the choices object
        GrammarBuilder gb = new GrammarBuilder();
        gb.Append(song_00);

        // Create the grammar instance and load it into the sppech reocognition engine.
        Grammar g = new Grammar(gb);

        g.Enabled = true;

        srEngine.LoadGrammar(g);
        srEngine.SetInputToDefaultAudioDevice();
        // Register a handler for the Speechrecognized event.
        srEngine.SpeechRecognized += new EventHandler<SpeechRecognizedEventArgs>(sre_SpeechRecognized);
        srEngine.RecognizeAsync(RecognizeMode.Multiple);
    }

    // Create a simple handler for the SpeechRecognized event.
    void sre_SpeechRecognized(object sender, SpeechRecognizedEventArgs e)
    {
        MessageBox.Show("Speech recognized: " + e.Result.Text);
    }

Below one does not show any message, too.

foreach (RecognizerInfo ri in SpeechRecognitionEngine.InstalledRecognizers())
{
    MessageBox.Show(ri.Culture);
}

So the main reason of failing that I can think is language.

Is there any solution to use english recognition in non-english version of windows? or Is there problems that I couldn't notice?

  • Now I'm using non-english version of windows7(64-bit), and my mic is connected well. (I already checked the control panel.)
Was it helpful?

Solution

You have simple choices defined, but you don't mention what exactly you are trying to match. Microsoft Speech uses a confidence scale in order to decide if it heard a phrase, and you may not be hitting this mark when you are speaking.

Add a callback for SpeechRecognitionRejected and SpeechHypothesized. See if they are firing and what information is coming out of them. It will help you debug.

Simply looking for the words "twinkle", "little" and "star" will not allow you capture "Twinkle, twinkle, little star". It will capture those words as singletons, but as soon as you start stringing them together and adding new words the confidence level will go down and you will have a much lower chance of getting the result you want.

In addition to Choices you should also be defining phrases that use those choices and put them into context. The GrammerBuilder class documentation at MSDN gives an example:

private Grammar CreateColorGrammar()
{

  // Create a set of color choices.
  Choices colorChoice = new Choices(new string[] {"red", "green", "blue"});
  GrammarBuilder colorElement = new GrammarBuilder(colorChoice);

  // Create grammar builders for the two versions of the phrase.
  GrammarBuilder makePhrase = new GrammarBuilder("Make background");
  makePhrase.Append(colorElement);
  GrammarBuilder setPhrase = new GrammarBuilder("Set background to");
  setPhrase.Append(colorElement);

  // Create a Choices for the two alternative phrases, convert the Choices
  // to a GrammarBuilder, and construct the grammar from the result.
  Choices bothChoices = new Choices(new GrammarBuilder[] {makePhrase, setPhrase});
  Grammar grammar = new Grammar((GrammarBuilder)bothChoices);
  grammar.Name = "backgroundColor";
  return grammar;
}

Notice that the code does not assume that "Set background to blue" will be captured. It explicitly sets that condition up.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top