SAPI 和 Windows 7 问题

发布于 2024-10-03 02:25:52 字数 476 浏览 6 评论 0原文

我尝试使用 Windows 7 识别语音,但它总是将语音识别为命令或只是说“那是什么?”。

我怎样才能获得所有演讲?

代码:

SpeechRecognizer _speechRecognizer;

    public Window1()
    {
        InitializeComponent();

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

I'm trying to recognize speech with Windows 7 but it always recognizes a speech as a command or just says "What was that?".

How I can get all speeches?

CODE:

SpeechRecognizer _speechRecognizer;

    public Window1()
    {
        InitializeComponent();

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

美人骨 2024-10-10 02:25:52

也许您想使用 .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;

然后我将以下事件处理程序添加到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();
    }                          
}

Perhaps you want to use the .net System.Speech namespace instead of SAPI? There is a very good article that was published a few years ago at http://msdn.microsoft.com/en-us/magazine/cc163663.aspx. It is probably the best introductory article I’ve found so far. It is a little out of date, but very helfpul. (The AppendResultKeyValue method was dropped after the beta.)

Are you trying to use a shared recognizer? That may be why you are seeing commands. Do you have a specific task for recognition? In that case, you would be better served with a task specific grammar and an inproc recognizer.

If you need to handle any words, use the DictationGrammar that comes with System.Speech. See http://msdn.microsoft.com/en-us/library/system.speech.recognition.dictationgrammar%28VS.85%29.aspx

For fun, I whipped together the simplest .NET windows forms app to use a dictation grammar that I could think of. I created a form. Dropped a button on it and made the button big. Added a reference to System.Speech and the line:

using System.Speech.Recognition;

Then I added the following event handler to 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();
    }                          
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文