コード例 #1
0
        private void Btn_Down(object sender, MouseEventArgs e)
        {
            button1.Text      = "录音中...";
            button1.BackColor = Color.FromArgb(255, 120, 255);
            textBox1.Visible  = false;
            recorder          = new SoundRecord();
            try
            {
                recorder.InitCaptureDevice();
            }catch (NullReferenceException) { }
            try
            {
                recorder.mWavFormat = recorder.CreateWaveFormat();
            }
            catch (NullReferenceException) { }


            //
            // 录音设置
            //
            string wavfile;

            wavfile = "test.wav";
            //if (recorder == null)
            //{
            //    recorder = new SoundRecord();
            //}

            recorder.SetFileName(wavfile);
            recorder.RecStart();
        }
コード例 #2
0
        private void Btn_Up(object sender, MouseEventArgs e)
        {
            try
            {
                recorder.RecStop();
            }catch (NullReferenceException)
            {}

            recorder = null;
            //Boolean flag=false;
            string voiceStr = Post(Application.StartupPath + "\\test.wav");

            if (!voiceStr.Contains("3301"))
            {
                if (voiceStr.Contains("关闭"))
                {
                    Play("欢迎下次使用!");

                    //主程停止1秒
                    Thread.Sleep(1500);
                    //该方法会强制进程关闭,并给操作系统一个退出代码。
                    Environment.Exit(0);
                    //调用 Application.Exit() 并不一定能让程序立即退出,程序会等待所有的前台线程终止后才能真正退出。
                    //Application.Exit();
                }
                string flag = ToolClass.openBrowser(voiceStr);
                if (flag == "")
                {
                    textBox1.Visible = true;
                    //textBox1.Text = voiceStr + ":未包含定义的字符!";
                    textBox1.Text = "指令未包含定义的字符!";
                }
                else
                {
                    textBox1.Text = "已打开" + flag;
                }
            }
            else
            {
                textBox1.Visible = true;
                textBox1.Text    = voiceStr;
            }


            button1.Text      = "按住说话";
            button1.BackColor = Color.FromArgb(255, 255, 255);
            string text = textBox1.Text;

            Play(text);
        }