0
votes

I am trying to write a program that generates speech recognition grammar from a file and stores the phrases in a dictionary where the keys are the phrases. The following code:

sre.LoadGrammarAsync(new Grammar(new GrammarBuilder(new Choices(commands.Keys.ToArray()))));

Throws this exception:

System.InvalidOperationException: The language for the grammar does not match the language of the speech recognizer.
   vid System.Speech.Recognition.RecognizerBase.ThrowIfSapiErrorCode(SAPIErrorCodes errorCode)
   vid System.Speech.Recognition.RecognizerBase.LoadSapiGrammarFromCfg(SapiGrammar sapiGrammar, Grammar grammar, Uri baseUri, Boolean enabled, Single weight, Int32 priority)
   vid System.Speech.Recognition.RecognizerBase.LoadSapiGrammar(Grammar grammar, SapiGrammar sapiGrammar, Boolean enabled, Single weight, Int32 priority)
   vid System.Speech.Recognition.RecognizerBase.LoadGrammarAsyncCallback(Object grammarObject)

And I have no idea of why this is happening, because all generated phrases are in English, and the program specifically demands the SpeechRecognitionEngine to use a RecognizerInfo with a culture of en-US (or Culture.TwoLetterISOLanguageName of "en").

I have MS-1033-80-DESK (en-US) Microsoft Speech Recognizer 8.0 for Windows (English - US) installed.

1

1 Answers

0
votes

I simply had to specify the Culture of my grammar. Here's the working code:

sre.LoadGrammarAsync(new Grammar(
    new GrammarBuilder(new Choices(commands.Keys.ToArray())) {
        Culture = new System.Globalization.CultureInfo(Settings.CompatibleCultureInfo)
    }
));