'How to capture 16 kHz sample rate from NAudio
Is it possible to capture 16000 kHz sample rate rather than 48000 kHz? Currently the code below captures 48000 kHz sample rate.
var outputFolder = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "NAudio");
Directory.CreateDirectory(outputFolder);
var outputFilePath = Path.Combine(outputFolder, "recorded.wav");
var capture = new WasapiLoopbackCapture();
var writer = new WaveFileWriter(outputFilePath, capture.WaveFormat);
var sampleRate = capture.WaveFormat.SampleRate; <--- this returns 48000, but I need 16000
capture.DataAvailable += (s, a) =>
{
writer.Write(a.Buffer, 0, a.BytesRecorded);
if (writer.Position > capture.WaveFormat.AverageBytesPerSecond * 20)
{
capture.StopRecording();
}
};
Solution 1:[1]
WASAPI will not let you pick 16kHz. You can use WaveInEvent, but you wont be able to do loopback capture. Your only real option with WASAPI is to resample the audio to 16kHz after capturing
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Mark Heath |