audio语音流播放
<div>
<h2>语音流播放</h2>
<audio id="voice" controls>
<source src="" >
</audio>
</div>
<script>
var url = "xxx";
var xhr = new XMLHttpRequest();
xhr.open("POST", url, true);
xhr.setRequestHeader("Content-type", "application/json");
xhr.send(params);
xhr.responseType = "arraybuffer";
xhr.onreadystatechange = function () {
if (xhr.readyState == 4 && xhr.status == 200) {
var url = new Blob([xhr.response], {
type: "audio/mpeg"});
let voice = document.getElementById("voice")
voice.src = url;
voice.load();
voice.play();
}
}
</script>