Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/rust/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# ';SAPI不实现语音字母选择';例外_C#_.net_Dll_Speech Recognition_Text To Speech - Fatal编程技术网

C# ';SAPI不实现语音字母选择';例外

C# ';SAPI不实现语音字母选择';例外,c#,.net,dll,speech-recognition,text-to-speech,C#,.net,Dll,Speech Recognition,Text To Speech,每当我试图在我的笔记本电脑上编写任何语音识别程序时,我总是会收到如下所述的信息。我总是可以编译代码并让windows窗体应用程序工作。但问题是,该程序不会检测到我的语音。而且该程序也不会工作 我非常确定我的代码运行良好,因为我通常从youtube视频中获取代码,如:和更多。。 我正在为我的项目使用.NET framework 4客户端配置文件。。我只提到“系统语音”…我可能有什么问题 我收到的调试消息: speaker.vshost.exe Information: 0 : SAPI does

每当我试图在我的笔记本电脑上编写任何语音识别程序时,我总是会收到如下所述的信息。我总是可以编译代码并让windows窗体应用程序工作。但问题是,该程序不会检测到我的语音。而且该程序也不会工作

我非常确定我的代码运行良好,因为我通常从youtube视频中获取代码,如:和更多。。 我正在为我的项目使用.NET framework 4客户端配置文件。。我只提到“系统语音”…我可能有什么问题

我收到的调试消息:

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());
        }


    }
}
使用系统;
使用System.Collections.Generic;
使用系统组件模型;
使用系统数据;
使用系统图;
使用System.Linq;
使用系统文本;
使用System.Windows.Forms;
使用系统、语音、合成;
使用系统语音识别;
使用系统线程;
使用System.Threading.Tasks;
名称空间说话人
{
公共部分类Form1:Form
{
公共表格1()
{
初始化组件();
}
SpeechSynthesizer sSynth=新的SpeechSynthesizer();
PromptBuilder pBuilder=新PromptBuilder();
SpeechRecognitionEngine sRecognize=新建SpeechRecognitionEngine();
私有void Form1\u加载(对象发送方、事件参数e)
{
}
私有无效按钮1\u单击(对象发送者,事件参数e)
{
pBuilder.ClearContent();
pBuilder.AppendText(textBox1.Text);
sSynth.Speak(pBuilder);
}
私有无效按钮2\u单击(对象发送者,事件参数e)
{
按钮2.Enabled=false;
按钮2.Enabled=true;
选项列表=新选项();
添加(新字符串[]{“hello”、“test”、“it works”、“how”、“are”、“you”、“today”});
语法gr=新语法(新语法生成器(sList));
尝试
{
sRecognize.RequestRecognizerUpdate();
认知负荷语法(gr);
sRecognize.SpeechRecognized+=新事件处理程序(sRecognize_SpeechRecognized);
sRecognize.setInputOdeFaultAudioDevice();
sRecognize.RecognizeAsync(RecognizeMode.Multiple);
}
抓住
{
返回;
}
}
void sRecognize_SpeechRecognized(对象发送方,SpeechRecognizedEventArgs e)
{
//如果(如结果置信度>=0.3)
Show(“speech is:+e.Result.Text.ToString());
}
}
}
您需要

 gram.Culture = New System.Globalization.CultureInfo("en-GB")
有关更多详细信息,请参阅


您正在使用try/catch em all语句在代码中隐藏bug。正在进行语音识别时,调用SetInputOdeFaultAudioDevice()无效。多次订阅SpeechReceigned事件也是一个严重的错误。您还有更多的工作要做,永远不要隐藏不方便的真相。@HansPassant..好的..与其调用setInputOdeFaultAudioDevice(),我应该在代码中做什么?我想使用笔记本电脑中的内置麦克风作为输入设备…..在代码中添加gr.Culture=New System.Globalization.CultureInfo(“en GB”)会出现以下错误:“System.Globalization.CultureInfo”是一个“类型”,这在给定的上下文中无效。我如何解决这个问题?在C#中是
grammarBuilder.Culture=new System.Globalization.CultureInfo(“en GB”);gr=新语法(grammarBuilder)静止hv错误..对于第一行,非静态字段、方法或属性'System.Speech.Recognition.GrammarBuilder.get'…需要对象引用,对于第二行,“System.Speech.Recognition.GrammarBuilder”是一个“类型”,但它像一个“变量”一样使用。如果你把你的答案与我的示例代码联系起来,这对我来说将是很有价值的,因为我是C#&Speech Recognition的新手。谢谢