我正在遵循此documentation,以使用Text To Speech REST API将文本转换为语音。
我可以使用Postman
成功获得有效回复,并且可以用PostMan
支付音频。但是我无法使用JavaScript
播放音频。以下是我的Javascript
代码。我不确定如何处理response
。
function bingSpeech(message) {
var authToken = "TokenToCommunicateWithRestAPI";
var http = new XMLHttpRequest();
var params = `<speak version='1.0' xml:lang='en-US'><voice xml:lang='en-US' xml:gender='Female' name='Microsoft Server Speech Text to Speech Voice (en-US, JessaRUS)'>${message}</voice></speak>`;
http.open('POST', 'https://speech.platform.bing.com/synthesize', true);
//Send the proper header information along with the request
http.setRequestHeader("Content-Type", "application/ssml+xml");
http.setRequestHeader("Authorization", "bearer " + authToken);
http.setRequestHeader("X-Microsoft-OutputFormat", "audio-16khz-32kbitrate-mono-mp3");
http.onreadystatechange = function () {
if (http.readyState == 4 && http.status == 200) {
// I am getting the respone, but I'm not sure how to play the audio file. Need help here
}
}
http.send(params);
}
谢谢。
答案 0 :(得分:0)
我使用Java代码引用了以下存储库。它在IDE中播放音频,并将音频文件保存到系统中。