The language for the grammar does not match the language of the speech recognizer
Asked Answered
T

3

5

Good day! It is about Microsoft Server Speech SDK v11.0 (Server version).

I have run test example at MSDN sample . So English phrases -red,blue - recognized well. But I want to recognize Russian language too -install Microsoft Speech Recognition Language -TELE (ru-RU) and runs my app/

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));
      
    }

Error appears at 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 try to set CultureInfo, but it does not works... Thank you!

Tetrastich answered 8/7, 2014 at 11:21 Comment(0)
A
2

Looks like you need

SpeechRecognitionEngine recognizer =
        new SpeechRecognitionEngine(
          new System.Globalization.CultureInfo("ru-RU")))
Arran answered 8/7, 2014 at 17:57 Comment(0)
J
6

Change the GrammarBuilder.Culture property would solve this error.

After:

GrammarBuilder gb = new GrammarBuilder();

Add:

gb.Culture = Thread.CurrentThread.CurrentCulture

So that the grammar culture matches the recognizer.

Jepson answered 15/6, 2015 at 9:1 Comment(1)
This answer is wrong. The culture of the thread is completely irrelevant, it can be anything. You have to set GrammarBuilder.Culture = myCulture and new SpeechRecognitionEngine(myCulture); Then the exception is gone.Wampler
A
2

Looks like you need

SpeechRecognitionEngine recognizer =
        new SpeechRecognitionEngine(
          new System.Globalization.CultureInfo("ru-RU")))
Arran answered 8/7, 2014 at 17:57 Comment(0)
C
2

The grammar builder culture has to match the speech recognizer. The easiest way to do this is by setting the grammar culture to be the same as the speech recognizer, as below:

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

// set the culture
gb.Culture = sr.RecognizerInfo.Culture;
Cheerly answered 14/9, 2017 at 12:9 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.