I am trying to record audio into a web audio bufferNode, then stream that audio from the browser to the server. I've been trying to use socket.io-stream https://github.com/nkzawa/socket.io-stream to do this. Socket.io-stream wants me to pass it a stream object and I'm not sure how to go about creating a stream object from a bufferNode. Perhaps I am going about this all wrong but here is what I'm trying to do:
var socketStream = ss.createStream();
ss(this.socket).emit('audio', stream);
// this part is pseudocode for what i want to do
var audioStream = createStream(myBufferNode);
audioStream.pipe(socketStream);
I have also tried something like this:
var stream = ss.createStream();
ss(this.socket).emit('audio', stream);
var audioSource = this.actx.createBufferSource();
audioSource.buffer = this.recorder.buffer.bufferNode
var processor = this.actx.createScriptProcessor(2048, 1, 1);
processor.onaudioprocess = function (e) {
stream.push(e.inputBuffer.getChannelData(0));
}
// processor nodes need to be connected to a destination to work. its a bug
processor.connect(this.actx.destination);
audioSource.connect(processor);
audioSource.playbackRate.value = 1024;
audioSource.start(0);
Still nothing seems to be passing through the stream on the server. Here is my server code:
ss(socket).on('audio', function(stream, data) {
stream.pipe(process.stdout);
stream.on('data', function (chunk) {
console.log('CHUNK: ', chunk);
});
});
Any help is appreciated