【问题标题】:Microsoft Azure Cognitive Services - Bing Text to Speech API - Play audio using javascriptMicrosoft Azure 认知服务 - 必应文本到语音 API - 使用 javascript 播放音频
【发布时间】: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


【解决方案1】:

我为我的 Java 代码参考了以下存储库。它在 IDE 中播放音频并将音频文件保存到您的系统中。

https://github.com/Azure-Samples/Cognitive-Speech-TTS/tree/master/Samples-Http/Java/TTSSample/src/com/microsoft/cognitiveservices/ttssample

【讨论】:

  • 请在您的实际答案中包含解决方案,否则一旦链接资源不可用,它就会变得无用。
猜你喜欢
  • 1970-01-01
  • 2021-04-21
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-05-18
  • 1970-01-01
  • 2019-01-07
相关资源
最近更新 更多