I'm using Node.JS BinaryServer and WAV.js to stream audio from the client to the node server.
Problem is - it's too slow.
On an average internet connection, a 10 minutes recording has a delay of 3 minutes to upload. Meaning, after the stream.end
event was fired, the client still sends more data to the node server. It's a huge overhead.
As you can see in the Node.js code below, I'm using a BinaryServer
with an HttpsServer
, since I have no chiose (WebRTC is only allowed in HTTPS).
I read on several places that writing binary data to node.js can be speeded up by adding the highWaterMark
to fs.createWriteStream
, as suggested here, but I'm not using this class, I'm using the wav.FileWriter
class.
Node.js server code:
var binaryServer = require('binaryjs').BinaryServer;
var wav = require('wav');
var https = require('https');
var httpsserver = https.createServer(options).listen(9002);
var server = binaryServer({ server: httpsserver });
server.on('connection', function(client) {
client.on('stream', function (stream, meta) {
var fileWriter = new wav.FileWriter('/foo.wav', {
channels: 1,
sampleRate: meta.SampleRate,
bitDepth: 16,
highWaterMark: Math.pow(2, 16) // this seems useless
});
stream.pipe(fileWriter);
});
});
Javascript client code:
// This streams the sound to the node server:
var sound = convertFloat32ToInt16(e.inputBuffer.getChannelData(0));
window.Stream.write(sound );
function convertFloat32ToInt16(buffer) {
l = buffer.length;
buf = new Int16Array(l);
while (l--) {
buf[l] = Math.min(1, buffer[l])*0x7FFF;
}
return buf.buffer;
}
Does anyone have an idea how to speed things up ?
Is there a way to implement highWaterMark
in wav.FileWriter
?
via Koby Douek
No comments:
Post a Comment