C#语音识别

C#语音识别,c#,speech-recognition,C#,Speech Recognition,这里有一篇关于这个的帖子……但对我来说不起作用。我已经添加了在internet上找到的system.speech.dll,但我无法使用system.speech,因为它没有出现 错误1找不到类型或命名空间名称“SpeechRecognizer”(是否缺少using指令或程序集引用?) 错误2找不到类型或命名空间名称“SpeechRecognizedEventArgs”(是否缺少using指令或程序集引用?) 我用过这个代码。我正在使用Windows Vista 64 using System;

这里有一篇关于这个的帖子……但对我来说不起作用。我已经添加了在internet上找到的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;
        }
    }
}
使用系统;
使用System.Collections.Generic;
使用系统组件模型;
使用系统数据;
使用系统图;
使用System.Linq;
使用系统文本;
使用System.Windows.Forms;
使用SpeechLib;
使用系统线程;
命名空间Windows窗体应用程序13
{
公共部分类Form1:Form
{
SpeechRecognizer rec=新的SpeechRecognizer();
公共表格1()
{
初始化组件();
rec.speechrecogned+=rec_speechrecogned;
}
void rec_SpeechRecognized(对象发送方,SpeechRecognizedEventArgs e)
{
lblLetter.Text=e.Result.Text;
}
私有void Form1\u加载(对象发送方、事件参数e)
{
var c=新选择();
//不工作的人必须使用英语单词来添加选择和
//填充语法。
//
//对于(var i=0;i1),您需要在项目中添加对System.Speech的引用

2) 你不应该非得在互联网上找到“System.Speech.dll”,它应该在.NET3中(或3.5中,但无论如何都要得到3.5,除非你有令人信服的理由不这样做)

编辑:

您可能想看看这里:


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

using System.Speech.Recognition

或者,完全限定您的类名。

虽然不直接适用于上述问题,但值得注意的是,Speech SDK不一定在每个客户端计算机上都可用。虽然Vista包括语音识别器,但XP不包括。纠正这一问题的可能方法是让XP用户安装Speech SDK,其中包括一是增加Office 2003(而不是2007)作为依赖项。

检查您的语言引擎是否与您在Vista中配置的语言匹配。请参阅

在Windows XP上,我对SpeechRecognitor类有问题。有时它可以工作,但有时不工作,需要重新启动pc。在Windows 7上,它工作正常。我认为语音引擎本身存在一些问题,导致w当我运行应用程序几次时,它就会停止工作

我正在使用这个代码:

使用制度; 使用System.Collections.Generic; 使用系统组件模型; 使用系统数据; 使用系统图; 使用System.Linq; 使用系统文本; 使用System.Windows.Forms; 使用SpeechLib; 使用系统线程

命名空间Windows窗体应用程序13 { 公共部分类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;
    }
}