如何在没有MIC的情况下录制静音

时间:2018-10-08 07:55:28

标签: c# audio-recording naudio

我有一个C#桌面应用程序,它使用NAudio库记录来自MIC的音频。如果MIC连接到系统,则应用程序将从默认输入设备开始记录。输出波形文件被保存。 如果未连接MIC,我想将静音录制到输出文件中。如果没有连接真实的麦克风,如何馈送虚拟MIC或虚拟MIC以开始录制。

谢谢 这是代码:

class AudioRecorder
    {
        private WaveIn waveIn = null;
        private WaveFileWriter waveWriter = null;
        public AudioRecorder()
        {
            if (WaveIn.DeviceCount > 0) //Means there is a mic
            {
                waveIn = new WaveIn();
                waveIn.DeviceNumber = 0; //default device
                waveIn.DataAvailable += WaveIn_DataAvailable;
            }
            else
            {
                //I want to add the virtual mic that will send only silent signal
            }
        }
        public void Start()
        {
            waveIn.StartRecording();
        }
        public void Stop()
        {
            waveIn.StopRecording();
        }
        private void WaveIn_DataAvailable(object sender, WaveInEventArgs e)
        {
            if (waveWriter == null)
                waveWriter = new WaveFileWriter("output.wav", new WaveFormat(44100, 2));
            waveWriter.Write(e.Buffer, 0, e.BytesRecorded);
        }
    }

0 个答案:

没有答案