Tts internals

From drakulavich/kesha-voice-kit · View interactive version

Tts internals is an AI agent skill from the GitHub repository drakulavich/kesha-voice-kit. Use when working on kesha TTS internals — voice routing and which engine serves which voice-id prefix, Kokoro/Vosk ONNX I/O shapes, the CharsiuG2P vs FluidAudio G2P split, SSML handling, multilingual behaviour (es/fr/it/pt on ONNX, hi/ja/zh on darwin-arm64), or the KESHA_* TTS environment variables.

How to use this skill

Skill file

TTS internals

Engines

Text-to-speech via three engines selected by voice id prefix:

Install Kokoro + Vosk-TTS explicitly with kesha install --tts (~990 MB). macos-* voices use installed macOS voices and need no model install.

Behavior, G2P, and SSML

ONNX I/O shapes

Environment variables

CharsiuG2P engine (es/fr/it/pt on ONNX builds)

Romance-language G2P uses the klebster 3-file KV-cache ONNX export of CharsiuG2P

(Zhu et al. 2022). Three ort sessions implement an autoregressive byte-level seq2seq decode:

encoder_model.onnx (run once), decoder_model.onnx (step 0, seeds all 16 KV presents),

decoder_with_past_model.onnx (steps 1..N, 8 rolling decoder KV + 8 constant encoder KV).

License: CC-BY 4.0 (attribution in NOTICES).

Tokenizer: ByT5 byte-level — input format "<tag>: word" where tag is one of

<spa> (es), <fra> (fr), <ita> (it), <por-bz> (pt). Each byte maps to

byte_value + 3 (special-token offset), followed by EOS id 1.

OOV remap: Charsiu can emit IPA symbols outside Kokoro's phoneme vocabulary

(tie-bar affricates t͡s/t͡ʃ/d͡ʒ, Latin g U+0067, pre-composed nasals õ/ũ/ẽ).

tts::charsiu::remap normalizes these to Kokoro-vocab equivalents (ʦ/ʧ/ʤ,

script-g U+0261, NFD base+combining-tilde); locked by a zero-residual-OOV regression test.

Normalize pass: numbers and acronyms are expanded before G2P (512 → quinientos doce

in es, etc.) via tts::normalize::{numbers,acronyms}. CharsiuG2P collapses raw digits;

the normalizer runs first so digit sentences produce longer, correctly-paced audio.

IO contract (PR #185, verified against the pinned export). encoder_model: in

input_ids int64 [B,S] + attention_mask int64 [B,S], out last_hidden_state

f32 [B,S,256]. decoder_model (step 0): in input_ids + encoder_attention_mask

f32 [B,6,S,64]. decoder_with_past_model (steps 1..N): in input_ids [B,1] +

encoder_attention_mask + the 16 past_key_values.*, out logits [B,1,384] + only

the 8 decoder presents — the encoder K/V are seeded once at step 0 and re-fed

verbatim every step. Decode is greedy, stops on EOS, capped at 128 steps.

Model is ByT5-tiny: vocab_size 384, d_model 256, 12 encoder / 4 decoder layers,

6 heads. Measured ~36 ms/word single-thread on M2, byte-identical to the Python

reference for es/fr/it/pt.

Multilingual G2P (#511)

--lang es-ES selects Castilian Spanish via charsiu::is_castilian_region / base_lang

resolution. Because the upstream CharsiuG2P klebster export contains no Castilian θ tag

(confirmed in the #511 Phase-0 spike), the is_castilian_region branch in

tts/charsiu/mod.rs falls back to Latin-American phonology (<spa> tag) and emits

a one-time stderr note. es / es-419 / es-MX continue to use Latin-American directly

with no warning. Per-language acronym stop-lists (ES/FR/IT/PT_STOP_LIST in

rust/src/tts/normalize/acronyms.rs) are curated seeds that prevent word-acronyms

(OTAN, OVNI, FIFA…) from being letter-spelled; they are not exhaustive.

FluidAudio KokoroAne variants — macOS Chinese (#492)

On system_kokoro (darwin/ANE), tts::fluid_kokoro::with_kokoro resolves the voice's

language (lang_for_fluid_id) and passes it to init_kokoro(voice, lang). The fork's

Swift bridge (fluidaudio-rs, version pinned in rust/Cargo.toml) maps it to a KokoroAneVariant:

zh → .mandarin (tone-aware G2P: jieba + g2pw + bopomofo + tone sandhi), everything

else → .english (en plus Latin-script es/fr/it/pt, which the English G2P handles

acceptably). The .mandarin variant reads its own ANE-zh/ bundle (nested

voices/<id>.bin), which kesha install --tts zh stages and SHA-256-checks up front

(models/staging.rs::stage_fluidaudio_kokoro_assets, models/manifest.rs::ANE_ZH_FILES);

nothing is fetched at synthesis (#823). zh voices live in ANE_ZH_FILES, not

ANE_KOKORO_VOICES, and the staging-coverage test counts them there (like af_heart in

ANE_EN_FILES). Default zh voice: zh-zm_050 (male). Native-script hi/ja on the Kokoro

voices still fail fast (E_SCRIPT_UNSUPPORTED) — no FluidAudio KokoroAne variant for them

yet; with no --voice, src/voice-routing.ts::resolveSayVoice routes that text on darwin to

an installed AVSpeech voice (Lekha hi-IN, Otoya ja-JP) instead. The

-Wl,-rpath,/usr/lib/swift link arg in build.rs is emitted under

coreml/system_kokoro/system_diarize so the Swift runtime loads without

MACOSX_DEPLOYMENT_TARGET=14.0 locally.

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.