Optimus Prime
Optimus Prime

Reputation: 11

Simple Python code for Text-to-Speech using IBM Watson

I have been searching for code that could help me in text to speech using ibm watson in pycharm. Please help me at an earliest

Upvotes: 1

Views: 3516

Answers (1)

CarlosSR
CarlosSR

Reputation: 1195

You can find most of this code in IBM Watson Documentation

First you need ibmwatson package installed, then you need to authenticate yourself vía API Key and url. Only after you have established your connection, you can call the synthesize function.

pip install --upgrade "ibm-watson>=4.4.0"

from ibm_watson import TextToSpeechV1
from ibm_cloud_sdk_core.authenticators import IAMAuthenticator

authenticator = IAMAuthenticator('{apikey}')
text_to_speech = TextToSpeechV1(
    authenticator=authenticator
)

text_to_speech.set_service_url('{url}')

with open('filename.wav','wb') as audio_file:
    audio_file.write(text_to_speech.synthesize('hello world',voice='en-US_Henry3Voice',accept='audio/mp3').get_result().content)

Upvotes: 4

Related Questions