SAPI和Windows 7问题

Kaa*_*aan 2 speech-recognition sapi speech-to-text windows-7

我试图用Windows 7识别语音,但它总是将语音识别为命令或只是说"那是什么?".

我怎么能得到所有的演讲?

码:

SpeechRecognizer _speechRecognizer;

    public Window1()
    {
        InitializeComponent();

        // set up the recognizer
        _speechRecognizer = new SpeechRecognizer();
        _speechRecognizer.Enabled = false;
        _speechRecognizer.SpeechRecognized +=
      new EventHandler<SpeechRecognizedEventArgs>(_speechRecognizer_SpeechRecognized); }
Run Code Online (Sandbox Code Playgroud)

Mic*_*evy 5

也许您想使用.net System.Speech命名空间而不是SAPI?几年前有一篇非常好的文章发表在http://msdn.microsoft.com/en-us/magazine/cc163663.aspx上.这可能是迄今为止我发现的最好的介绍性文章.它有点过时了,但非常好.(测试结束后,AppendResultKeyValue方法被删除了.)

您是否尝试使用共享识别器?这可能就是你看到命令的原因.你有特定的承认任务吗?在这种情况下,您可以更好地使用特定于任务的语法和inproc识别器.

如果您需要处理任何单词,请使用System.Speech附带的DictationGrammar.请参阅http://msdn.microsoft.com/en-us/library/system.speech.recognition.dictationgrammar%28VS.85%29.aspx

为了好玩,我把最简单的.NET Windows窗体应用程序组合在一起,使用我能想到的听写语法.我创建了一个表单.在它上面放了一个按钮,使按钮变大.添加了对System.Speech和行的引用:

using System.Speech.Recognition;
Run Code Online (Sandbox Code Playgroud)

然后我将以下事件处理程序添加到button1:

private void button1_Click(object sender, EventArgs e)
{         
    SpeechRecognitionEngine recognizer = new SpeechRecognitionEngine();
    Grammar dictationGrammar = new DictationGrammar();
    recognizer.LoadGrammar(dictationGrammar);
    try
    {
        button1.Text = "Speak Now";
        recognizer.SetInputToDefaultAudioDevice();
        RecognitionResult result = recognizer.Recognize();
        button1.Text = result.Text;
    }
    catch (InvalidOperationException exception)
    {
        button1.Text = String.Format("Could not recognize input from default aduio device. Is a microphone or sound card available?\r\n{0} - {1}.", exception.Source, exception.Message);
    }
    finally
    {
        recognizer.UnloadAllGrammars();
    }                          
}
Run Code Online (Sandbox Code Playgroud)