{"id":5234,"library":"g2p-en","title":"English Grapheme To Phoneme Conversion","description":"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.","status":"maintenance","version":"2.1.0","language":"en","source_language":"en","source_url":"https://github.com/Kyubyong/g2p","tags":["g2p","phoneme","grapheme","nlp","speech-synthesis","english","pronunciation","text-to-speech"],"install":[{"cmd":"pip install g2p-en","lang":"bash","label":"Install core library"},{"cmd":"python -m nltk.downloader \"averaged_perceptron_tagger\" \"cmudict\"","lang":"bash","label":"Download NLTK data (required post-install)"}],"dependencies":[{"reason":"Numerical operations and inference engine.","package":"numpy","optional":false},{"reason":"Used for part-of-speech tagging (e.g., for homograph disambiguation) and dictionary lookups (CMU Pronouncing Dictionary).","package":"nltk","optional":false},{"reason":"Handles spelling out numbers and other text normalization.","package":"inflect","optional":false},{"reason":"Likely used for string similarity or comparison in internal algorithms.","package":"Distance","optional":false}],"imports":[{"symbol":"G2p","correct":"from g2p_en import G2p"}],"quickstart":{"code":"from g2p_en import G2p\n\ntexts = [\n    \"I have $250 in my pocket.\", # number -> spell-out\n    \"popular pets, e.g. cats and dogs\", # e.g. -> for example\n    \"I refuse to collect the refuse around here.\", # homograph\n    \"I'm an activationist.\" # newly coined word\n]\n\ng2p = G2p()\nfor text in texts:\n    out = g2p(text)\n    print(out)","lang":"python","description":"Initializes the G2p converter and processes a list of English sentences, demonstrating handling of numbers, abbreviations, homographs, and out-of-vocabulary words."},"warnings":[{"fix":"Ensure your environment is set up for NumPy. If you had TensorFlow installed specifically for g2p-en, it's no longer needed.","message":"Version 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.","severity":"breaking","affected_versions":"< 2.0"},{"fix":"Run `python -m nltk.downloader \"averaged_perceptron_tagger\" \"cmudict\"` after installing the package.","message":"The 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`.","severity":"gotcha","affected_versions":"All"},{"fix":"Be aware of potential ambiguities for homographs in critical applications; manual review or external context might be necessary.","message":"While 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.","severity":"gotcha","affected_versions":"All"},{"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.","message":"For 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.","severity":"gotcha","affected_versions":"All"},{"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`.","message":"The 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.","severity":"gotcha","affected_versions":"All"}],"env_vars":null,"last_verified":"2026-04-13T00:00:00.000Z","next_check":"2026-07-12T00:00:00.000Z"}