Download runtime/text.py from florianvoss/kokoro-sima: direct link, hf CLI and curl.
- Browser
- Download file 1.38 kB
-
https://huggingface.co/florianvoss/kokoro-sima/resolve/main/runtime/text.py
- Command line
-
hf download hf://florianvoss/kokoro-sima/runtime/text.py
-
curl -L -o text.py https://huggingface.co/florianvoss/kokoro-sima/resolve/main/runtime/text.py
1.38 kB
| """Kokoro text frontends without loading the original PyTorch model.""" | |
| import ctypes.util | |
| import os | |
| from pathlib import Path | |
| def create_g2p(language): | |
| from misaki import en, espeak | |
| from phonemizer.backend.espeak.wrapper import EspeakWrapper | |
| library = os.environ.get('KOKORO_ESPEAK_LIBRARY') | |
| data = os.environ.get('KOKORO_ESPEAK_DATA_PATH') | |
| if not library and not data: | |
| native = ctypes.util.find_library('espeak-ng') | |
| for candidate in ('/usr/lib/aarch64-linux-gnu/espeak-ng-data', | |
| '/usr/lib/x86_64-linux-gnu/espeak-ng-data', '/usr/share/espeak-ng-data'): | |
| if native and (Path(candidate) / 'phontab').is_file(): | |
| library, data = native, candidate | |
| break | |
| if library: | |
| EspeakWrapper.set_library(library) | |
| if data: | |
| EspeakWrapper.set_data_path(data) | |
| if language in ('a', 'b'): | |
| british = language == 'b' | |
| fallback = espeak.EspeakFallback(british=british) | |
| return en.G2P(trf=False, british=british, fallback=fallback, unk='') | |
| if language == 'j': | |
| from misaki.ja import JAG2P | |
| return JAG2P() | |
| if language == 'z': | |
| from misaki.zh import ZHG2P | |
| return ZHG2P(version=None) | |
| codes = {'e': 'es', 'f': 'fr-fr', 'h': 'hi', 'i': 'it', 'p': 'pt-br'} | |
| return espeak.EspeakG2P(language=codes[language]) | |