34
loading...
This website collects cookies to deliver better user experience
pip install ibm_watson
!pip install ibm_watson
from ibm_watson import TextToSpeechV1
from ibm_cloud_sdk_core.authenticators import IAMAuthenticator
url = '<your-api-url>'
apiKey = '<your-api-key>'
authenticator = IAMAuthenticator(apiKey)
tts = TextToSpeechV1(authenticator=authenticator)
tts.set_service_url(url)
with open('./speech.mp3', 'wb') as audio_file:
res = tts.synthesize('Hello World! I\'m Thirasha', accept='audio/mp3', voice='en-US_AllisonV3Voice').get_result()
audio_file.write(res.content)
speech.mp3
at the root directory.with open('SpeechText.txt', 'r') as f:
text = f.readlines()
text = [line.replace('\n', '') for line in text]
text = ''.join(str(line) for line in text)
with open('./speech.mp3', 'wb') as audio_file:
res = tts.synthesize(text, accept='audio/mp3', voice='en-US_AllisonV3Voice').get_result()
audio_file.write(res.content)
de-DE_BirgitV3Voice
, that code should be change like this.with open('./germanspeech.mp3', 'wb') as audio_file:
res = tts.synthesize('Hallo Welt! Ich bin Thirasha', accept='audio/mp3', voice='de-DE_BirgitV3Voice').get_result()
audio_file.write(res.content)