Download pronunciation.py from gitmodelmujtaba/kokoro-grounded-documentary: direct link, hf CLI and curl.
- Browser
- Download file 3.14 kB
-
https://huggingface.co/gitmodelmujtaba/kokoro-grounded-documentary/resolve/main/pronunciation.py
- Command line
-
hf download hf://gitmodelmujtaba/kokoro-grounded-documentary/pronunciation.py
-
curl -L -o pronunciation.py https://huggingface.co/gitmodelmujtaba/kokoro-grounded-documentary/resolve/main/pronunciation.py
3.14 kB
| """ | |
| pronunciation.py | |
| ---------------- | |
| Phonetic lexicon and pronunciation normalization for difficult Vedic, Sanskrit, | |
| and historical terminology when synthesizing speech via Kokoro-ONNX. | |
| Calibrated via Gemini acoustic phonetics for British RP (en-gb) Kokoro voice models. | |
| Ensures authentic Sanskrit pronunciation without syllable chopping or English diphthong distortion. | |
| """ | |
| import re | |
| from typing import Dict, Optional | |
| # Core Vedic & Sanskrit phonetic replacement lexicon for Kokoro (en-gb) | |
| VEDIC_PRONUNCIATION_MAP: Dict[str, str] = { | |
| # Seers & Canonical Texts | |
| r"\bṚṣis?\b": "Rishis", | |
| r"\bRsis\b": "Rishis", | |
| r"\bRsi\b": "Rishi", | |
| r"\bRig\s*Veda\b": "Rig Veyduh", | |
| r"\bRigveda\b": "Rig Veyduh", | |
| r"\bṚgveda\b": "Rig Veyduh", | |
| r"\bVedas\b": "Veyduhs", | |
| r"\bVeda\b": "Veyduh", | |
| r"\bVedic\b": "Veydik", | |
| # Cosmic Unity & Creation Hymns | |
| r"\bvipra bahudha vadanti\b": "Vipruh buh-hoo-dah vuh-dun-tee", | |
| r"\bEkam Sat\b": "Ehkum Sut", | |
| r"\bTad Ekam\b": "Tud Ehkum", | |
| r"\bEkam\b": "Ehkum", | |
| r"\bNasadiya Sukta\b": "Nahsuh-deeyuh Sooktuh", | |
| r"\bNāsadīya Sūkta\b": "Nahsuh-deeyuh Sooktuh", | |
| r"\bVisvakarman\b": "Veeshvah-kurmun", | |
| r"\bViśvakarman\b": "Veeshvah-kurmun", | |
| r"\bPrajapati\b": "Prajah-pati", | |
| r"\bPrajāpati\b": "Prajah-pati", | |
| # Deities | |
| r"\bAgni\b": "Ugnee", | |
| r"\bIndra\b": "Indruh", | |
| r"\bVaruna\b": "Vah-roonuh", | |
| r"\bVaruṇa\b": "Vah-roonuh", | |
| r"\bVayu\b": "Vah-yu", | |
| r"\bVāyu\b": "Vah-yu", | |
| r"\bVisnu\b": "Vishnu", | |
| r"\bViṣṇu\b": "Vishnu", | |
| r"\bSoma\b": "Sohmuh", | |
| # Upanishads & Philosophers | |
| r"\bBrihad-Aranyaka\b": "Breehad Aranyaka", | |
| r"\bBrihadaranyaka\b": "Breehad Aranyaka", | |
| r"\bBṛhadāraṇyaka\b": "Breehad Aranyaka", | |
| r"\bUpanishads\b": "Oopunishuds", | |
| r"\bUpanishad\b": "Oopunishud", | |
| r"\bUpaniṣads?\b": "Oopunishud", | |
| r"\bYajnavalkya\b": "Yahgnya Vahlkya", | |
| r"\bYājñavalkya\b": "Yahgnya Vahlkya", | |
| r"\bmahiman\b": "muh-hee-man", | |
| r"\bChandogya\b": "Chahn-dohg-ya", | |
| r"\bChāndogya\b": "Chahn-dohg-ya", | |
| r"\bKatha\b": "Kuh-tuh", | |
| r"\bKaṭha\b": "Kuh-tuh", | |
| r"\bMaitri\b": "Mai-tree", | |
| r"\bMaitrī\b": "Mai-tree", | |
| # Core Metaphysical Concepts | |
| r"\bBrahman\b": "Brah-man", | |
| r"\bBrahma\b": "Brah-muh", | |
| r"\bAtman\b": "Aht-man", | |
| r"\bĀtman\b": "Aht-man", | |
| r"\bṚta\b": "Rituh", | |
| r"\bRta\b": "Rituh", | |
| r"\bSamsara\b": "Sum-sahruh", | |
| r"\bSaṃsāra\b": "Sum-sahruh", | |
| r"\bMoksha\b": "Mohkshuh", | |
| r"\bMokṣa\b": "Mohkshuh", | |
| r"\bMaya\b": "Mah-yah", | |
| r"\bMāyā\b": "Mah-yah", | |
| r"\bDharma\b": "Dhurmuh", | |
| r"\bKarma\b": "Kurmuh", | |
| } | |
| def apply_pronunciation_lexicon( | |
| text: str, custom_map: Optional[Dict[str, str]] = None | |
| ) -> str: | |
| """ | |
| Replaces ancient and difficult terms with their phonetic equivalents for TTS. | |
| """ | |
| active_map = VEDIC_PRONUNCIATION_MAP.copy() | |
| if custom_map: | |
| active_map.update(custom_map) | |
| result = text | |
| for pattern, replacement in active_map.items(): | |
| result = re.sub(pattern, replacement, result, flags=re.IGNORECASE) | |
| return result | |