[英]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.