2012-10-30 60 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语句,以查看是否有人触发并发布结果。 –