Speech to text using IBM and python

Viewed 87

I am trying to make work a simple transcription with IBM Watson using python:

import json
from os.path import join, dirname
from ibm_watson import SpeechToTextV1
from ibm_watson.websocket import RecognizeCallback, AudioSource
import threading
from ibm_cloud_sdk_core.authenticators import IAMAuthenticator

authenticator = IAMAuthenticator('myAPIKey')

service = SpeechToTextV1(authenticator=authenticator)
service.set_service_url('myURLendPoint')

#service.set_disable_ssl_verification(True)



with open('C:\\path\\myaudio.flac',
          'rb') as audio_file:
    speech_recognition_results = service.recognize(
        audio=audio_file,
        content_type='audio/flac',
).get_result()
    
print(json.dumps(speech_recognition_results, indent=2))

but it does not work. I got this error:

ApiException: Error: <HTML><HEAD>
<TITLE>Internal Server Error</TITLE>
</HEAD><BODY>
<H1>Internal Server Error - Write</H1>
The server encountered an internal error or misconfiguration and was unable to
complete your request.<P>
Reference&#32;&#35;4&#46;e0a33617&#46;1636132745&#46;598fc
</BODY></HTML>
, Code: 503

Any idea on what I am doing wrong..? I am following IBM docs..

1 Answers

A 503 indicates a service unavailable error, so either the service was down, or the endpoint you are using is incorrect. You don't provide it in your code

service.set_service_url('myURLendPoint')

so its difficult to tell, but it should look something like:

service.set_service_url('https://api.us-east.speech-to-text.watson.cloud.ibm.com')

see the API documentation - https://cloud.ibm.com/apidocs/speech-to-text?code=python#service-endpoint

Related