Search code examples
c#speech-recognitionsapi

SpeechRecognizer.SpeechRecognized Event is not working with Speech Recognizer (English-UK)


I created a simple grammar in C# and after that I used SpeechRecognizer.SpeechRecognized Event. but I don't know why it works with Microsoft Speech Recognizer (English-US), But it doesn't work with Microsoft Speech Recognizer (English-UK).

here is the code:

    private void button1_Click(object sender, EventArgs e)
    {
        System.Speech.Recognition.SpeechRecognizer sr = new SpeechRecognizer();
        Choices Slist = new Choices();
        Slist.Add(new string[] { "Brazil", "Germany", "Argentina", "Netherlands" });
        Grammar gr = new Grammar(new GrammarBuilder(Slist));
        sr.RequestRecognizerUpdate();
        sr.LoadGrammarAsync(gr);
        sr.SpeechRecognized += sr_SpeechRecognized;

    }

    void sr_SpeechRecognized(object sender, SpeechRecognizedEventArgs e)
    {
        if (e.Result.Text.ToString()== "Brazil")
        {
            MessageBox.Show("Fourth");
        }
        if (e.Result.Text.ToString() == "Germany")
        {
            MessageBox.Show("First");
        }
        if (e.Result.Text.ToString() == "Argentina")
        {
            MessageBox.Show("Second");
        }
        if (e.Result.Text.ToString() == "Netherlands")
        {
            MessageBox.Show("third");
        }
    }

Any help would be appreciated.


Solution

  • Apparently the Culture property on the GrammarBuilder object must match the Culture of the recognizer in order to get recognitions to work.