2014-07-08 282 views
4

美好的一天!它關於Microsoft Server Speech SDK v11.0(服務器版本)。語法語言與語音識別器的語言不匹配

我在MSDN sample上運行測試示例。 所以英語短語 - 紅色,藍色 - 很好的認識。 但我想認識俄語太 - 安裝微軟的語音識別語言-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,但它不起作用... 謝謝!

回答

0

看起來你需要

SpeechRecognitionEngine recognizer = 
     new SpeechRecognitionEngine(
      new System.Globalization.CultureInfo("ru-RU"))) 
6

更改GrammarBuilder.Culture財產會解決這個錯誤。

後:

GrammarBuilder gb = new GrammarBuilder(); 

地址:

gb.Culture = Thread.CurrentThread.CurrentCulture 

以便使文法文化識別器相匹配。

+0

這個答案是錯誤的。線程的文化是完全不相關的,它可以是任何東西。你必須設置GrammarBuilder.Culture = myCulture和新的SpeechRecognitionEngine(myCulture);然後,異常消失了。 – Elmue

0

語法生成器文化必須與語音識別器匹配。最簡單的方法是將語法文化設置爲與語音識別器相同,如下所示:

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

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