/// <summary> /// 开始录音 /// </summary> /// <param name="freq">录音采样率,默认48000</param> /// <param name="chans">声道数[1-6],默认1</param> /// <param name="period">录音数据输出间隔,单位/毫秒,默认100.最小值5ms,the maximum the maximum is half the BASS_CONFIG_REC_BUFFER setting. /// If the period specified is outside this range, it is automatically capped. The default is 100ms</param> /// <param name="sampleType">采样类型,建议默认值16位</param> public void Start(int freq = 48000, int chans = 1, int period = 100, SampleType sampleType = SampleType.Sample16Bit) { BASSFlag flags = this.SampleTypeToBASSFlag(sampleType); this._recordFlag = true; this._handle = RecordHelper.RecordStart(freq, chans, flags, period, this._recordPro, IntPtr.Zero); WavHelper.ChannelPlay(this._handle, false); }
/// <summary> /// 构造函数 /// </summary> /// <param name="dataOutput">录音数据输出委托[第一个参数:设备索引;第二个参数:数据;第三个参数:数据长度]</param> /// <param name="device">录音设备索引,-1 = default device, 0 = first. BASS_RecordGetDeviceInfo can be used to enumerate the available devices</param> public SoundRecorder(Action <int, byte[], int> dataOutput, int device = 0) { if (dataOutput == null) { throw new ArgumentNullException(nameof(dataOutput)); } RecordHelper.RecordInit(device); this._device = device; this._dataOutput = dataOutput; this._recordPro = new RECORDPROC(RecordProCallback); }
/// <summary> /// Frees all resources used by the recording device. /// </summary> public static void Free() { RecordHelper.RecordFree(); }
/// <summary> /// 获取当前使用的录音设备的信息 /// </summary> /// <returns>当前使用的录音设备的信息</returns> public BASS_DEVICEINFO GetDeviceInfo() { return(RecordHelper.RecordGetDeviceInfo(this._device)); }