Regarding decoding, audioContext from the window object should do the job.
var audioCtx = new (window.AudioContext || window.webkitAudioContext)();
and then
audioCtx.decodeAudioData(audioData, function(buffer) {
directly on the binary array.
Regarding communication, I'd rather use XMLHttpRequest (a low level function and old) and using the response directly.
This is a pretty good function made by MDM guys (I updated the url of the ogg file so you can test it directly) :
function getData() {
source = audioCtx.createBufferSource();
request = new XMLHttpRequest();
request.open('GET', 'https://raw.githubusercontent.com/mdn/webaudio-examples/master/decode-audio-data/viper.ogg', true);
request.responseType = 'arraybuffer';
request.onload = function() {
var audioData = request.response;
audioCtx.decodeAudioData(audioData, function(buffer) {
myBuffer = buffer;
songLength = buffer.duration;
source.buffer = myBuffer;
source.playbackRate.value = playbackControl.value;
source.connect(audioCtx.destination);
source.loop = true;
loopstartControl.setAttribute('max', Math.floor(songLength));
loopendControl.setAttribute('max', Math.floor(songLength));
},
function(e){"Error with decoding audio data" + e.error});
}
request.send();
}
the full source code is here :
https://raw.githubusercontent.com/mdn/webaudio-examples/master/decode-audio-data/index.html