Friday, 21 April 2017

Send blob to nodejs server and save as mp3 file

I am currently sending a blob made from recorded input to a nodejs server like so:

...
mediaRecorder.onstop = function(e) {
  var blob = new Blob(this.chunks, { 'type' : 'audio/mpeg'});
  socket.emit('radio', blob);
};
...

And retrieving it on my nodejs server like so:

...
socket.on('radio', function(blob) {
  let arraybuffer = Uint8Array.from(blob).buffer;
  fs.writeFileSync('test.mp3', arraybuffer);
}
...

The file is created, but there's no audio and time. Part of my struggle is that I don't full understand the relationship between a Blob and how to properly convert it to the rite format to save properly as an mp3, or if this can even be done.

I'd be willing to use a different format, as long as I can save the audio file. Also further documentation on Blob would be appreciated as I continue to research and understand all this myself.



via zillaofthegods

No comments:

Post a Comment