[英]C# Speech Recognition
这里有一篇关于那个的帖子......但它对我不起作用。 我添加了一个我在互联网上找到的 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;
}
}
}
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
我同意詹姆斯·奥格登的观点。 此外,您应该添加一个“使用”语句:
using System.Speech.Recognition
或者,完全限定您的 class 名称。
检查您的语言引擎是否与您在 Vista 中配置的语言相匹配。 请参阅http://support.microsoft.com/kb/934377
我在 Windows XP 上遇到有关 SpeechRecognizer class 的问题。 有时它可以工作,但有时它不起作用,需要重新启动电脑。 在 windows 7 上工作正常。 我认为这是语音引擎本身的一些问题,因为当我多次运行我的应用程序时它停止工作。
我使用这段代码:
使用系统; 使用 System.Collections.Generic; 使用 System.ComponentModel; 使用 System.Data; 使用 System.Drawing; 使用 System.Linq; 使用 System.Text; 使用 System.Windows.Forms; 使用语音库; 使用 System.Threading;
命名空间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;
}
}
}
虽然不直接适用于上述问题 - 值得注意的是,语音 SDK 不一定在每台客户端机器上都可用。 虽然 Vista 包含语音识别器,但 XP 没有。 纠正此问题的一种可能方法是让 XP 用户安装 Speech SDK,其中包括一个。 另一种是将Office 2003(不是2007)添加为依赖项。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.