Unauthorized Text to Speech Watson IBM

Asked

Viewed 82 times

0

I have a problem trying to make a request through the text-to-Speech api, when trying to make the request it gives the following error:

{
    "code": 401,
    "error": "Unauthorized"
}

My JS code

$(function () {

    $("#btnPOst").click(function () {

        var username= "XXXX-XXXX-XXXX";  
        var password = "XXXX-XXXX-XXXX";
        var request = $("#text-to-speech input[name=speech-text]").val();

        var url = "https://stream.watsonplatform.net/text-to-speech/api/v1/synthesize?voice=en-US_MichaelVoice&accept=audio/wav&text=" + request;


    $.ajax({
        type: "POST",
        url: url,
        dataType: "application/json; charset=utf-8",
        headers: {
            'Content-Type': 'application/json',
            'Accept': 'audio/wav',
            'Authorization': ("Basic " + btoa(username + ":" + password))
        },

        success: function (content) {
            alert('ok');
        },

    });

    $("#speech").attr("src", url)[0].play();

    });
});

My HTML code

<input type="text" name="speech-text" TextMode="MultiLine" />
<input type="button" id="btnPOst" value="Play" />
<audio id="speech" autoplay preload="auto" autobuffer controls class="audio"></audio>
  • The HTTP Status Code 401 - Unauthorized means exactly what it looks like, unauthorized. Probably the API needs some token or password that you are not past or are passing incorrectly.

  • @fernandosavio then saw in the documentation and found this command in Curl: curl -X GET -u "apikey:{apikey}" --output hello_world.wav "https://stream.watsonplatform.net/text-to-speech/api/v1/synthesize?accept=audio%2Fwav&amp;text=Hello%20world&amp;voice=en-US_AllisonVoice", what would be this -u in the requisition?

  • Take a look at that link. This site is good to explain commands.

  • Error Remains Same Unauthorized

  • Docs. In the documentation you need to use an Apikey, have you generated and are using it? No and per user/password. And I advise you to use the method encodeURIComponent in the requestbefore playing on the string.

  • @fernandosavio use Apikey in Authorization itself? I mean it would look like this: 'Authorization':'MINHA API KEY'?

Show 1 more comment
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.