I'm learning to use the Watson Speech JS SDK. In particular I like Transcribe from Microphone, with Alternatives. I'm generating my token with a Firebase Cloud Function. I'm using AngularJS, not JQuery. The first problem I'm running into is
var stream = WatsonSpeech.SpeechToText.recognizeMicrophone(Object.assign(token, {
objectMode: true,
format: false,
wordConfidence: true
}));
I got this error message:
WatsonSpeechToText: missing required parameter: opts.token
(Using $scope.token
or token
makes no difference.)
Looking up this error in the documentation:
module.exports = function recognizeMicrophone(options) {
if (!options || !options.token) {
throw new Error('WatsonSpeechToText: missing required parameter: opts.token');
}
OK, it's looking for an options
object. I fixed the error with this code:
const options = {
token: $scope.token,
objectMode: true,
format: false,
wordConfidence: true
};
console.log(options);
var stream = WatsonSpeech.SpeechToText.recognizeMicrophone(options);
Now I get this error:
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
The options
object logs this:
token:
access_token: "eyJraWQiOiIyMDIwMDIyNTE4MjgiLCJhbGciOiJSUzI1NiJ9.eyJpYW1faWQiOiJp0tU2..."
expiration: 1585332575
expires_in: 3600
refresh_token: "OKC8z8ebLMzZcrAt6YgInnJJn0UIx1P3NTeDvdEC3kJqIQ7Yn9J9iu6-DF..."
scope: "ibm openid"
token_type: "Bearer"
objectMode: true
format: false
wordConfidence: true
smart_formatting: false
The token is a JSON object, which includes the access_token
. Is this what the SDK wants? The RecognizeStream documentation doesn't say whether it wants the JSON token or just the naked access_token
.
Adding 000
to the expiration
field shows that I have 53 minutes left on this token.
I'm using the API key that's specific to my Speech-to-Text service.
Any other suggestions?