'SAPI does not implement phonetic alphabet selection' exception

◇◆丶佛笑我妖孽 提交于 2019-11-30 18:15:41

问题


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


    }
}

回答1:


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



来源:https://stackoverflow.com/questions/27198683/sapi-does-not-implement-phonetic-alphabet-selection-exception

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!