Calling a service from python on bluemix

I am using python on the IBM Bluemix platform. How can I call Watson with text to speech? I have a line inside my Python code and I need to pass this text for reading.

+4
source share
2 answers

Assuming you already have a Bluemix account and have added text in the Watson API to the Bluemix workspace, you have credentials to access the API (sedative).

If you requested to use the CURL linux application, 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 could 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)

. http://docs.python-requests.org/en/master/user/quickstart/.

. https://www.ibm.com/smarterplanet/us/en/ibmwatson/developercloud/text-to-speech/api/v1/ text2Speech.

+3

All Articles