mstar.model.kokoro.g2p#
Grapheme-to-phoneme front end and sentence chunking for Kokoro.
Runs on the CPU in the API data worker (process_prompt). English uses
misaki’s lexicon G2P with, when the optional misaki[en] extra (which
bundles espeak-ng) is installed, its espeak fallback for out-of-dictionary
words; Japanese and Mandarin use misaki[ja] / misaki[zh]; the other
languages Kokoro ships voices for go through espeak-ng.
Text is cut into chunks at sentence boundaries. A chunk never exceeds the model’s 510-phoneme window; sentences are packed up to a target size so the first chunk is small (time-to-first-audio) while later ones amortize per-step cost.
Functions
|
Pack (text, phonemes) sentences produced by a string-level G2P. |
|
|
|
|
|
|
|
Greedily merge consecutive pieces while the phoneme count stays within |
|
Cut a phoneme string into pieces of at most |
|
Group misaki tokens into sentences, keeping closing quotes/brackets with the sentence they end. |
Classes
|
One synthesis unit: the source text and its phoneme string. |
|
Lazily constructed per-language phonemizers plus chunking. |
- class mstar.model.kokoro.g2p.Chunk(text, phonemes)[source]#
Bases:
objectOne synthesis unit: the source text and its phoneme string.
- class mstar.model.kokoro.g2p.G2PFrontend(chunk_target, max_phonemes, espeak_fallback=True, first_chunk_target=None)[source]#
Bases:
objectLazily constructed per-language phonemizers plus chunking.
- Parameters:
- available(lang)[source]#
Whether this process can phonemize
lang.English is judged by the presence of
misaki.en(its backend loads spaCy, which the process answering/v1/audio/voicesnever needs); the other languages by constructing their backend, which is cheap.
- mstar.model.kokoro.g2p.chunk_phoneme_strings(pairs, target, hard_max, first_target=None)[source]#
Pack (text, phonemes) sentences produced by a string-level G2P.
- mstar.model.kokoro.g2p.pack_pieces(pieces, target, first_target=None)[source]#
Greedily merge consecutive pieces while the phoneme count stays within
target(first_targetfor the first chunk); a single piece may exceed it.