IBM Watson text-to-speech 生成的音频/mp3 未播放

问题描述

以下代码使用来自浏览器中运行的 react.js 项目的 IBM Watson 文本到语音服务进行身份验证:

import TextToSpeechV1 from 'ibm-watson/text-to-speech/v1';
import {BearerTokenAuthenticator} from 'ibm-cloud-sdk-core'


submit = () => {
    const token = '<the bearer token>'
    const url = '<the service url>'
    const textToSpeech = new TextToSpeechV1({
        authenticator: new BearerTokenAuthenticator({bearerToken: token}),serviceUrl: url,});
    
    const params = {
        text: 'This is my text.',voice: 'en-US_MichaelV3Voice',accept: 'audio/mp3'
    };
    
    textToSpeech
    .synthesize(params)
    .then(response => {
        console.log(response.result.length);
        
        // make a download link
        const myURL = window.URL || window.webkitURL
        var binaryData = [];
        binaryData.push(response.result);
        const url = myURL.createObjectURL(new Blob(binaryData,{type: "audio/mp3"}))
        document.querySelector("a").href = url;
    })
    .catch(err => {
        console.log(err);
    });
}

点击下载链接后,我得到一个大小合理的 MP3 文件,以 ID3#TSSELavf58.29.100 开头,但在我的任何播放器中都无法播放试过了。我错过了什么?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)