5

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?

Demetry Pascal
  • 383
  • 4
  • 15

4 Answers4

2

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.

  • Thank u, it's interesting solution but I hope to use not only english and by google/yandex/microsoft translator or certain package for this task, not so universal solution – Demetry Pascal May 24 '20 at 19:26
2

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

Prathamesh
  • 1,064
  • 1
  • 6
  • 16
  • Thank u but pronouncing doesn't give what exactly I need: phones are hard and this package generally supports rhymes and something like that. Pysle gives hard phonetics too, I should use just latin symbols like 'bomb' = 'bomb', not 'bomb' = 'bɒm' – Demetry Pascal May 24 '20 at 19:21
2

You might wanna check out the epitran python library

  • Thank u! It looks very like i need but usually gives not so current output (without some symbols). For example, 'salam' (persian) goes to 'slom', not 'solom', and 'man' (persian) goes to 'mn', not 'man'. However, it's better than nothing – Demetry Pascal May 24 '20 at 20:24
  • @ДмитрийПасько are you sure non-ascii characters are getting printed properly? – Filip Henningsson May 24 '20 at 21:50
  • I mean that it's not so good package. It gives not enough correct prononciation -- for farsi without a lot of symbols, for russian -- not only english symbols ([for example](https://github.com/dmort27/epitran/issues/50)) So it looks like I want, but not enough – Demetry Pascal May 25 '20 at 00:01
0
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

sourab maity
  • 1,025
  • 2
  • 8
  • 16