Python Arpabet phonetic transcription

前端 未结 4 1337
天涯浪人
天涯浪人 2020-12-28 10:23

Is there a library in python that can convert words (mainly names) to Arpabet phonetic transcription?

BARBELS -> B AA1 R B AH0 L Z

BARBEQUE -> B AA1 R B IH0

4条回答
  •  被撕碎了的回忆
    2020-12-28 10:23

    What you want is variously called "letter to sound" or "grapheme to phoneme" engine. There are a few around, including one in every text-to-speech system.

    I usually deal with non-US accents, for which I use espeak. It doesn't output arpabet directly (which is restricted to US sounds anyway), but you can coax it to attempt an American accent, and convert from IPA to arpabet later.

    >>> from subprocess import check_output
    >>> print check_output(["espeak", "-q", "--ipa",
                            '-v', 'en-us',
                            'hello  world']).decode('utf-8')
    həlˈoʊ wˈɜːld
    

    You can use -x rather than --ipa for espeak's own phone representation (it's ascii):

    >>> check_output(["espeak", "-q", "-x", '-v', 'en-us', 'hello world'])
    h@l'oU w'3:ld
    

    Converting to arpabet isn't quite as simple as a character look-up though; for example "tʃ" should be converted to "CH", not the "T SH" that a greedy conversion would give you (except, that is, in odd cases like "swˈɛtʃɑːp" for "sweatshop").

提交回复
热议问题