The language for the grammar does not match the language of the speech recognizer

Good afternoon! This is a Microsoft Server Speech SDK v11.0 (server version).

I ran a test case sample MSDN . So, the English phrases - red, blue - are well known. But I also want to recognize Russian - install Microsoft Speech Recognition Language -TELE (ru-RU) and run my application /

the code:

 static void DoWork()
    {

        Thread.CurrentThread.CurrentCulture = new CultureInfo("ru-RU");
        Thread.CurrentThread.CurrentUICulture = new CultureInfo("ru-RU");

        // Create a new SpeechRecognitionEngine instance.
        SpeechRecognitionEngine sre = new SpeechRecognitionEngine();

        // Configure the input to the recognizer.
        sre.SetInputToWaveFile(@"c:\Test\.wav");

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

        // Create a GrammarBuilder object and append the Choices object.
        GrammarBuilder gb = new GrammarBuilder();
        gb.Culture = new CultureInfo("ru-RU"); // add Culture Info

        gb.Append(colors);

        Console.WriteLine(gb.Culture.CultureTypes);

        // 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.
    static void sre_SpeechRecognized(object sender, SpeechRecognizedEventArgs e)
    {
        Console.WriteLine(String.Format("Speech recognized: {0}",e.Result.Text));

    }

An error appears on this line:

 sre.LoadGrammar(g);

The language for the grammar does not match the language of the speech recognizer.

So how to fix this error? I am trying to install CultureInfo, but it does not work ... Thanks!

+4
source share
3 answers

Sounds like you need

SpeechRecognitionEngine recognizer =
        new SpeechRecognitionEngine(
          new System.Globalization.CultureInfo("ru-RU")))
+1
source

GrammarBuilder.Culture, .

:

GrammarBuilder gb = new GrammarBuilder();

:

gb.Culture = Thread.CurrentThread.CurrentCulture

.

+6

. - , , :

var sr = new SpeechRecognizer();
var gb = new GrammarBuilder();

// set the culture
gb.Culture = sr.RecognizerInfo.Culture;
0

Source: https://habr.com/ru/post/1547579/


All Articles