· 4 years ago · Aug 12, 2021, 12:02 PM
1from ibm_watson import TextToSpeechV1
2from ibm_cloud_sdk_core.authenticators import IAMAuthenticator
3
4# enter your API KEY
5APIkey = 'mykey'
6TTSurl = 'myserver'
7
8inputTXT = "TEXT GOES IN HERE"
9
10authenticator = IAMAuthenticator(APIkey)
11text_to_speech = TextToSpeechV1(
12 authenticator=authenticator
13)
14
15text_to_speech.set_service_url(TTSurl)
16
17with open('hello_world.wav', 'wb') as audio_file:
18 audio_file.write(
19 text_to_speech.synthesize(
20 'Hello world',
21 voice='en-US_AllisonV3Voice',
22 accept='audio/wav'
23 ).get_result().content)