I was using the Google Cloud Speech to recognize streaming audios (from microphone) on the node server. At the same time I would like to store the streamed audio into a file. Since the streaming recognition is operated on chunks of buffers, how could I combine all the buffers and store it as a single audio file?
The actual code I was using is adapted from this library, where the audio encoding on the server side is defined as
const encoding = 'LINEAR16';
const sampleRateHertz = 16000;
And each time there's a audio stream it will be sent via the cloud api:
client.on('binaryData', function (data) {
if (recognizeStream !== null) {
recognizeStream.write(data);
}
});
On the client side, the buffer was preprocessed in this file (downsampled into a Int16Array).
So can I just concatenate each buffer and save to a pcm file on the server side, when the streaming finishes? Or do I need to merge the buffers in a complex way (such as using audiobuffer-to-wav?