Reputation: 13
I'm trying to record the speaker in a WAV file using the WasapiLoopbackCapture class. I notice that if the speaker is initially silent, the WAV file starts recording when the first sound is emitted from the speaker, for example after 5 or 10 seconds from the beginning of the recording.
Is there a way to record also the initial silence in the WAV file?
Here is the code I wrote:
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();
Thanks
Upvotes: 1
Views: 579
Reputation: 26936
From the 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.
Upvotes: 1