Write to wav file when streaming node js

Is there a way to force .pipe in a stream to write to a file every specific time / size?

Basically, I use the io socket stream, from the browser I send a buffer with sound, and I send with emit:

Browser

        c.onaudioprocess = function(o) 
        {
        var input = o.inputBuffer.getChannelData(0);

            stream1.write( new ss.Buffer( convertFloat32ToInt16( input ) ));

        }

Server (nodejs)

var fileWriter = new wav.FileWriter('/tmp/demo.wav', {
    channels: 1,
    sampleRate: 44100,
    bitDepth: 16
});

ss(socket).on('client-stream-request', function(stream)
{
    stream.pipe(fileWriter);
}

The problem is that the demo.wav file will only be recorded after the stream finishes, so when I stop the microphone. But I would like him to write always, since I will do speech recognition using Google, any ideas? If I call speech recognition from Google using a channel, the chunks are too small and Google cannot recognize it.

+4
source share
1 answer

stream API, , pipe.

stream.pipe(fileWriter, { end: false });
0

Source: https://habr.com/ru/post/1672185/


All Articles