Monday, 13 March 2017

write to a wav file while streaming node js

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

Basically, I am using socket io stream, from a browser I am sending a buffer with audio 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 I have is that the file demo.wav will be only wrote when I finish the stream, so when I stop the microphone. But I would like it to write always, as I will be doing speech recognition using google, any ideas? If I call the speech recognition from google using pipe, the chuncks are too small and google is not able to recognize it.



via peterpeterson

No comments:

Post a Comment