Язык грамматики не соответствует языку распознавателя речи.

Добрый день! Речь идет о Microsoft Server Speech SDK v11.0 (версия для сервера).

Я запустил тестовый пример в образце MSDN . Так что английские фразы -red,blue - распознаются хорошо. Но я тоже хочу распознавать русский язык - устанавливаю Microsoft Speech Recognition Language -TELE (ru-RU) и запускаю мое приложение/

Код:

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

Ошибка появляется в этой строке:

 sre.LoadGrammar(g);

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

Итак, как исправить эту ошибку? Пытаюсь установить CultureInfo, но не получается... Спасибо!


person user2545071    schedule 08.07.2014    source источник


Ответы (3)


Похоже, вам нужно

SpeechRecognitionEngine recognizer =
        new SpeechRecognitionEngine(
          new System.Globalization.CultureInfo("ru-RU")))
person Nikolay Shmyrev    schedule 08.07.2014

Изменение свойства GrammarBuilder.Culture устранит эту ошибку.

После:

GrammarBuilder gb = new GrammarBuilder();

Добавлять:

gb.Culture = Thread.CurrentThread.CurrentCulture

Чтобы культура грамматики соответствовала распознавателю.

person Kevor Wang    schedule 15.06.2015
comment
Этот ответ неверен. Культура треда совершенно не имеет значения, это может быть что угодно. Вы должны установить GrammarBuilder.Culture = myCulture и новый SpeechRecognitionEngine(myCulture); Тогда исключение исчезнет. - person Elmue; 26.08.2017

Культура построителя грамматики должна соответствовать распознавателю речи. Самый простой способ сделать это — установить культуру грамматики так же, как и распознаватель речи, как показано ниже:

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

// set the culture
gb.Culture = sr.RecognizerInfo.Culture;
person aleksk    schedule 14.09.2017