1
votes

I'm trying to use IBM Watson Speech to Text and am having trouble with the cURL structure given the documentation seems to show username:password as authentication but this is nowhere to be found.

I came across this question which has a similar issue How to get username & password for Watson Text to Speech Service?

When I include the api-key instead of the username:password I'm asked to enter my password. Is this still the right cURL request or has it moved elsewhere?

curl -X POST -u <api-key> \
--header "Content-Type: audio/flac" \
--data-binary @audio-file.flac \
"https://stream.watsonplatform.net/speech-to-text/api/v1/recognize"

Thanks :)

1

1 Answers

1
votes

If you want to stick to the Basic Authentication scheme you can use the actual api key as the password with apikey as the username:

curl https://stream.watsonplatform.net/speech-to-text/api/v1/models -u "apikey:<apikey>"

That said, for security reasons it is recommended that production applications do not use the api key directly, but a token:

You can get a token using the api key, it will be valid for one hour:

curl -X POST https://iam.ng.bluemix.net:443/oidc/token -H 'cache-control: no-cache' -H 'content-type: application/x-www-form-urlencoded' -H 'grant_type: urn:ibm:params:oauth:grant-type:apikey' -d 'grant_type=urn%3Aibm%3Aparams%3Aoauth%3Agrant-type%3Aapikey&apikey=<apikey>'

then you can pass that token in the calls to the service like this:

curl https://stream.watsonplatform.net/speech-to-text/api/v1/models -header "Authorization: Bearer <token_here>"