Simple WORKING example of IBM Watson Text to Speech service in Python

from ibm_watson import TextToSpeechV1
from ibm_cloud_sdk_core.authenticators import IAMAuthenticator
import os

def speak(theText):
         # put the API Key in your account here
         authenticator = IAMAuthenticator('xxxxxxYOUR API KEYxxxxxx')
         text_to_speech = TextToSpeechV1(authenticator=authenticator)

         # put the service URL listed in your account here
         text_to_speech.set_service_url('https://api.us-south.text-to-speech.watson.cloud.ibm.com/instances/YOURINSTANCEID')

         with open('speech.mp3', 'wb') as audio_file:
             audio_file.write(
                 text_to_speech.synthesize(text=theText, voice='en-US_MichaelV3Voice', accept='audio/mp3').get_result().content)
         os.system("mpg321 -q speech.mp3")
		 
speak("This is what's up")

the examples on the Watson site are WRONG. In the Synthesize routine, you have to put ‘text=thenthetext’ instead of ‘thenthetext’

This exmample uses mpg321 Linux program to playback the output. you can install this with:

sudo apt-get update
sudo apt-get install mpg321