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-enVerified import paths — ran on the pinned version, not inferred.
Initializes the G2p converter and processes a list of English sentences, demonstrating handling of numbers, abbreviations, homographs, and out-of-vocabulary words.
Ensure your environment is set up for NumPy. If you had TensorFlow installed specifically for g2p-en, it's no longer needed.
Run `python -m nltk.downloader "averaged_perceptron_tagger" "cmudict"` after installing the package.
Be aware of potential ambiguities for homographs in critical applications; manual review or external context might be necessary.
Test with a representative corpus of OOV words if accuracy is critical; consider adding custom dictionary entries if specific OOV words are consistently mispronounced.
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`.
Change the import statement to correctly reference the `G2p` class: `from g2p_en import G2p`.
Download the required NLTK data by running the following commands in a Python interpreter: `import nltk; nltk.download('cmudict'); nltk.download('averaged_perceptron_tagger')`.Install the package using pip: `pip install g2p-en`.