I'm working off the fantastic sample here.
In essence, I am capturing audio from the mic using getUserMedia and then downsampling each frame to an Int16Array of 16000 samples per second.
On the server side, I am able to receive the audio and using the wav package, I am able to save WAV files as well.
The problem is when I don't want to downsample (yes, I know the bandwidth implication but that's my requirement).
I'm able to stream raw audio (in Float32Array) and able to save it as a WAV. However, there's a lot of white noise added in.
When I downsample on the server side, the WAV package is unable to handle it because it is no longer a viable WAV frame.
I tried to wrap the mic samples using
var samples = new Float32Array(e.inputBuffer.getChannelData(0))
socket.emit('binaryData',samples.buffer);
and received it on the server side with
socket.on('binaryData',function (data){
var recovered = new Float32Array(data);
wavFileWriter.write(recovered.buffer);
});
But that doesn't work either.
I'm now wondering if Socket.io does something to the data that trips the downsample function.
Or am I missing something obvious here?
Edit 1: in my quest to rule out Socket.io issues, I created the server with these settings without any improvement:
{
perMessageDeflate: false,
httpCompression: false,
maxHttpBufferSize:1e8
}
Solved it with:
const f32 = new Float32Array(data.buffer, 0, data.byteLength / Float32Array.BYTES_PER_ELEMENT);