2012-10-30 55 views
0

我試圖識別簡單的英語單詞,但沒有識別出現。基本語音識別不起作用

private void Form1_Load(object sender, EventArgs e) 
    { 
     SpeechRecognitionEngine srEngine = new SpeechRecognitionEngine(); 

     // Create a simple grammar that recognizes "twinkle", "little", "star" 
     Choices song_00 = new Choices(); 
     song_00.Add(new string[] {"twinkle", "little", "star"}); 

     // Create a GrammarBuilder object and append the choices object 
     GrammarBuilder gb = new GrammarBuilder(); 
     gb.Append(song_00); 

     // Create the grammar instance and load it into the sppech reocognition engine. 
     Grammar g = new Grammar(gb); 

     g.Enabled = true; 

     srEngine.LoadGrammar(g); 
     srEngine.SetInputToDefaultAudioDevice(); 
     // Register a handler for the Speechrecognized event. 
     srEngine.SpeechRecognized += new EventHandler<SpeechRecognizedEventArgs>(sre_SpeechRecognized); 
     srEngine.RecognizeAsync(RecognizeMode.Multiple); 
    } 

    // Create a simple handler for the SpeechRecognized event. 
    void sre_SpeechRecognized(object sender, SpeechRecognizedEventArgs e) 
    { 
     MessageBox.Show("Speech recognized: " + e.Result.Text); 
    } 

下面的一個也不顯示任何消息。

foreach (RecognizerInfo ri in SpeechRecognitionEngine.InstalledRecognizers()) 
{ 
    MessageBox.Show(ri.Culture); 
} 

所以我認爲失敗的主要原因是語言。

是否有任何解決方案在非英語版本的Windows中使用英文識別? 或 有沒有我無法注意到的問題?

  • 現在我使用非英語版的windows7(64位),並且我的麥克風連接良好。 (我已經檢查了控制面板。)

回答

0

你有簡單的選擇定義,但你沒有提到你想要匹配的是什麼。 Microsoft Speech使用置信度來判斷它是否聽到了一個短語,並且當您說話時您可能不會觸及此標記。

SpeechRecognitionRejectedSpeechHypothesized添加回調。看看他們是否正在解僱,以及他們有什麼信息。它會幫助你調試。

只需尋找「閃爍」,「小」和「星」等字樣,就不會讓您捕捉到「閃爍,閃爍,小星星」。它會將這些單詞捕獲爲單身人士,但只要您開始將它們串起來並添加新單詞,置信度就會降低,並且獲得想要的結果的機會會更低。

除了Choices之外,您還應該定義使用這些選項的短語並將其放入上下文中。在MSDN的GrammerBuilder類文檔舉了一個例子:

private Grammar CreateColorGrammar() 
{ 

    // Create a set of color choices. 
    Choices colorChoice = new Choices(new string[] {"red", "green", "blue"}); 
    GrammarBuilder colorElement = new GrammarBuilder(colorChoice); 

    // Create grammar builders for the two versions of the phrase. 
    GrammarBuilder makePhrase = new GrammarBuilder("Make background"); 
    makePhrase.Append(colorElement); 
    GrammarBuilder setPhrase = new GrammarBuilder("Set background to"); 
    setPhrase.Append(colorElement); 

    // Create a Choices for the two alternative phrases, convert the Choices 
    // to a GrammarBuilder, and construct the grammar from the result. 
    Choices bothChoices = new Choices(new GrammarBuilder[] {makePhrase, setPhrase}); 
    Grammar grammar = new Grammar((GrammarBuilder)bothChoices); 
    grammar.Name = "backgroundColor"; 
    return grammar; 
} 

注意,代碼不認爲「設置背景爲藍色」將被捕獲。它明確地設置了這個條件。

+0

我加了SpeechRecognitionRejected和SpeechHypothesized,但沒有任何信息出來。我還測試了MSDN示例(http://msdn.microsoft.com/en-us/library/hh361683.aspx)而不進行修改,但它也不起作用。 – Walker

+0

另外,我也嘗試過Kinect SDK的Speech Basics-WPF示例,但它也根本不起作用。 – Walker

+0

您是否將Kinect用作麥克風?當您運行SpeechBasics-WPF併發布任何錯誤時,您可以查看輸出嗎?嘗試在語音識別路徑中添加一些Debug.WriteLine語句,以查看是否有人觸發併發布結果。 –