public void Start() { if (_isRecord) { return; } Stop(); try { FileInfo file = new FileInfo(tmpName); if (file.Exists) { file.Delete(); } fs_tmp = new FileStream(tmpName, System.IO.FileMode.Create); bw_tmp = new BinaryWriter(fs_tmp); dt_Start = DateTime.Now; _isRecord = true; //m_Format = new WaveFormat(6400, 8, 1); m_Format = new WaveFormat(16000, 16, 1); //if (RecordQuality == Quality.low) m_Format = new WaveFormat(32000, 8, 2); //else if (RecordQuality == Quality.Normal) m_Format = new WaveFormat(44100, 8, 2); //else m_Format = new WaveFormat(44100, 16, 2); m_Recorder = new WaveInRecorder(-1, m_Format, 16384, 3, new BufferDoneEventHandler(DataArrived)); } catch (Exception ex) { LogManage.WriteLog(this.GetType(), ex); OnError(ex, "启动录音失败!"); Stop(); } }
public void Stop() { if (m_Recorder != null) { try { bw_tmp.Close(); m_Recorder.Dispose(); WriteToFile(); _recordSize = 0; _isRecord = false; } catch (Exception ex) { LogManage.WriteLog(this.GetType(), ex); } finally { m_Recorder = null; } } }
/// <summary> /// 开始录音 /// </summary> /// <param name="callBack"></param> public void Start(Action <bool> callBack) { if (this.IsRecord) { return; } this.Stop(); try { FileInfo file = new FileInfo(this.tmpName); if (file.Exists) { file.Delete(); } this.fs_tmp = new FileStream(this.tmpName, System.IO.FileMode.Create); this.bw_tmp = new BinaryWriter(this.fs_tmp); this.dt_Start = DateTime.Now; this._isRecord = true; //m_Format = new WaveFormat(6400, 8, 1); this.m_Format = new WaveFormat(16000, 16, 1); //if (RecordQuality == Quality.low) m_Format = new WaveFormat(32000, 8, 2); //else if (RecordQuality == Quality.Normal) m_Format = new WaveFormat(44100, 8, 2); //else m_Format = new WaveFormat(44100, 16, 2); m_Recorder = new WaveInRecorder(-1, m_Format, 16384, 3, new BufferDoneEventHandler(DataArrived), new Action <bool>((isSuccessed) => { if (callBack != null) { callBack(isSuccessed); } })); } catch (Exception ex) { LogManage.WriteLog(this.GetType(), ex); OnError(ex, "启动录音失败!"); Stop(); } }