Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jayshields/21434f808a95d1c597be7ea110bdf3cc to your computer and use it in GitHub Desktop.
Save jayshields/21434f808a95d1c597be7ea110bdf3cc to your computer and use it in GitHub Desktop.
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