Javascript make audio blob

Suppose you have base64 encoded version of audio like this

data="data:audio/ogg;base64,T2dnUwACAAAAAAAAAADSeWyXAU9nZ1MAAAAAAAAAAAAA0nl";

1.First remove the base64 headers (preamble) and decode it to pure binary form, the form it lies in as in your iPad. You can use convertDataURIToBinary an excellent snippet by borismus on github for that

var binary= convertDataURIToBinary(data);

2.Now create a Blob from the binary; specifying the type of audio it is

var blob=new Blob([binary], {type : 'audio/ogg'});

3.Now create blob url out of this Blob

var blobUrl = URL.createObjectURL(blob);

That’s all now simply replace src attribute of <source> to this blob url.In case you already have the pure decoded binary then you just do step 3

https://jsfiddle.net/sanddune/uubnnr0w/

Leave a Comment