Exemple #1
0
        public RecordingFrm(string sampleRate, string sampleBits)
        {
            InitializeComponent();
            cleanUp();
            RecordFlagModel = new AudioRecording.RecordFlagModel();
            waveInSource    = new WaveIn();
            int rate = 8000;
            int bits = 8;

            try
            {
                rate = int.Parse(sampleRate);
                bits = int.Parse(sampleBits);
            }
            catch (Exception)
            {
                rate = 8000;
                bits = 8;
            }
            waveInSource.WaveFormat = new WaveFormat(rate, bits, 1);
            //waveInSource.WaveFormat = new WaveFormat(8000, 1);
            waveInSource.BufferMilliseconds = 1000;

            waveInSource.DataAvailable    += waveInSource_DataAvailable;
            waveInSource.RecordingStopped += waveInSource_RecordingStopped;
            string path = Application.StartupPath + "\\record";

            if (!Directory.Exists(path))
            {
                Directory.CreateDirectory(path);
            }
            //string fileName = Utils.random_str(20)+"-"+DateTime.Now.ToString("yyyy-MM-dd-HH-mm-ss") + ".wav";
            string fileName = DateTime.Now.ToString("yyyy-MM-dd-HH-mm-ss") + ".wav";

            path += "\\" + fileName;
            RecordFlagModel.Flag               = false;
            RecordFlagModel.RecprdFileName     = fileName;
            RecordFlagModel.RecordFileFullPath = path;
            waveFileWriter = new WaveFileWriter(path, waveInSource.WaveFormat);
            try
            {
                waveInSource.StartRecording();
            }
            catch (Exception)
            {
                waveFileWriter.Dispose();
                waveFileWriter = null;
                waveInSource.Dispose();
                waveInSource = null;
                MessageBox.Show("录音出错,请检查麦克风或话筒等输入设备!");
                this.Dispose();
                this.Close();
            }

            startTime = DateTime.Now;
            recordingTimer.Enabled = true;
            recordingTimer.Start();
        }
Exemple #2
0
        void recordingFrm_FormClosing(object sender, FormClosingEventArgs e)
        {
            //throw new NotImplementedException();
            RecordFlagModel model = (sender as RecordingFrm).RecordFlagModel;

            if (model.Flag == true)
            {
                pList.Add(model.RecprdFileName, model.RecordFileFullPath);
                this.recordListBox.Items.Add(model.RecprdFileName);
            }
        }