这里有一篇关于这个的帖子......但它对我不起作用.我添加了一个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;
}
}
}
Run Code Online (Sandbox Code Playgroud)
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
| 归档时间: |
|
| 查看次数: |
5551 次 |
| 最近记录: |