Embeddable AI

  • 1.  audio/mp3 produced by Watson text-to-speech is not playing

    Posted Wed July 21, 2021 07:57 AM
    The following code authenticates with the text-to-speech service from a react.js project running in the browser using a bearer token:

        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);
            });
        }​


    After clicking the download link, I get an MP3 file of reasonable size having `ID3`, `#TSSE` and `Lavf58.29.100` at the beginning, but it does not play in any of the players I tried. What am I missing?

    ------------------------------
    Meir Goldenberg
    ------------------------------

    #EmbeddableAI
    #WatsonAPIs


  • 2.  RE: audio/mp3 produced by Watson text-to-speech is not playing

    Posted Wed July 21, 2021 10:33 PM
    Can you try work it out through recordrtc package?
    https://www.npmjs.com/package/recordrtc 


    ------------------------------
    David Tin
    ------------------------------



  • 3.  RE: audio/mp3 produced by Watson text-to-speech is not playing

    Posted Thu July 22, 2021 04:44 AM
    Hi David,
    I am not sure I am getting your idea. In RecordRTC, one gets the ready for download blob from the recorder. So, what part of RecordRTC can I use for my purposes?
    Thank you!
    Meir

    ------------------------------
    Meir Goldenberg
    ------------------------------