Speech recognition 基本的语音识别不起作用

Speech recognition 基本的语音识别不起作用,speech-recognition,sapi,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 son

我试图识别简单的英语单词,但没有识别

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);
    }
所以我认为失败的主要原因是语言

在非英语版本的windows中是否有使用英语识别的解决方案? 或 有我没注意到的问题吗

  • 现在我使用的是非英语版本的windows7(64位),我的麦克风连接良好。(我已经检查了控制面板。)

您定义了简单的选择,但没有提到您要匹配的内容。Microsoft Speech使用置信度来确定它是否听到了一个短语,而您在讲话时可能没有达到这个标准

SpeechRecognitionRejected
SpeechOximated
添加回调。看看他们是否开火,从中得到什么信息。它将帮助您调试

简单地寻找“闪烁”、“小”和“星星”这几个词不会让你捕捉到“闪烁、闪烁、小星星”。它会将这些单词作为单个词捕获,但一旦你开始将它们串在一起并添加新词,信心水平就会下降,你获得想要的结果的机会就会大大降低

除了
选项
之外,您还应该定义使用这些选项的短语,并将其置于上下文中。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;
}

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

我添加了SpeechRecognitionRejected和SpeechAspected,但没有从中得到任何信息。我还未经修改就测试了MSDN示例(),但它也不起作用。作为替代方案,我也尝试了Kinect SDK的Speech Basics WPF示例,但它也不起作用。您是否将Kinect用作麦克风?当您运行SpeechBasics WPF并发布任何错误时,是否可以查看输出?尝试沿语音识别路径添加一些Debug.WriteLine语句,查看是否有人触发,并发布结果。我正在测试普通麦克风和Kinect麦克风。这是第一个问题的重复,但Kinect示例中出现了相同的结果。我只是在下一个循环中添加了一些writeline,但并没有消息SpeechRecognitionEngine.InstalledRecognitors()中的识别器信息识别器
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;
}