NAudio: WaveFormat cannot be set for WASAPI Loopback Capture
I am trying to record from speaker (loopback recording) in sample rate-8000 and channel-1, problem is code is recording in sample rate-44100 and channel-2, format…
Stream stream = new System.IO.MemoryStream();
waveIn = new WasapiLoopbackCapture();
waveIn.DataAvailable += new EventHandler<NAudio.Wave.WaveInEventArgs>(sourceStream_DataRecord);
waveWriter = new NAudio.Wave.WaveFileWriter(stream, waveIn.WaveFormat);
waveIn.StartRecording();
when i add
waveIn.WaveFormat = new NAudio.Wave.WaveFormat(16000, 1);
it thrown exception
WaveFormat cannot be set for WASAPI Loopback Capture
there is any way to record it in 16000,1 format… actually i dont want it change after complete recording… i want it at start time… please help me on this
About this issue
- Original URL
- State: closed
- Created 7 years ago
- Comments: 20 (8 by maintainers)
you are confusing the length of buffers in bytes with the number of samples. In WaveInEventArgs you should use bytes recorded. Divide it by 4 to get number of samples, and then by 2 (assuming stereo) to get number of sample frames.
take a look at my article on input driven resampling, for one way to do this.