I'm using python on the IBM Bluemix platform. How can I do a call to the text-to-speech Watson service? I have the string inside my python code and I need to pass this text to be read.
Asked
Active
Viewed 1,102 times
4
-
2See https://github.com/watson-developer-cloud/text-to-speech-python for starter sample application – Alex da Silva Mar 05 '16 at 23:06
2 Answers
3
Assuming that you already have a Bluemix account and added text to speech Watson API to your Bluemix workspace, you have the credentials to access the API (restful).
If you were requesting using the CURL linux app, it would be something like this
curl -u "xxxxx729-b03f-4403-8adf-c5418ee4ea05":"xxxxxiWtmVoG" "https://stream.watsonplatform.net/text-to-speech/api/v1/synthesize?text=Hello+World" -H "accept: audio/flac" > sound.flac
Using Python, it can be
import requests
headers = {'accept': 'audio/flac'}
r = requests.get('https://stream.watsonplatform.net/text-to-speech/api/v1/synthesize?text=Hello+World', auth=('xxxxx729-b03f-4403-8adf-c5418ee4ea05', 'xxxxxiWtmVoG'), headers=headers)
with open('/home/leo/sound.flac', 'wb') as fd:
for chunk in r.iter_content(1024):
fd.write(chunk)
See http://docs.python-requests.org/en/master/user/quickstart/ for details on the requests package.
See https://www.ibm.com/smarterplanet/us/en/ibmwatson/developercloud/text-to-speech/api/v1/ for text2Speech documentation.

Leo
- 751
- 4
- 29
-
2Thank you so much @Leo... everything you explained here was very useful... it was what I needed to start... – Vitor Hugo Mar 06 '16 at 15:22
-
1Then how about upvoting the answer or tagging it as the correct answer? Just a thought. ;-) – Tom Pohl Feb 10 '17 at 17:58