我正在进行休息通话,这会给我wav
内容类型的audio/mpeg
回复,类似
ID3.O��^H��B��F�����^H��B��F���
我想在我的客户端播放此音频。所以我想为此创建一个blob URL。
$.ajax({
url: 'texttospeechnew2?text='+text+'&voice=en-US_AllisonVoice&download=true&accept=audio%2Fmp3',
type: 'GET',
//data: params,
success: function(data) {
responsefile = data;
var byteArray = new Uint8Array(responsefile);
var blob = new Blob(byteArray, { type: "audio/mpeg3" });
const url = window.URL.createObjectURL(blob);
console.log(url);
},
error: function(data, err) {
console.log("err");
}
});
它给了我blob网址,但没有正确的格式无法播放。有人帮忙。 感谢
答案 0 :(得分:0)
您必须使用XMLHttpRequest
xhr = new XMLHttpRequest();
xhr.open('GET', 'texttospeechnew2?text='+text+'&voice=en-US_AllisonVoice&download=true&accept=audio%2Fmp3', true);
xhr.responseType = 'blob';
xhr.onload = function(e) {
if (this.status == 200) {
const url = window.URL.createObjectURL(this.response);
console.log(url);
}
};
xhr.send();