gpt4 book ai didi

c# - 'SAPI 没有实现拼音选择' 异常

转载 作者:行者123 更新时间:2023-11-30 17:45:39 27 4
gpt4 key购买 nike

每当我尝试在我的笔记本电脑上编写任何语音识别程序时,我总是会收到如下所述的相同消息。我总是可以编译我的代码并让 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());
}


}
}

最佳答案

你需要

 gram.Culture = New System.Globalization.CultureInfo("en-GB")

详情请见

http://www.vbforums.com/showthread.php?751297-RESOLVED-(VS2102)-Speech-Recognition-Suddenly-Stopped

关于c# - 'SAPI 没有实现拼音选择' 异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27198683/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com