0

Hi everyone,
I was going through a tutorial blog for speech recognition, and tried the following code Which is supposed to print "Hello world" on the screen. But it generates an error InvalidOperationException on line 16 and says "The language for the grammar does not match the language of the speech recognizer." Can anyone help me in this?

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Speech.Recognition;

namespace speach
{
    class Program
    {
        static void Main(string[] args)
        {
            SpeechRecognitionEngine srEngine = new SpeechRecognitionEngine();
            Grammar gram = new Grammar("helloworld.xml");
            srEngine.LoadGrammar(gram);  // error here!
            srEngine.SetInputToWaveFile("helloworld.wav");
            srEngine.SpeechRecognized += new EventHandler<SpeechRecognizedEventArgs>(srEngine_SpeechRecognized);
            srEngine.Recognize();
        }

        static void srEngine_SpeechRecognized(object sender, SpeechRecognizedEventArgs e)
        {
            Console.WriteLine("Detected: " + e.Result.Text);
        }

    }
}
2
Contributors
1
Reply
18
Views
3 Years
Discussion Span
Last Post by humorousone
0

My best guess is that there's a mistake somewhere in helloworld.xml.

Double check that everything's formatted correctly and the syntax is correct.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.