How to get pronunciation (phonetics) of text (not speech, only text)?

Viewed 6787

I wanna get pronunciation of short messages using python. For example, message 'text' should be transformed to 'tekst' and message 'привет' (russian) should be transformed to 'privet'.

I have tried to use googletrans for it but there is no pronunciation in fact (pronunciation is None, my issue).

Does anybody know some package for this task? I have googled for it but there are no results. I've found over 5 packages for convert text-to-speech or text-translate-to-speech but I don't need an audio file, I need only text of pronunciation. The phonemizer is very good solution but I cannot run it's backends on windows.

Maybe does somebody know how to take some 'API' of this, this or this or this?

4 Answers

Well there is a module named pronouncing in python which includes function to get pronunciations of words such as:

>>> import pronouncing
>>> pronouncing.phones_for_word("permit")
[u'P ER0 M IH1 T', u'P ER1 M IH2 T']
  1. The pronouncing.phones_for_word() function returns a list of all pronunciations for the given word found in the CMU pronouncing dictionary.
  2. Pronunciations are given using a special phonetic alphabet known as ARPAbet.
  3. Here’s a list of ARPAbet symbols and what English sounds they stand for. Each token in a pronunciation string is called a “phone.”
  4. The numbers after the vowels indicate the vowel’s stress. The number 1 indicates primary stress; 2 indicates secondary stress; and 0 indicates unstressed.

I got this from tutorial and cookbook page of pronouncing

There is another module named pysle which can help you

You can use selenium to get the texts from macmillandictionary.com. With selenium you can navigate in the page, click, enter texts, etc. So your job will be hit the word in the search bar and get the result using selenium. You may use oxfordlearnersdictionaries.com too.

from googletrans import Translator
translator = Translator()
k = translator.translate("who are you", dest='hindi')
print(k)
print(k.text)
p = translator.translate(k.text,dest='hindi')#convert same language to same to get
                                             #pronunciation
print(p)
print(p.pronunciation)

please try this for pronunciation

Output:

Translated(src=en, dest=hi, text=तुम कौन हो, pronunciation=None, extra_data="{'translat...")
तुम कौन हो
Translated(src=hi, dest=hi, text=तुम कौन हो, pronunciation=tum kaun ho, extra_data="{'translat...")
tum kaun ho

requirement to install googletrans

Related