[英]How to convert .wav response in to blob url so that I can play as audio in client side using javascript
I'm doing a rest call which would give me as wav
response of audio/mpeg
content type, Something like 我正在打个电话,这会给我audio/mpeg
内容类型的wav
响应,类似
ID3.O��^H��B��F�����^H��B��F���
I want to play this audio on my client side. 我想在客户端播放此音频。 So I want to create a blob URL for this. 所以我想为此创建一个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");
}
});
It is giving me blob url but not proper format unable to play that.can someone help. 它给了我Blob网址,但格式不正确,无法播放。有人可以帮忙。 Thanks 谢谢
You have to use XMLHttpRequest
您必须使用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();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.