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

1 回答 1

0

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

SpeechRecognitionRejected为和添加回调SpeechHypothesized。看看他们是否在开火,以及从他们那里得到什么信息。它将帮助您调试。

仅仅寻找“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;
}

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

于 2012-10-30T17:59:47.607 回答