Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/290.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/20.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# 听写语法与习惯语法_C#_.net_Visual Studio 2010_Text To Speech_Voice Recognition - Fatal编程技术网

C# 听写语法与习惯语法

C# 听写语法与习惯语法,c#,.net,visual-studio-2010,text-to-speech,voice-recognition,C#,.net,Visual Studio 2010,Text To Speech,Voice Recognition,我正在编写以下代码 using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Speech.Recognition; using System.Speech.Synthesis; using System.Windows.Forms; using System.IO; namespace US_Speech_Recognizer { public

我正在编写以下代码

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Speech.Recognition;
using System.Speech.Synthesis;
using System.Windows.Forms;
using System.IO;

namespace US_Speech_Recognizer
{
    public class RecognizeSpeech
    {
        private SpeechRecognitionEngine sEngine; //Speech recognition engine
        private SpeechSynthesizer sSpeak; //Speech synthesizer
        string text3 = "";

        public RecognizeSpeech()
        {
            //Make the recognizer ready
            sEngine = new SpeechRecognitionEngine(new System.Globalization.CultureInfo("en-US"));


            //Load grammar
            Choices sentences = new Choices();
            sentences.Add(new string[] { "I am hungry" });

            GrammarBuilder gBuilder = new GrammarBuilder(sentences);

            Grammar g = new Grammar(gBuilder);

            sEngine.LoadGrammar(g);

            //Add a handler
            sEngine.SpeechRecognized +=new EventHandler<SpeechRecognizedEventArgs>(sEngine_SpeechRecognized);


            sSpeak = new SpeechSynthesizer();
            sSpeak.Rate = -2;



            //Computer speaks the words to get the phones
            Stream stream = new MemoryStream();
            sSpeak.SetOutputToWaveStream(stream);


            sSpeak.Speak("I was hungry");
            stream.Position = 0;
            sSpeak.SetOutputToNull();


            //Configure the recognizer to stream
            sEngine.SetInputToWaveStream(stream);

            sEngine.RecognizeAsync(RecognizeMode.Single);


        }


        //Start the speech recognition task
        private void sEngine_SpeechRecognized(object sender, SpeechRecognizedEventArgs e)
        {
            string text = "";

            if (e.Result.Text == "I am hungry")
            {
                foreach (RecognizedWordUnit wordUnit in e.Result.Words)
                {
                    text = text + wordUnit.Pronunciation + "\n";
                }

                MessageBox.Show(e.Result.Text + "\n" + text);
            }


        }
    }
}
使用系统;
使用System.Collections.Generic;
使用System.Linq;
使用系统文本;
使用系统语音识别;
使用系统、语音、合成;
使用System.Windows.Forms;
使用System.IO;
名称空间US_语音识别器
{
公共类识别语音
{
私有语音识别引擎sEngine;//语音识别引擎
专用语音合成器sSpeak;//语音合成器
字符串text3=“”;
公众认可的言论
{
//准备好识别器
sEngine=new SpeechRecognitionEngine(新系统、全球化、文化信息(“en-US”);
//加载语法
选择句子=新的选择();
添加(新字符串[]{“我饿了”});
GrammarBuilder gBuilder=新的GrammarBuilder(句子);
语法g=新语法(gBuilder);
加载语法(g);
//添加一个处理程序
sEngine.speechrecogned+=新事件处理程序(sEngine\u speechrecogned);
sSpeak=新的语音合成器();
sSpeak.Rate=-2;
//电脑说话是为了得到手机
Stream=新的MemoryStream();
sSpeak.SetOutputToWaveStream(流);
说话(“我饿了”);
流位置=0;
sSpeak.setoutputtonll();
//将识别器配置为流
sEngine.SetInputToWaveStream(流);
sEngine.RecognizeAsync(RecognizeMode.Single);
}
//启动语音识别任务
私有void sEngine_SpeechRecognized(对象发送方,SpeechRecognizedEventArgs e)
{
字符串文本=”;
如果(e.Result.Text==“我饿了”)
{
foreach(在e.Result.Words中识别出WordOrdUnit wordUnit)
{
text=text+wordUnit.发音+“\n”;
}
MessageBox.Show(e.Result.Text+“\n”+文本);
}
}
}
}
在这里,语法是
我饿了
,但是计算机被要求说
我饿了
。但情况是,识别事件被触发,并表示文本完全等于
我饿了
。在输出框中,您还可以检查音素

避免这种情况的唯一方法是加载
DictationGrammar

我认为提供自定义语法是限制应用程序侦听所有不需要的内容的最佳方法,但似乎自定义语法失败了


我的问题是,有没有办法避免这种情况?为什么会这样

我找到了答案<代码>自定义语法
将通过给引擎很大的压力来过滤用户的发音,以使用提供的有限语法识别用户的语音

听写语法
不是这样的,它只是试图匹配计算机理解的内容,而不是用户确切说的内容

这可以通过训练语音引擎来最小化