基本语音识别不起作用

时间:2012-10-30 03:09:29

标签: speech-recognition sapi

我正在尝试识别简单的英语单词,但不会发生任何认可。

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位),我的麦克风连接良好。 (我已经检查了控制面板。)

1 个答案:

答案 0 :(得分:0)

您已定义了简单的选项,但未提及您要确切匹配的内容。 Microsoft Speech使用置信度量表来判断它是否听到了一个短语,并且在您说话时可能没有达到此标记。

SpeechRecognitionRejectedSpeechHypothesized添加回调。看看他们是否正在开火以及他们会发出什么信息。它可以帮助您调试。

简单地寻找单词“twinkle”,“little”和“star”将不允许你捕捉“Twinkle,twinkle,little star”。它会将这些单词捕获为单例,但只要你开始将它们串在一起并添加新单词,置信度就会下降,你获得所需结果的可能性就会大大降低。

除了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;
}

请注意,代码不会假定将捕获“将背景设置为蓝色”。它明确地设定了这个条件。

相关问题