CMUdict (cmudict) is a Python wrapper package for the CMU Pronouncing Dictionary data files, providing access to over 134,000 English words and their ARPAbet pronunciations. It exposes the data with minimal assumptions on its usage. The library is actively maintained with frequent patch releases, often related to dependency updates or minor fixes, and occasional minor version bumps for features like type hints.
pip install cmudictVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to initialize the CMU dictionary and retrieve pronunciations for a specific word using `cmudict.dict()`. It also highlights `cmudict.entries()` for iterating through all word-pronunciation pairs.
Understand the return types: `cmudict.dict()` for direct word-to-pronunciations mapping, `cmudict.entries()` for iterating all individual word-pronunciation pairs.
Always check for `None` or an empty list when performing lookups: `if pronunciations: ... else: word_not_found_handling()`.
Avoid installing these specific yanked versions. Use the latest stable version (e.g., `pip install cmudict`) or a known working older version.
Ensure your environment is compatible with Python 3.9+ for the best type hint experience, and update to `cmudict>=1.1.1` to benefit from these internal improvements.
Install the package using pip: `pip install cmudict`
Before accessing a word's pronunciation, check if the word exists in the dictionary: `import cmudict; d = cmudict.dict(); word = 'UNKNOWNWORD'; if word.upper() in d: print(d[word.upper()])`
Access the dictionary data by calling the appropriate function, such as `cmudict.dict()`, which returns a dictionary object: `import cmudict; pronunciation_dict = cmudict.dict(); word = 'EXAMPLE'; print(pronunciation_dict[word.upper()])`