Skip to main content

A Simple Python Module for English Grapheme To Phoneme Conversion

Project description

This module is designed to convert English graphemes (spelling) to phonemes (pronunciation). It is considered essential in several tasks such as speech synthesis. Unlike many languages like Spanish or German where pronunciation of a word can be inferred from its spelling, English words are often far from people’s expectations. Therefore, it will be the best idea to consult a dictionary if we want to know the pronunciation of some word. However, there are at least two tentative issues in this approach. First, you can’t disambiguate the pronunciation of homographs, words which have multiple pronunciations. (See a below.) Second, you can’t check if the word is not in the dictionary. (See b below.)

  • a. I refuse to collect the refuse around here. (rɪ|fju:z as verb vs. |refju:s as noun)

  • b. I am an activationist. (activationist: newly coined word which means n. A person who designs and implements programs of treatment or therapy that use recreation and activities to help people whose functional abilities are affected by illness or disability. from WORD SPY

For the first homograph issue, fortunately many homographs can be disambiguated using their part-of-speech, if not all. When it comes to the words not in the dictionary, however, we should make our best guess using our knowledge. In this project, we employ a deep learning seq2seq framework based on TensorFlow.

Algorithm

  1. Spells out arabic numbers and some currency symbols. (e.g. $200 -> two hundred dollars) (This is borrowed from Keith Ito’s code)

  2. Attempts to retrieve the correct pronunciation for homographs based on their POS)

  3. Looks up The CMU Pronouncing Dictionary for non-homographs.

  4. For OOVs, we predict their pronunciations using our neural net model.

Environment

  • python 2.x or 3.x

Dependencies

  • numpy >= 1.13.1

  • tensorflow >= 1.3.0

  • nltk >= 3.2.4

  • python -m nltk.downloader “averaged_perceptron_tagger” “cmudict”

  • inflect >= 0.3.1

  • Distance >= 0.1.3

  • future >= 0.16.0

Installation

pip install g2p_en

OR

python setup.py install

nltk package will be automatically downloaded at your first run.

Training (Note that pretrained model is already included)

python train.py

Usage

from g2p_en import g2p

text = "I refuse to collect the refuse around here."
print(g2p(text))
>>>[u'AY1', ' ', u'R', u'IH0', u'F', u'Y', u'UW1', u'Z', ' ', u'T', u'UW1', ' ', u'K', u'AH0', u'L', u'EH1', u'K', u'T', ' ', u'DH', u'AH0', ' ', u'R', u'EH1', u'F', u'Y', u'UW2', u'Z', ' ', u'ER0', u'AW1', u'N', u'D', ' ', u'HH', u'EH1', u'R']

text = "I am an activationist."
print(g2p(text))
>>>[u'AY1', u'M', ' ', u'AE1', u'N', ' ', u'AE2', u'K', u'T', u'AH0', u'V', u'EY1', u'SH', u'AH0', u'N', u'IH0', u'S', u'T']

If you need to convert lots of texts, you can use the global tf session.

import g2p_en as g2p

with g2p.Session():
    phs = [g2p.g2p(text) for text in texts]

May, 2018.

Kyubyong Park & Jongseok Kim

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

g2p_en-1.0.1.tar.gz (4.0 MB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

g2p_en-1.0.1-py3-none-any.whl (4.0 MB view details)

Uploaded Python 3

File details

Details for the file g2p_en-1.0.1.tar.gz.

File metadata

  • Download URL: g2p_en-1.0.1.tar.gz
  • Upload date:
  • Size: 4.0 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.19.1 setuptools/40.4.3 requests-toolbelt/0.8.0 tqdm/4.26.0 CPython/3.6.5

File hashes

Hashes for g2p_en-1.0.1.tar.gz
Algorithm Hash digest
SHA256 3fd6f3abaf17de9d84e013df0cd3e3e01b611554ada96b83049b09241e1b3863
MD5 97b1662aad2157d87c578636ee820f66
BLAKE2b-256 8d3dcc02a2e408c064983230604712afc6b92fed0337c11c0e0bccc2b7fa9156

See more details on using hashes here.

File details

Details for the file g2p_en-1.0.1-py3-none-any.whl.

File metadata

  • Download URL: g2p_en-1.0.1-py3-none-any.whl
  • Upload date:
  • Size: 4.0 MB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.19.1 setuptools/40.4.3 requests-toolbelt/0.8.0 tqdm/4.26.0 CPython/3.6.5

File hashes

Hashes for g2p_en-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 ba035348e900009daf8e31d53a6cf311fe348c76d4ea0ab112b08ca57b38d38a
MD5 fb183aa204ee8a566760093938f300e4
BLAKE2b-256 5fbe0a2464d05ce60b02d70abbc9d347454e953354279c41d3119da1a48031cd

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page