【问题标题】:Difficult times with Speech Recognition Engine and checkboxes语音识别引擎和复选框的困难时期
【发布时间】:2015-02-16 11:31:28
【问题描述】:

我很难将此代码与复选框结合起来。

我希望代码在启用复选框时运行(真),并在禁用复选框时停止(假),但由于某种原因我不能,我需要一些帮助。

如果有人有解决方案或不同的建议,我将不胜感激。

代码为:private void Form1_Load(object sender, EventArgs e)

        Choices cities = new Choices(new string[] { "google" });
        Grammar gr = new Grammar(new GrammarBuilder(cities));


        SpeechRecognitionEngine recognize = new SpeechRecognitionEngine();
        SpeechSynthesizer Synth = new SpeechSynthesizer();
        recognize.SetInputToDefaultAudioDevice();
        DictationGrammar Voc = new DictationGrammar();
        recognize.LoadGrammar(Voc);
        recognize.RecognizeAsync(RecognizeMode.Multiple);
        recognize.SpeechRecognized += new EventHandler<SpeechRecognizedEventArgs>(recognize_SpeechRecognized);



    }

    **private void recognize_SpeechRecognized(object sender, SpeechRecognizedEventArgs e)**
    {
        if (e.Result.Text == "google")

            System.Diagnostics.Process.Start("http://www.google.com");
    }



        **(and possibly sth that touches the solution?)**

    private void checkBox1_CheckedChanged(object sender, EventArgs e)
    {
        if (checkBox1.Checked == true)
            recognize.RecognizeAsync(RecognizeMode.Multiple);
        else if (checkBox1.Checked == false) // turn off
            recognize.RecognizeAsyncCancel();
    }

谢谢

【问题讨论】:

    标签: c# .net speech-recognition speech-to-text


    【解决方案1】:

    我猜您希望该复选框表示语音识别当前是否处于活动状态并使用它来切换它。您的代码的问题是复选框的初始状态与您立即开始的语音识别状态不对应。

    您可以通过将复选框的初始选中状态设置为true 或删除初始块中的以下行来解决它:

    recognize.RecognizeAsync(RecognizeMode.Multiple);
    

    因为这段代码无论如何都会在复选框事件处理程序上运行。您还需要将recognize 变量的定义拉到Form1_Load 之外的类级别。

    【讨论】:

      【解决方案2】:

      您需要将checkBox1_CheckedChanged 与前端的复选框相关联(我假设为checkBox1)。 &lt;asp:CheckBox id="checkBox1" OnCheckedChanged="checkBox1_CheckedChanged" /&gt;

      【讨论】:

        【解决方案3】:

        不幸的是它没有帮助,所以我用按钮制作了这个应用程序。

        private void button1_Click(object sender, EventArgs e) { 识别.RecognizeAsync(RecognizeMode.Multiple); button1.Enabled = false; }

        感谢您的宝贵时间

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 2017-10-02
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多