private void button1_Click(object sender, EventArgs e) { mciSendString("set wave bitpersample 8", "", 0, 0); mciSendString("set wave samplespersec 20000", "", 0, 0); mciSendString("set wave channels 2", "", 0, 0); mciSendString("set wave format tag pcm", "", 0, 0); mciSendString("open new type WAVEAudio alias movie", "", 0, 0); mciSendString("record movie", "", 0, 0); System.Threading.Thread.Sleep(1000); mciSendString("stop movie", "", 0, 0); mciSendString("save movie 1.wav", "", 0, 0); mciSendString("close movie", "", 0, 0); SndPlayer.GetWavFileTime("1.wav"); }
private void btn_play_Click(object sender, EventArgs e) { string fileName = "ffmpeg.exe"; Process p = new Process(); p.StartInfo.UseShellExecute = false; p.StartInfo.RedirectStandardOutput = true; p.StartInfo.FileName = fileName; p.StartInfo.CreateNoWindow = true; p.StartInfo.Arguments = "-i " + txt_VoicePath.Text + " -y -ar 11025 -ac 1 -acodec pcm_u8 output.wav";//参数以空格分隔,如果某个参数为空,可以传入”” p.Start(); p.WaitForExit(); int i_sleeptime = (int)(SndPlayer.GetAudioTime(txt_VoicePath.Text) * 1000); bs.SetFilePath(txt_VoicePath.Text); bs.Play(); //SndPlayer.Play(txt_VoicePath.Text); System.Threading.Thread.Sleep(i_sleeptime + 200); }
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; } }