0
votes

I am trying to use the IBM Watson speech to text API/service in the following Python program.

import json
import os
import sys
from watson_developer_cloud import SpeechToTextV1

def transcribe_audio(audio_file_name) :
    IBM_USERNAME = "yourusername"  

    IBM_PASSWORD = "yourpassword"
    #what changes should be made here instead of username and password

    stt = SpeechToTextV1(username=IBM_USERNAME, password=IBM_PASSWORD)
    audio_file = open(audio_file_name, "rb")        
    json_file = os.path.abspath("america")+".json"; 
    with open(json_file, 'w') as fp:
        result = stt.recognize(audio_file,timestamps=True,content_type='audio/wav', inactivity_timeout =-1,word_confidence = True)
        result.get_result()
        json.dump(result, fp, indent=2)
    script = "Script is : "
    for rows in result['results']:
        script += rows['alternatives'][0]['transcript']
    print(script)
transcribe_audio("america.wav")

This code gave me an authentication error as mentioned in the title because IBM changed the authorization method from username + password to apikey very recently.

Could anybody tell me what changes should be made in this? And also how to generate the apikey on IBM Watson speech to text with username and password?

I am new to speech recognition, please let me know. Thanks in advance.

1
how to generate the api key on ibm watson speech to text with username and password? You automatically get spikey . Check your IBM Cloud console and click on your service. But This apikey is not used for authentication for streaming audio.RC0993
Kindly go through this documentation. Directly jumping over SDKs is probably not a good idea.RC0993
@RC0993 Thank you so much. I kinda figured out getting the api keys shortly after posting.envi z
@RC0993 But the documentation link you mentioned was pretty useful and saved a lot of time.envi z
Are you able to resolve the issue, if yes can you post the answer here, it would be of great help as i am facing the same issue.Harshit Yadav

1 Answers

0
votes

All the information you want is in the API documentation, including how to obtain the API Key - https://cloud.ibm.com/apidocs/speech-to-text?code=python