如何停止循环语音识别 [英] how to stop the loop speech recognition

查看:128
本文介绍了如何停止循环语音识别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,



我的问题是,如果我说(你好那里)sSynth一直打招呼你好你好你好你好......



有人可以帮忙。





这是我的代码

hello,

my problem is that if I say (hello there) the sSynth keeps saying hello hello hello hello hello....

can someone please help.


here is my code

namespace WindowsFormsApplication2
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        SpeechSynthesizer sSynth = new SpeechSynthesizer();
        PromptBuilder pBuilder = new PromptBuilder();
        SpeechRecognitionEngine sRecognize = new SpeechRecognitionEngine();
        string name = "Microsoft Zira Desktop";
       

        private void textBox1_TextChanged(object sender, EventArgs e)
        {

        }

        private void button1_Click(object sender, EventArgs e)
        {
            
           
        }

        private void button2_Click(object sender, EventArgs e)
        {
            textBox1.Text = "on";
            Choices list = new Choices();
            list.Add(new String[] { "hello there", "good bye" });
            Grammar GR = new Grammar(new GrammarBuilder(list));
            

            try
            {
                sRecognize.UnloadAllGrammars();
                sRecognize.RecognizeAsyncCancel();
                sRecognize.RequestRecognizerUpdate();
                sRecognize.LoadGrammar(GR);
                sRecognize.SpeechRecognized += sRecognize_SpeechRecognized;
                sRecognize.SetInputToDefaultAudioDevice();
                sRecognize.RecognizeAsync(RecognizeMode.Multiple);
            }

            catch
            {
                textBox1.Text = "Error";
            }
        }

        private void sRecognize_SpeechRecognized(object sender, SpeechRecognizedEventArgs e)
        {
            switch (e.Result.Text)
                {
                    case "hello there":
                        speakText("hello");
                        break;

                    case "good bye":
                        speakText("bye");
                        break;

                }

          
            }

        public void speakText(string textSpeak)
        {
            sRecognize.RecognizeAsyncCancel();
            sRecognize.RecognizeAsyncStop();
            pBuilder.ClearContent();
            pBuilder.AppendText(textSpeak.ToString());
            sSynth.SelectVoice(name);
            sSynth.SpeakAsync(pBuilder);
            sRecognize.RecognizeAsyncCancel();
            sRecognize.RecognizeAsyncStop();
            sRecognize.RecognizeAsync(RecognizeMode.Multiple); 
        }

    }
}

>





谢谢。

>


thanks.

推荐答案

哈!您只需要在声学上隔离合成和识别。或者及时隔离它们,禁用识别直到说出的语音结束。例如,尝试在耳机中做同样的事情。



惊讶?问题实际上非常简单:您的合成文本由麦克风拾取并识别。然后你的代码再次生成。



-SA
Ha! You just need to isolate synthesis and recognition acoustically. Or isolate them in time, disable recognition until the speech spoken is ended.For example, try to do the same in headphones.

Surprised? The problem is actually very simple: your synthesized text is picked up by the microphone and recognized. Then your code generated is again.

—SA


这篇关于如何停止循环语音识别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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