简体   繁体   English

C# 语音识别

[英]C# Speech Recognition

There is a post in here about that...but it doesn't work for me.这里有一篇关于那个的帖子......但它对我不起作用。 I have added a system.speech.dll that I found in the internet but i cannot use System.speech, because it doesn't appear.我添加了一个我在互联网上找到的 system.speech.dll,但我不能使用 System.speech,因为它没有出现。

Error 1 The type or namespace name 'SpeechRecognizer' could not be found (are you missing a using directive or an assembly reference?)错误 1 找不到类型或命名空间名称“SpeechRecognizer”(您是否缺少 using 指令或程序集引用?)

Error 2 The type or namespace name 'SpeechRecognizedEventArgs' could not be found (are you missing a using directive or an assembly reference?)错误 2 找不到类型或命名空间名称“SpeechRecognizedEventArgs”(您是否缺少 using 指令或程序集引用?)

I have used this code.我用过这段代码。 I am using Windows Vista 64我正在使用 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;
        }
    }
}

1) You need to add a reference to System.Speech in your project 1)您需要在项目中添加对 System.Speech 的引用

2) You shouldn't have had to find 'System.Speech.dll' on the Internet, it should be in.Net 3 (or 3.5, but get 3.5 anyway unless you've a compelling reason not to) 2)您不必在 Internet 上找到“System.Speech.dll”,它应该在.Net 3(或 3.5,但无论如何都要获得 3.5,除非您有令人信服的理由不这样做)

Edit:编辑:

You might want to look here:你可能想看这里:

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

I agree with James Ogden.我同意詹姆斯·奥格登的观点。 Also, you should add a "using" statement:此外,您应该添加一个“使用”语句:

using System.Speech.Recognition

Or, fully qualify your class names.或者,完全限定您的 class 名称。

Check that you have a language engine matching the language you have configured in Vista.检查您的语言引擎是否与您在 Vista 中配置的语言相匹配。 See http://support.microsoft.com/kb/934377请参阅http://support.microsoft.com/kb/934377

Im having problem about SpeechRecognizer class on Windows XP.我在 Windows XP 上遇到有关 SpeechRecognizer class 的问题。 sometimes it works but sometimes it doesnot work, and need to restart pc.有时它可以工作,但有时它不起作用,需要重新启动电脑。 on windows 7 its working fine.在 windows 7 上工作正常。 I think its some problem in speech engine itself, cause when I run my application several times it stops working.我认为这是语音引擎本身的一些问题,因为当我多次运行我的应用程序时它停止工作。

Im using this code:我使用这段代码:

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

namespace WindowsFormsApplication13 { public partial class Form1: Form {命名空间WindowsFormsApplication13 {公共部分class Form1:表格{

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

} }

While not directly applicable to the above question - it is worth noting that the Speech SDK will not nessecarily be availible on each clients machines.虽然不直接适用于上述问题 - 值得注意的是,语音 SDK 不一定在每台客户端机器上都可用。 While Vista includes a speech recognizer, XP does not.虽然 Vista 包含语音识别器,但 XP 没有。 A possible way to correct this is to get the XP users to install the Speech SDK, which includes one.纠正此问题的一种可能方法是让 XP 用户安装 Speech SDK,其中包括一个。 The other is to add Office 2003 (not 2007) as a dependency.另一种是将Office 2003(不是2007)添加为依赖项。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM