0

次のコードは、ブラウザーで実行されている 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);
    });
}

ダウンロード リンクをクリックするとID3、適切なサイズの MP3 ファイルが取得されます。最初は . 私は何が欠けていますか?#TSSELavf58.29.100

4

0 に答える 0