IBM-Watson Text to Speech throws "403:Forbidden" Error
manojmsrit opened this issue · 4 comments
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)
Hi @manojmsrit, Thanks for opening the issue, can you replace IBM_API_ENDPOINT = "https://api.eu-de.text-to-speech.watson.cloud.ibm.com/text-to-speech/api/v1/synthesize"
with IBM_API_ENDPOINT = "https://api.eu-de.text-to-speech.watson.cloud.ibm.com/text-to-speech/api"
and see if it works?
Hello @mamoonraja I tried your suggestion. Still, I face the issue even after the changes. Please suggest me.
Note : Curl command works fine.
Hi, I was able to run the example using IBM_API_ENDPOINT = "https://api.eu-de.text-to-speech.watson.cloud.ibm.com/text-to-speech/api"
. Looks like your endpoint is not getting set properly, can you share what version of SDK
you are using?
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.