每当我尝试在我的笔记本电脑中编写任何语音识别程序时,我总会得到与下面提到的相同的消息。我总是可以编译我的代码并使Windows窗体应用程序正常工作。但问题是,程序将会没有察觉我的声音......程序不会工作..
我非常确定我的代码工作正常,因为我通常从youtube视频中获取代码,例如:https://www.youtube.com/watch?v=KR0-UYUGYgA等等。 我正在为我的项目使用.NET framework 4客户端配置文件..我只参考“system.speech”......可能是我的问题?
调试我得到的消息:
speaker.vshost.exe Information: 0 : SAPI does not implement phonetic alphabet selection.
A first chance exception of type 'System.Runtime.InteropServices.COMException' occurred in System.Speech.dll
A first chance exception of type 'System.InvalidOperationException' occurred in System.Speech.dll
A first chance exception of type 'System.InvalidOperationException' occurred in System.Speech.dll
A first chance exception of type 'System.InvalidOperationException' occurred in System.Speech.dll
我尝试的示例代码:
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 System.Speech.Synthesis;
using System.Speech.Recognition;
using System.Threading;
using System.Threading.Tasks;
namespace speaker
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
SpeechSynthesizer sSynth = new SpeechSynthesizer();
PromptBuilder pBuilder = new PromptBuilder();
SpeechRecognitionEngine sRecognize = new SpeechRecognitionEngine();
private void Form1_Load(object sender, EventArgs e)
{
}
private void button1_Click(object sender, EventArgs e)
{
pBuilder.ClearContent();
pBuilder.AppendText(textBox1.Text);
sSynth.Speak(pBuilder);
}
private void button2_Click(object sender, EventArgs e)
{
button2.Enabled = false;
button2.Enabled = true;
Choices sList = new Choices();
sList.Add(new string[]{"hello","test","it works","how","are","you","today"});
Grammar gr = new Grammar(new GrammarBuilder(sList));
try
{
sRecognize.RequestRecognizerUpdate();
sRecognize.LoadGrammar(gr);
sRecognize.SpeechRecognized += new EventHandler<SpeechRecognizedEventArgs>(sRecognize_SpeechRecognized);
sRecognize.SetInputToDefaultAudioDevice();
sRecognize.RecognizeAsync(RecognizeMode.Multiple);
}
catch
{
return;
}
}
void sRecognize_SpeechRecognized(object sender, SpeechRecognizedEventArgs e)
{
//if (e.Result.Confidence >= 0.3)
MessageBox.Show("speech is:" + e.Result.Text.ToString());
}
}
}
答案 0 :(得分:1)
你需要
gram.Culture = New System.Globalization.CultureInfo("en-GB")
有关详细信息,请参阅
http://www.vbforums.com/showthread.php?751297-RESOLVED-(VS2102)-Speech-Recognition-Suddenly-Stopped