I am trying to use IBM watson api for text to speech service. The service works if I use curl command but when I try to use the srrvice using Python SDK, It throws me below error.
Traceback (most recent call last): File "/anaconda3/lib/python3.6/site-packages/ibm_cloud_sdk_core/base_service.py", line 234, in send response.status_code, error_message, http_response=response) ibm_cloud_sdk_core.api_exception.ApiException: Error: Forbidden, Code: 403 Method failed with status code 403: Forbidden
Below is the curl command
curl -X GET -u "apikey:myapiKey" --output hello_world.wav "https://api.eu-de.text-to-speech.watson.cloud.ibm.com/text-to-speech/api/v1/synthesize?accept=audio/wav&text=Hallo%20Welt&voice=de-DE_DieterVoice"
Below is the python code
from ibm_watson import TextToSpeechV1
from ibm_cloud_sdk_core.authenticators import IAMAuthenticator
from ibm_watson import ApiException
import json
IBM_API_ENDPOINT = "https://api.eu-de.text-to-speech.watson.cloud.ibm.com/text-to-speech/api/v1/synthesize"
IBM_TTS_API_KEY = "myAPIKey"
authenticator = IAMAuthenticator(IBM_TTS_API_KEY)
text_to_speech = TextToSpeechV1(authenticator=authenticator)
text_to_speech.set_service_url(IBM_API_ENDPOINT)
try:
with open('IBM.wav', 'wb') as audio_file:
audio_file.write(text_to_speech.synthesize("Hallo world", voice='de-DE_DieterVoice', accept='audio/wav').get_result().content)
except ApiException as ex:
print("Method failed with status code " + str(ex.code) + ": " + ex.message)