1

I tried to recognition speech in C# but it began bad. I had followed some tutorials in YouTube but this error appear every time. So I got the Microsoft MSDN code and I tried to find some solutions in Google. This is the code I'm using:

public Form1()
    {
        InitializeComponent();
        Initialize();
    }

    private void Initialize()
    {

        // Create a new SpeechRecognitionEngine instance.
        SpeechRecognitionEngine sre = new SpeechRecognitionEngine();
        // Configure the input to the recognizer.
        //sre.SetInputToWaveFile(@"c:\Test\Colors.wav");
        sre.SetInputToDefaultAudioDevice();

        // Create a simple grammar that recognizes "red", "green", or "blue".
        Choices colors = new Choices();
        colors.Add(new string[] { "red", "green", "blue" });

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

        // Create the Grammar instance and load it into the speech recognition engine.
        Grammar g = new Grammar(gb);
        sre.LoadGrammar(g);

        // Register a handler for the SpeechRecognized event.
        sre.SpeechRecognized +=
          new EventHandler<SpeechRecognizedEventArgs>(sre_SpeechRecognized);

        // Start recognition.
        sre.Recognize();
    }

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

I already downloaded the Microsoft Speech Platform SDK and the Runtime Languages (US). The error persists.

I also already had used this code, as I saw in a topic here in StackOverflow:

 sre = new SpeechRecognitionEngine(new CultureInfo("en-GB"));

It didn't work, so I tried to use this (as I saw in MSDN):

 SpeechRecognitionEngine sre = new SpeechRecognitionEngine(new System.Globalization.CultureInfo("en-US"));

When I tried to use those codes, the error change and say: "No recognizer of the required ID found". I use the Windows 7 (Home Basic, x64), Microsoft Visual C# 2010 Express. My default language (the system language also is) is Portuguese (Brazil), maybe it's the error cause? Well, thats it, I hope I wrote all detailed for you understand. Sorry for my english I'm training this, haha :P

Rafael Almeida
  • 677
  • 7
  • 21
  • @Saruman I've switched and the error changed to "No recognizer of the required ID found." in the CultureInfo (when I create the sre). I tried to download the pt-BR file but it also happens. If I leave it alone the error changes to "Speech Recognition is not available on this system. SAPI and Speech Recognition engines cannot be found." – Rafael Almeida Dec 24 '14 at 04:59

1 Answers1

2

Run the following to determine what recognizers you have installed, breakpoint / debug and inspect if you need to

foreach (RecognizerInfo ri in SpeechRecognitionEngine.InstalledRecognizers())
{
    System.Diagnostics.Debug.WriteLine(ri.Culture.Name);
}

And use one of the listed cultures in the SpeechRecognitionEngine constructor

TheGeneral
  • 79,002
  • 9
  • 103
  • 141