Smalltalkman
Smalltalkman

Reputation: 33

Watson speech to text authentication

I am trying to get Transcribe from Microphone working on my server as a starting point.

The code is straightforward but I am having trouble with the token.

on IBMcloud I created a IAM-Service id with Access Policies
Viewer, Reader 14 Speech to Text service in all resource groups

created an apikey from that

created the token file

    curl -k -X POST  --output token \
  --header "Content-Type: application/x-www-form-urlencoded" \
  --header "Accept: application/json" \
  --data-urlencode "grant_type=urn:ibm:params:oauth:grant-type:apikey" \
  --data-urlencode "apikey={apikey}" \
  "https://iam.cloud.ibm.com/identity/token"

the response has 'access_token' but the javascript SDK 0.38.1 looks for 'accessToken'

when I start microphone I get a socket error 'wss://stream.watsonplatform.net/speech-to-text/api/v1/recognize"

I checked token expiration.

I confirmed it is an auth problem:

 curl -X GET "https://stream.watsonplatform.net/speech-to-text/api/v1/models?access_token="{accessToken}"

responds "unauthorized"

I have researched and am unsure what to do next. My best guess is I am generating the token improperly.

Upvotes: 0

Views: 143

Answers (1)

data_henrik
data_henrik

Reputation: 17186

I would leave the token generation to the code. All the SDKs have an IAMAuthenticator component. The full documentation for Node.js is here. It has a very simple example where you pass in the API key:

import { IamAuthenticator } from 'ibm-cloud-sdk-core';

const authenticator = new IamAuthenticator({
  apikey: '{apikey}',
});

Thereafter, you instantiate the service, e.g., STT.

Upvotes: 1

Related Questions