Registry / ai-ml / g2p-en

g2p-en

JSON →
library2.1.0pypypi✓ verified 23d ago

g2p-en is a Python module designed for converting English graphemes (spelling) to phonemes (pronunciation). It is essential for tasks like speech synthesis. The library uses a combination of dictionary lookups, part-of-speech tagging for homograph disambiguation, and a neural network (using NumPy for inference as of v2.0) for out-of-vocabulary words. The current version is 2.1.0, released in late 2019, and its release cadence appears to be infrequent.

pip install g2p-en
INSTALL
IMPORT
SIG · G2P-EN
G
g2p-en
ai-mlpythonv2.1.0
Install
7.0s avg
Import
7469ms
Disk
116MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v2.1.0 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.95 runs
installs and imports cleanly · install 0.0s · import 7.790s · 114.9MB
glibc
py 3.103.95 runs
installs and imports cleanly · install 7.0s · import 7.148s · 112MB
116MB installed
● package 116MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

G2p
from g2p_en import G2p

Initializes the G2p converter and processes a list of English sentences, demonstrating handling of numbers, abbreviations, homographs, and out-of-vocabulary words.

from g2p_en import G2p texts = [ "I have $250 in my pocket.", # number -> spell-out "popular pets, e.g. cats and dogs", # e.g. -> for example "I refuse to collect the refuse around here.", # homograph "I'm an activationist." # newly coined word ] g2p = G2p() for text in texts: out = g2p(text) print(out)
Debug
Known issues
breakingVersion 2.0 removed TensorFlow as a dependency, replacing it with NumPy for neural network inference. Users upgrading from pre-2.0 versions will no longer require TensorFlow.
fix
Ensure your environment is set up for NumPy. If you had TensorFlow installed specifically for g2p-en, it's no longer needed.
affects: < 2.0
gotchaThe library requires downloading specific NLTK data files ('averaged_perceptron_tagger' and 'cmudict') after installation. This step is crucial for the library's functionality and is not performed automatically by `pip install`.
fix
Run `python -m nltk.downloader "averaged_perceptron_tagger" "cmudict"` after installing the package.
affects: All
gotchaWhile the library attempts to disambiguate homographs (words spelled the same but pronounced differently, like 'refuse' as a verb vs. noun) using part-of-speech tagging, perfect contextual disambiguation is not always guaranteed for all cases.
fix
Be aware of potential ambiguities for homographs in critical applications; manual review or external context might be necessary.
affects: All
gotchaFor words not present in its internal dictionaries (Out-Of-Vocabulary words), g2p-en uses a neural network to predict pronunciations. While it makes a 'best guess', accuracy may vary for highly novel, specialized, or irregularly spelled terms.
fix
Test with a representative corpus of OOV words if accuracy is critical; consider adding custom dictionary entries if specific OOV words are consistently mispronounced.
affects: All
gotchaThe library performs internal text preprocessing, including spelling out numbers ($250 -> two hundred fifty dollars), expanding common abbreviations (e.g. -> for example), and normalizing contractions (I'm -> I am). This can alter the input text before G2P conversion.
fix
Be aware that input text is transformed. If fine-grained control over text normalization is needed, consider pre-processing your text externally before passing it to `g2p-en`.
affects: All
Errors
Common errors & fixes
ImportError: cannot import name 'g2p' from 'g2p_en'
The `g2p-en` library's main class for grapheme-to-phoneme conversion is named `G2p` (with a capital 'G'), but developers often incorrectly try to import it as `g2p` (lowercase).
fix
Change the import statement to correctly reference the `G2p` class: `from g2p_en import G2p`.
LookupError: Resource cmudict not found. Please use the NLTK Downloader to obtain the resource:
The `g2p-en` library depends on specific NLTK data resources, namely the CMU Pronouncing Dictionary (`cmudict`) and the `averaged_perceptron_tagger`. This error occurs when these resources have not been downloaded or cannot be found by NLTK.
fix
Download the required NLTK data by running the following commands in a Python interpreter: `import nltk; nltk.download('cmudict'); nltk.download('averaged_perceptron_tagger')`.
ModuleNotFoundError: No module named 'g2p_en'
The `g2p-en` package is not installed in the Python environment being used.
fix
Install the package using pip: `pip install g2p-en`.
Upgrade
Version history
2.1.0latest on PyPI · released Dec 31, 2019
Audit
Dependencies
numpyrequiredNumerical operations and inference engine.
nltkrequiredUsed for part-of-speech tagging (e.g., for homograph disambiguation) and dictionary lookups (CMU Pronouncing Dictionary).
inflectrequiredHandles spelling out numbers and other text normalization.
DistancerequiredLikely used for string similarity or comparison in internal algorithms.
Agent activity
13 hits · last 30 days
node
10
OpenAI (training)
2
Resources
g2p-en — pip install g2p-en · libregistry