【发布时间】:2018-08-09 07:54:50
【问题描述】:
我正在关注此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);
}
谢谢。
【问题讨论】:
-
你有没有想过这个问题?尝试使用 Azure TTS 服务解决此问题
-
嗨@ElleryFamilia,不。如果您找到了解决方案,请告诉我。谢谢
标签: text-to-speech microsoft-cognitive azure-cognitive-services bing-speech