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

4

6

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?

Fredrika answered 24/5, 2020 at 14:38 Comment(0)
C
3

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

Colan answered 24/5, 2020 at 14:47 Comment(1)
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'Fredrika
S
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.

Spoondrift answered 24/5, 2020 at 14:46 Comment(1)
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 solutionFredrika
V
2

You might wanna check out the epitran python library

Vardon answered 24/5, 2020 at 14:48 Comment(3)
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 nothingFredrika
@ДмитрийПасько are you sure non-ascii characters are getting printed properly?Vardon
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) So it looks like I want, but not enoughFredrika
C
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

Crowley answered 29/7, 2020 at 6:7 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.