{"id":4909,"library":"cmudict","title":"CMU Pronouncing Dictionary Python Wrapper","description":"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.","status":"active","version":"1.1.3","language":"en","source_language":"en","source_url":"https://github.com/prosegrinder/python-cmudict","tags":["NLP","linguistics","pronunciation","dictionary","speech"],"install":[{"cmd":"pip install cmudict","lang":"bash","label":"Install latest version"}],"dependencies":[{"reason":"Required Python version range.","package":"python","version":">=3.9,<4.0"}],"imports":[{"note":"The primary module for accessing dictionary data.","symbol":"cmudict","correct":"import cmudict"},{"note":"`.dict()` returns a dictionary where keys are unique words and values are a list of their phonetic pronunciations. Use `cmudict.entries()` if you need a list of (word, pronunciation) tuples where a word with multiple pronunciations will appear multiple times.","wrong":"cmudict.entries() for unique word lookups","symbol":"dict","correct":"cmudict.dict()"}],"quickstart":{"code":"import cmudict\n\n# Get the full dictionary as a mapping from word to a list of pronunciations\npron_dict = cmudict.dict()\n\nword = \"hello\"\npronunciations = pron_dict.get(word)\n\nif pronunciations:\n    print(f\"Pronunciations for '{word}': {pronunciations}\")\n    # Example: Accessing the first pronunciation and its phonemes\n    first_pronunciation_phonemes = pronunciations[0]\n    print(f\"First pronunciation phonemes: {first_pronunciation_phonemes}\")\nelse:\n    print(f\"'{word}' not found in CMUdict.\")\n\n# To get all entries as (word, pronunciation) tuples (e.g., for iteration)\nall_entries = cmudict.entries()\n# print(f\"Total entries (including variants): {len(all_entries)}\")\n\n# Example of getting pronunciations via entries() (less direct for single word lookup)\n# target_word = \"example\"\n# example_pronunciations = [p for w, p in all_entries if w == target_word]\n# print(f\"Pronunciations for '{target_word}' (from entries): {example_pronunciations}\")","lang":"python","description":"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."},"warnings":[{"fix":"Understand the return types: `cmudict.dict()` for direct word-to-pronunciations mapping, `cmudict.entries()` for iterating all individual word-pronunciation pairs.","message":"The methods `cmudict.dict()` and `cmudict.entries()` return data in different structures and are often confused. `cmudict.dict()` maps unique words to a list of their pronunciations, while `cmudict.entries()` returns a list of (word, pronunciation) tuples, meaning words with multiple pronunciations will have multiple entries in the list.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Always check for `None` or an empty list when performing lookups: `if pronunciations: ... else: word_not_found_handling()`.","message":"Words not found in the CMU Pronouncing Dictionary will result in `None` when using `cmudict.dict().get(word)` or an empty list when filtering `cmudict.entries()`. The dictionary is comprehensive but does not include all possible English words or numbers (which should be spelled out).","severity":"gotcha","affected_versions":"All versions"},{"fix":"Avoid installing these specific yanked versions. Use the latest stable version (e.g., `pip install cmudict`) or a known working older version.","message":"Versions `1.0.7`, `1.0.8`, and `1.0.9` were yanked from PyPI due to a 'broken deployment process'. Attempting to install these specific older versions will likely fail or lead to unexpected behavior.","severity":"breaking","affected_versions":"1.0.7, 1.0.8, 1.0.9"},{"fix":"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.","message":"As of v1.1.1, internal typing hints were updated to use built-in types (`list`, `tuple`) instead of deprecated `typing.List` and `typing.Tuple`. While not directly breaking for most users, this reflects a move towards more modern Python typing conventions.","severity":"deprecated","affected_versions":"<1.1.1"}],"env_vars":null,"last_verified":"2026-04-12T00:00:00.000Z","next_check":"2026-07-11T00:00:00.000Z"}