示例#1
0
        private void tmr_listen_Tick(object sender, EventArgs e)
        {
            double inputValue;
            double level = Mci.GetLevel(10, out inputValue, 1);

            txt_VoiceLevel.Text = "Sample strength = " + ((int)level).ToString();
            prb_volume.Value    = Convert.ToInt32(level);


            //计算安静的时间
            if (inputValue <= 5)
            {
                silencetime++;
            }
            else
            {
                silencetime = 0;
            }
            if ((b_Read == true) && (inputValue <= 10))
            {
                lab_status.Text = "正在聆听";
                Log("正在聆听");
                lab_status.Refresh();
                rtb_output.Refresh();
                btn_Report_Click(sender, e);
                panel_sample.BackColor = Color.DarkGreen;
                panel_sample.Refresh();
            }

            //判断是否正式录音
            if (inputValue > 5)
            {
                if (recorderA.b_Recording == true)
                {
                    tmr_recorder.Enabled = false;
                    lab_status.Text      = "信道1正在拾取";
                    Log("信道1正在拾取");
                    lab_status.Refresh();
                    rtb_output.Refresh();
                    btn_Report_Click(sender, e);
                    b_Read = false;
                    panel_sample.BackColor = Color.Gold;
                    panel_sample.Refresh();
                }
                if (recorderB.b_Recording == true)
                {
                    tmr_recorder.Enabled = false;
                    lab_status.Text      = "信道2正在拾取";
                    Log("信道2正在拾取");
                    lab_status.Refresh();
                    rtb_output.Refresh();
                    btn_Report_Click(sender, e);
                    b_Read = false;
                    panel_sample.BackColor = Color.Gold;
                    panel_sample.Refresh();
                }
            }

            //判断是否记录 静默1s开始存储
            if ((silencetime > 10) && (b_Read == false))
            {
                if (recorderA.b_Recording == true)
                {
                    Random a    = new Random();
                    string aa   = "AA" + a.Next();
                    string path = Application.StartupPath + "\\wav\\" + aa + "r1.wav";
                    recorderA.SaveToFile(path);
                    System.Threading.Thread.Sleep(100);
                    int i_sleeptime = (int)(SndPlayer.GetWavFileTime(path) * 1000);
                    txt_AudioFile.Text = path;
                    lab_status.Text    = "信道1正在识别";
                    Log("信道1正在识别");
                    lab_status.Refresh();
                    rtb_output.Refresh();
                    btn_Report_Click(sender, e);
                    panel_sample.BackColor = Color.Blue;
                    panel_sample.Refresh();
                }
                if (recorderB.b_Recording == true)
                {
                    Random a    = new Random();
                    string aa   = "AA" + a.Next();
                    string path = Application.StartupPath + "\\wav\\" + aa + "r2.wav";
                    recorderB.SaveToFile(path);
                    System.Threading.Thread.Sleep(100);
                    int i_sleeptime = (int)(SndPlayer.GetWavFileTime(path) * 1000);
                    txt_AudioFile.Text = path;
                    lab_status.Text    = "信道2正在识别";
                    Log("信道2正在识别");
                    lab_status.Refresh();
                    rtb_output.Refresh();
                    btn_Report_Click(sender, e);
                    panel_sample.BackColor = Color.Blue;
                    panel_sample.Refresh();
                }
                b_Read = true;


                tmr_listen.Enabled = false;

                btn_Recognize_Click(sender, e);
                rtb_SendMsg.Refresh();
                if (message_bar.Text == "识别成功")
                {
                    Log("识别成功");
                    lab_status.Text = "语音识别完成";
                    Log("语音识别完成");
                }
                System.Threading.Thread.Sleep(1000);
                tmr_recorder.Enabled = true;
                tmr_listen.Enabled   = true;
            }
        }
示例#2
0
 private void VoiceRecorder_Load(object sender, EventArgs e)
 {
     Mci.StartLevelMeter();
     lab_status.Text = "无声";
 }