Skip to content
Advertisement

Speech Recognition(IBM) username and password

I hope to use IBM speech recognition service without - curl or ibm_watson module.
And my attempt is below:

import speech_recognition as sr
r = sr.Recognizer()
text = r.recognize_ibm(audio,username='',password='')

Even though, I have ‘Service credentials’ for IBM cloud – speech to text, I cannot find correct form for the function.
In the documents of recognize_ibm(), it is said that I need to enter the link_1 to find my username in XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX format.
But the link_1 is broken. Where can I find the username and password?

I also tried text = r.recognize_ibm(audio,username='apikey',password=api_key) as the previous answers link_2.

Actually I realized the module was not working.

Advertisement

Answer

Here are the official API docs for Speech to Text: https://cloud.ibm.com/apidocs/speech-to-text

It includes various samples and further links. You can use the IAMAuthenticator to turn an API key into an authentication token and to handle refresh tokens. If you don’t want to make use of the SDK you have to deal with the IBM Cloud IAM Identity Service API on your own. The API has functions to obtain authentication / access tokens.

I often use a function like this to turn an API key into an access token:

def getAuthTokens(api_key):
    url     = "https://iam.cloud.ibm.com/identity/token"
    headers = { "Content-Type" : "application/x-www-form-urlencoded" }
    data    = "apikey=" + api_key + "&grant_type=urn:ibm:params:oauth:grant-type:apikey"
    response  = requests.post( url, headers=headers, data=data )
    return response.json()

You could

User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement