g2p_en Documentation

repository·master·Indexed 21 days ago

https://github.com/kyubyong/g2p

A Python module for converting English graphemes to phonemes. It utilizes the CMU Pronouncing Dictionary, Part-of-Speech tagging for homograph disambiguation, and a neural network model for predicting pronunciations of out-of-vocabulary words.

Tokens
500
Snippets
2
Records
4
Agent score
26%

What's inside g2p_en

  1. g2pE Algorithm Overview

    master

    The conversion process follows these steps:

    1. Normalization: Spells out Arabic numbers and currency symbols (e.g., $200 becomes two hundred dollars).
    2. Disambiguation: Attempts to retrieve correct pronunciations for heteronyms based on their Part-of-Speech (POS).
    3. Dictionary Lookup: Uses the CMU Pronouncing Dictionary for standard words.
    4. Neural Prediction: For Out-of-Vocabulary (OOV) words, it predicts pronunciations using a neural net model (inference is performed using NumPy).
  2. Use the G2p class for phoneme conversion

    master

    To convert English text (graphemes) to phonemes, import the G2p class from g2p_en. You can instantiate the class and call the instance directly with a string. The module handles:

    • Spelling out Arabic numbers and currency symbols.
    • Disambiguating homographs using Part-of-Speech (POS) tagging.
    • Looking up words in the CMU Pronouncing Dictionary.
    • Predicting pronunciations for Out-of-Vocabulary (OOV) words using a neural network model.

    The output is a list of phonemes and spaces.

    from g2p_en import G2p
    
    texts = [
        "I have $250 in my pocket.",
        "popular pets, e.g. cats and dogs",
        "I refuse to collect the refuse around here.",
        "I'm an activationist."
    ]
    
    g2p = G2p()
    for text in texts:
        out = g2p(text)
        print(out)