方法“”没有重载,接受0个参数

时间:2018-12-06 08:26:52

标签: c# visual-studio-2010

我对rec.Speechreconized += rec_Speachrecognized中的代码有疑问。

我一直在互联网上寻找答案,但是那根本行不通。我希望有人能帮助我。

namespace ai
{
    public partial class Form1 : Form
    {
        SpeechSynthesizer s = new SpeechSynthesizer();
        Choices list = new Choice {};

        public Form1()
        {
            SpeechRecognitionEngine rec = new SpeechRecognitionEngine();
            list.Add(new String[] {"Hello", "how are you"});

            Grammar gr = new Grammar(new GrammarBuilder(list));

            try
            {
                rec.RequestRecognizerUpdate();
                rec.LoadGrammar(gr);
                rec.SpeechRecognized += rec_Speachrecognized();
                rec.SetInputToDefaultAudioDevice();
                rec.RecognizeAsync(RecognizeMode.Multiple);

            }
            catch{return;}
            s.Speak("Hi, I am Ms M, what can i help you?");

            InitializeComponent();
        }

        public void Say(String h)
        {
            s.Speak(h);
        }

        private EventHandler<SpeechRecognizedEventArgs> rec_Speachrecognized(object sender, SpeechRecognizedEventArgs e)
        {
            string r = e.Result.Text;


            if(r == "hello")
            {
                Say("hi");
            }
            throw new NotImplementedException();
        }

        private void Form1_Load(object sender, EventArgs e)
        {

        }
    }
}

1 个答案:

答案 0 :(得分:1)

您需要更改此行

rec.SpeechRecognized += rec_Speachrecognized();

rec.SpeechRecognized += rec_Speachrecognized;

基本上会在结尾处删除(),因为该事件将传递参数,但是通过这种方式,您将调用不带参数的方法