“SAPI不执行拼音字母选择”例外 [英] 'SAPI does not implement phonetic alphabet selection' exception

查看:439
本文介绍了“SAPI不执行拼音字母选择”例外的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

每当我尝试在笔记本电脑中编写任何语音识别程序时,我总是得到与下面提到的相同的消息。我可以随时编译我的代码,使Windows窗体应用程序工作。但问题是,程序将没有检测到我的声音..程序不工作..



我非常确定我的代码工作正常,因为我通常从YouTube视频中的代码,如: https://www.youtube.com/watch?v=KR0-UYUGYgA 等等..
我正在为我的项目使用.NET框架4客户端配置文件。我仅引用system.speech...可能是我的问题?



调试消息我得到:

  speaker.vshost.exe信息:0:SAPI不实现拼音字母选择。 
System.Speech.dll中发生类型为System.Runtime.InteropServices.COMException的第一次机会异常
System.Speech.dll中发生类型为System.InvalidOperationException的第一次机会异常
System.Speech.dll中出现类型为System.InvalidOperationException的第一次机会异常
System.Speech.dll中发生类型为System.InvalidOperationException的第一次机会异常

我尝试的示例代码:

 使用系统; 
使用System.Collections.Generic;
使用System.ComponentModel;
使用System.Data;
使用System.Drawing;
使用System.Linq;
使用System.Text;
使用System.Windows.Forms;
使用System.Speech.Synthesis;
使用System.Speech.Recognition;
使用System.Threading;
使用System.Threading.Tasks;

命名空间扬声器
{
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;
选择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


Whenever I attempt to code any speech recognition program in my laptop,I always get the same messages as mentioned below..I can always compile my code and get the windows form application working..But the problem is, the program will not detect my voice..And the program wont work..

I am very sure my codes works fine as I usually take the codes from youtube videos like : https://www.youtube.com/watch?v=KR0-UYUGYgA and many more.. I am using .NET framework 4 client profile for my projects.. I make reference only to "system.speech"...What might be my problem ?

Debug messages that I get :

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

Sample code that I tried :

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


    }
}

解决方案

You need

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

For more details see

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

这篇关于“SAPI不执行拼音字母选择”例外的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆