IBM Watson Speech-to-Text speech-javascript-sdk "HTTP Authentication failed; no valid credentials available"

184 views Asked by At

I'm trying to set up IBM Watson Speech-to-Text to run in my Angular frontend. I'm using German Attanasio's speech-javascript-sdk library. I want the transcript text to go to the console so I'm using the microphone-streaming-object-to-console.html example. Here's my code:

const options = {
      token: $scope.token,
      model: 'en-US_BroadbandModel',
      word_confidence: true,
      object_mode: true
};

var stream = WatsonSpeech.SpeechToText.recognizeMicrophone(options);

The error I'm getting is

watson-speech.js:10482 WebSocket connection to 'wss://stream.watsonplatform.net/speech-to-text/api/v1/recognize?model=en-US_BroadbandModel&watson-token=[object%20Object]' failed: HTTP Authentication failed; no valid credentials available

My guess is that my token isn't in the right format. The IAM bearer token is provided as a JSON object:

{
   access_token: "eyJraWQiOiIyMDIwMDIyNTE4MjgiLCJhbGciOiJSUzI1NiJ9.e…", 
   expiration: 1585264266, 
   expires_in: 3600, 
   refresh_token: "OKA5toCaoVmYsPbwpjARE1971xspAe7Xg5nOm9pRrLKjKgaubr…", 
   scope: "ibm openid",
}

I tried providing the bare naked access_token, and I tried providing the JSON object. Both resulted in the same error message. Which format is correct?

Did I set up the options object correctly? Is it object_mode orobjectMode?

I don't understand what Object.assign(token, means in the example code.

1

There are 1 answers

0
Javier Landa-Torres On

I had the same problem and I found the solution working perfectly:

In 'options' constant you need to change the field 'token' by 'accessToken' and It should be works.

NOTE:

The field 'model' in 'options' has a default value, but if you want to change it you have to set value to 'model' and 'laguage',

const params = {
        accessToken: 'token'
        format: true,           
        extractResults: true,
        objectMode: true,
        model:'es-MX_BroadbandModel',
        laguage: 'es-MX'
      };