Reputation: 18376
In google translate website, if we translate it shows translation and also pronounce of the word.
But when I use the Google translate rest API, it only return the translation, I need pronounce of the word same as website.
My Rest API
I may miss something, is any extra parameters there to retrieve these extra information?
Upvotes: 2
Views: 1448
Reputation: 392
gitHub Source for given gTTS module:
1. Install Required Libraries
pip install gTTS
2. Code Example:
from gtts import gTTS
import os
# Text to translate and generate sound for
text_to_translate = "Hello, how are you?"
# Specify the language
language = 'en' # English
# Create a gTTS object
tts = gTTS(text=text_to_translate, lang=language, slow=False)
# Save the sound file
tts.save("pronunciation.mp3")
# Play the sound
os.system("pronunciation.mp3") # This is for Windows, for other systems, use appropriate commands
This way you can store text to audio and then use 'os' module to play the given audio file.
Upvotes: 0
Reputation: 33
I was also looking for the same answer. I haven't found a way to get Pronuntiation with the Google Translate API yet. However, I found a way to get it through the Python library. You can use the Python googletrans library. The code is as follows.
You must use googletrans library 3.1.0a0 to avoid errors.
# pip install googletrans==3.1.0a0
from googletrans import Translator
translator = Translator()
SENTENSE = "안녕하세요. 반갑습니다."
LANGUAGE_CODE = translator.detect(SENTENSE).lang
k = translator.translate(SENTENSE, dest=LANGUAGE_CODE)
print(k)
print(k.text)
print(k.pronunciation)
Output:
Translated(src=ko, dest=ko, text=안녕하세요. 반갑습니다., pronunciation=annyeonghaseyo. bangabseubnida., extra_data="{'translat...")
안녕하세요. 반갑습니다.
annyeonghaseyo. bangabseubnida.
Upvotes: 0
Reputation: 2116
Translating a word from the alphabet of one language to another(get the pronuntiation), is named transliteration and it is not supported by Cloud Translate API yet.
However, there is a feature request filed for the same. You can vote for this feature by clicking "+1" and "STAR" mark to recieve updates on it.
Upvotes: 1