Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Download Audio from AJAX and Play as Blob
var a = fetch("http://path/to/audio.wav")
.then(res => {
var reader = res.body.getReader();
return reader.read().then(result => {
return result;
});
})
.then(data => {
console.log(data);
var blob = new Blob([data.value], { type: "audio/wav" });
var blobUrl = URL.createObjectURL(blob);
window.audio = new Audio();
window.audio.src = blobUrl;
window.audio.controls = true;
document.body.appendChild(window.audio);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.