This question is a followup to a previous question, that was resolved thanks to @thejh.
I'm trying to convert text to audio and serve the data to the client as 'chunked' data. So far my headers look like so:
res.writeHead(200, {
'Content-Type': 'audio/wav',
// I tried 'audio/x-wav' as well
'Transfer-Encoding': 'chunked'
});
And then I'm converting snippets of text to audio in a queue (which I get back as base64 encoded data), and serving them like so:
var src = Base64Audio.replace("data:audio/x-wav;base64,","");
var binAudio = new Buffer( src, 'base64');
res.write(binAudio);
All the information is being transferred and sent to the client, but for some reason the browser (I'm testing it in Firefox 7.0.1) is playing it and stopping after the first chunk. Here's the result/demo showing the premature end of the audio, and this is the code being run on github.
Why is this? Is this because the x-wav data has meta data like an End or specified length in is header/meta-data? If so what is this meta data and is there some way of editing it so that the browser successfully concatenates the received chunks?
I'm aware of the Header 'Content-Length': Buffer.length
but in this instance I don't know how long the entire stream is going to be.
Can anyone offer suggestions. Is it possible to Edit the buffers before they're sent such that the browser concatenates them properly?