NAudio - 如何记录说话者的初始静音

NAudio - How to record the initial silence of the speaker

我正在尝试使用 WasapiLoopbackCapture class 在 WAV 文件中录制扬声器。 我注意到,如果扬声器最初是静音的,WAV 文件会在扬声器发出第一声时开始录制,例如在录音开始后 5 或 10 秒后。

有没有办法在 WAV 文件中也记录初始静音?

这是我写的代码:

WasapiLoopbackCapture _speakerWave;
protected WaveFileWriter _speakerWriter;

_speakerWave = new WasapiLoopbackCapture();

_speakerWave.DataAvailable += (s, a) =>
{
    _speakerWriter.Write(a.Buffer, 0, a.BytesRecorded);
};

_speakerWriter = new WaveFileWriter("test.wav", _speakerWave.WaveFormat);
_speakerWave.StartRecording();

谢谢

来自NAudio WasapiLoopbackCapture documentation:

Now there is one gotcha with WasapiLoopbackCapture. If no audio is playing whatsoever, then the DataAvailable event won't fire. So if you want to record "silence", one simple trick is to simply use an NAudio playback device to play silence through that device for the duration of time you're recording. Alternatively, you could insert silence yourself when you detect gaps in the incoming audio.