Expand description
English grapheme-to-phoneme conversion for Kokoro, GPL-free.
Kokoro’s voices were trained on phonemes from misaki, hexgrad’s G2P, so
this crate reproduces misaki’s English pipeline: spaCy’s tokenization,
Penn Treebank tags, the misaki gold and silver lexicons, heteronym
selection, stress rules, morphology, and number, currency and year
reading. Each stage is checked against its Python original by the parity
harness in tools/parity.
Where upstream hands unknown words to eSpeak NG (GPL-3.0), this crate
uses a small embedded neural model trained on the same lexicons
(OovFallback::Neural). It links no GPL code.
use loqui_g2p::{Dialect, G2p, OovFallback};
let g2p = G2p::new(Dialect::American, OovFallback::Neural)?;
assert_eq!(g2p.phonemize("Hello world."), "həlˈO wˈɜɹld.");Modules§
- numbers
- English number words, as misaki gets them from Python’s
num2words. - tagger
- A part-of-speech tagger distilled from spaCy’s
en_core_web_sm. - tokenize
- spaCy’s English tokenizer, reimplemented.
Structs§
- G2p
- A ready-to-use phonemizer. Construction parses the lexicons (tens of
megabytes of JSON), so build one and share it: it is
Send + Sync. - Neural
G2p - The loaded model. Immutable after construction, so
Syncand shareable. - Phoneme
Token - One spoken word and its phonemes, as Kokoro’s chunker consumes them.
Enums§
- Dialect
- Which English the lexicons, rules and fallback model follow.
- Error
- OovFallback
- What happens to a word that no lexicon entry, morphology rule or number rule covers: a name, a coinage, a typo.
Constants§
- MAX_
WORD_ CHARS - The longest spelling the model can take: its 64 positions hold the
word plus
<s>and</s>. - UNKNOWN
- What misaki writes for a word it could not phonemize at all.