6

这里有一篇关于那个的帖子......但它对我不起作用。我添加了一个我在互联网上找到的 system.speech.dll 但我不能使用 System.speech ,因为它没有出现。

错误 1 ​​找不到类型或命名空间名称“SpeechRecognizer”(您是否缺少 using 指令或程序集引用?)

错误 2 找不到类型或命名空间名称“SpeechRecognizedEventArgs”(您是否缺少 using 指令或程序集引用?)

我用过这段代码。我正在使用 Windows Vista 64

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using SpeechLib;
using System.Threading;


namespace WindowsFormsApplication13
{
    public partial class Form1 : Form
    {

        SpeechRecognizer rec = new SpeechRecognizer();

        public Form1()
        {
            InitializeComponent();
            rec.SpeechRecognized += rec_SpeechRecognized;
        }

        void rec_SpeechRecognized(object sender, SpeechRecognizedEventArgs e)
        {
            lblLetter.Text = e.Result.Text;
        }


        private void Form1_Load(object sender, EventArgs e)
        {
            var c = new Choices();

            // Doens't work must use English words to add to Choices and
            // populate grammar.
            //
            //for (var i = 0; i <= 100; i++)
            //  c.Add(i.ToString());

            c.Add("one");
            c.Add("two");
            c.Add("three");
            c.Add("four");
            c.Add("Five");
            c.Add("six");
            c.Add("seven");
            c.Add("eight");
            c.Add("nine");
            c.Add("ten");

            // etc...

            var gb = new GrammarBuilder(c);
            var g = new Grammar(gb);
            rec.LoadGrammar(g);
            rec.Enabled = true;
        }
    }
}
4

5 回答 5

4

1)您需要在项目中添加对 System.Speech 的引用

2)您不必在 Internet 上找到“System.Speech.dll”,它应该在 .Net 3 中(或 3.5,但无论如何都要获得 3.5,除非您有令人信服的理由不这样做)

编辑:

你可能想看这里:

http://dotnet.org.za/beta/archive/2008/01/06/system-speech-recognition.aspx

于 2009-02-25T12:15:41.493 回答
4

我同意詹姆斯·奥格登的观点。此外,您应该添加一个“使用”语句:

using System.Speech.Recognition

或者,完全限定您的班级名称。

于 2009-02-25T12:17:13.970 回答
1

Check that you have a language engine matching the language you have configured in Vista. See http://support.microsoft.com/kb/934377

于 2009-03-16T17:09:53.217 回答
0

虽然不直接适用于上述问题 - 值得注意的是,语音 SDK 不一定在每台客户端机器上都可用。虽然 Vista 包含语音识别器,但 XP 没有。纠正此问题的一种可能方法是让 XP 用户安装语音 SDK,其中包括一个。另一种是将Office 2003(不是2007)添加为依赖项。

于 2009-02-26T09:23:18.797 回答
0

我在 Windows XP 上遇到了 SpeechRecognizer 类的问题。有时它可以工作,但有时它不起作用,需要重新启动电脑。在 Windows 7 上它工作正常。我认为这是语音引擎本身的一些问题,因为当我多次运行我的应用程序时它停止工作。

我使用这段代码:

使用系统;使用 System.Collections.Generic;使用 System.ComponentModel;使用 System.Data;使用 System.Drawing;使用 System.Linq;使用 System.Text;使用 System.Windows.Forms;使用语音库;使用 System.Threading;

命名空间 WindowsFormsApplication13 { 公共部分类 Form1 : Form {

    SpeechRecognizer rec = new SpeechRecognizer();

    public Form1()
    {
        InitializeComponent();
        rec.SpeechRecognized += rec_SpeechRecognized;
    }

    void rec_SpeechRecognized(object sender, SpeechRecognizedEventArgs e)
    {
        lblLetter.Text = e.Result.Text;
    }


    private void Form1_Load(object sender, EventArgs e)
    {
        var c = new Choices();


        c.Add("one");
        c.Add("two");
        c.Add("three");
        c.Add("four");
        c.Add("Five");
        c.Add("six");
        c.Add("seven");
        c.Add("eight");
        c.Add("nine");
        c.Add("ten");

        // etc...

        var gb = new GrammarBuilder(c);
        var g = new Grammar(gb);
        rec.LoadGrammar(g);
        rec.Enabled = true;
    }
}

}

于 2010-12-18T11:58:13.107 回答