Skip to content

Instantly share code, notes, and snippets.

@somerongit
Created August 8, 2022 10:11
Show Gist options
  • Save somerongit/f75e151d08f7b8a4a6511495b7deb3de to your computer and use it in GitHub Desktop.
Save somerongit/f75e151d08f7b8a4a6511495b7deb3de to your computer and use it in GitHub Desktop.
# Signup into ibm cloud and get your free api keys
# pip install ibm_watson
apikey = 'YOUR WATSON API KEY HERE'
url = 'YOUR WATSON URL HERE'
input_text ='Wir sinken.'
# Authenticate
authenticator = IAMAuthenticator(apikey)
tts = TextToSpeechV1(authenticator=authenticator)
tts.set_service_url(url)
# Indentify Language
language = lt.identify(input_text).get_result()
lang=language[0].language
# Translating
translation = lt.translate(text='We are sinking! Please send help!', model_id='en-'+lang).get_result()
text = translation['translations'][0]['translation']
# Save as media file
with open('./translation.mp3', 'wb') as audio_file:
res = tts.synthesize(text, accept='audio/mp3', voice='zh-CN_LiNaVoice').get_result()
audio_file.write(res.content)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment