I am using NAudio to capture data from the audio device, I need to convert the data to OGG Opus format. I am using OpusDotNet nuget package https://github.com/mrphil2105/OpusDotNet
Below is the code for getting audio data from NAudio
OpusEncoder opusEncoder = new OpusEncoder(Application.Audio, 16000, 1);
WaveInEvent waveInStream = new WaveInEvent();
waveInStream.DeviceNumber = 0;
waveInStream.WaveFormat = new WaveFormat(16000, 16, 1);
waveInStream.DataAvailable += new EventHandler<WaveInEventArgs>(OnDataAvailable);
waveInStream.StartRecording();
private void OnDataAvailable(object sender, WaveInEventArgs e)
{
int encodedLength;
byte[] encodedData = opusEncoder.Encode(e.Buffer,e.Buffer.Length,out encodedLength);
}
I am getting error saying invalid framesize. I looked into Converting WAV Stream to Opus using NAudio and Sending NAudio / Opus-encoded audio from device as RTP, but could not figure out the solution.