SAPI 和 Windows 7 问题 [英] SAPI and Windows 7 Problem

查看:44
本文介绍了SAPI 和 Windows 7 问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

我如何获得所有演讲?

代码:

SpeechRecognizer _speechRecognizer;

    public Window1()
    {
        InitializeComponent();

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

推荐答案

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

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.)

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

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.

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

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

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

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;

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

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();
    }                          
}

这篇关于SAPI 和 Windows 7 问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆