Repository navigation
Closed
Labels
area:inferenceGeneration, sampling, decoding (incl. speculative, DRY)area:modelsModel architectures, weights, loading, metadatapriority:mediumMedium prioritystatus:doneCompletedtype:enhancementNew features, capabilities, or significant additions
Milestone
Description
Part of #363
Blocked by #364 (Phase 1 server audio plumbing). Recommended to land after the STT sub-issue (#365), but the only hard dependency is #364.
Problem / Background
The /v1/audio/speech endpoint (epic #363) needs a real text-to-speech model plus a vocoder/codec to turn model output into a waveform. mlxcel has no TTS path. The server plumbing (#364) and the shared dedicated-thread MLX worker (AudioWorker, landed with #365) already exist, so this sub-issue ports a TTS model and vocoder and wires synthesis to /v1/audio/speech.
Proposed Solution
- Port a lightweight TTS model available as MLX. Recommended first target: Kokoro (phoneme-to-mel acoustic model with a built-in iSTFTNet vocoder, so it needs no separate neural codec, which makes it the simplest self-contained first TTS).
- For TTS families that do not bundle a vocoder, a separate neural vocoder/codec decode to waveform is required (e.g. Vocos, BigVGAN, EnCodec, or SNAC). Scope this sub-issue to one acoustic model plus whatever vocoder it requires; Kokoro keeps that to a single self-contained port.
- Implement the synthesis direction of the existing
AudioModelProviderseam (synthesize) and run it on the sharedAudioWorker(src/server/audio_worker.rs), so model load and MLX evaluation happen on one stream-initialized thread, exactly as the STT provider does. The route handler (audio_speechinsrc/server/routes/audio.rs) and the binary-response / WAV-writer plumbing are already in place from feat(server): audio endpoint plumbing (multipart upload, binary response, WAV output) #364. - Flow: text (plus
voice,speed) to grapheme-to-phoneme to acoustic model to vocoder to waveform to encode (WAV via the feat(server): audio endpoint plumbing (multipart upload, binary response, WAV output) #364 writer; mp3 optional) to binary response.
Checkpoint (local validation asset)
Already downloaded for development and e2e validation:
- Path:
models/kokoro-82m/(repoprince-canuma/Kokoro-82M; the identicalmlx-community/Kokoro-82M-bf16works too). - Model:
kokoro-v1_0.safetensors(~312 MB, 548 tensors), non-quantized. - Vocoder: iSTFTNet, built into the model (no separate codec checkpoint).
- Voices:
voices/<name>.safetensors(54 voices; defaultaf_heart). The redundant.ptcopies are unused (read the.safetensorsvoice packs). config.jsoncarries the architecture under anistftnetblock plusdim_in/hidden_dim/max_conv_dim/max_durand related fields.
Key design notes
- Detection: Kokoro's
config.jsonhas NO top-levelmodel_typefield, so themodel_type-based dispatch insrc/models/detection.rswill not auto-detect it. Detection must key off another signal, for example the presence of theistftnetconfig block or thekokoro-v1_0.safetensorsweight filename. Decide this so-m models/kokoro-82mresolves to the TTS provider. - Grapheme-to-phoneme (g2p): Kokoro consumes phonemes, not raw text, so a g2p front-end is required (the analog of the STT mel front-end). This is the main new host-side component beyond the acoustic model and vocoder; decide the approach (a Rust phonemizer, a bundled lexicon plus rules, or an espeak-style backend) and the language scope. The voice embedding is selected from the
voices/pack by thevoicerequest field. - Reuse: the
AudioWorkerfrom feat(models): Whisper ASR port for speech-to-text (/v1/audio/transcriptions) #365 (dedicated MLX thread + thread-local stream) handles the MLX thread/stream affinity, so the TTS provider must not evaluate MLX onspawn_blockingthreads directly. The WAV output encoder and binary-response path come from feat(server): audio endpoint plumbing (multipart upload, binary response, WAV output) #364.
Acceptance Criteria (integrated, not build-only)
- A real Kokoro MLX checkpoint synthesizes audio via
POST /v1/audio/speechend-to-end, returning playable audio (verify by decoding the response and checking sample rate / duration). -
voice(selects avoices/pack),speed, andresponse_formatare honored. - The server resolves a Kokoro checkpoint to the TTS provider (detection works without a
model_typefield). -
mlxcel listshows the TTS architecture. - Unit tests added;
cargo test,cargo clippy --all-targets -- -D warnings, andcargo fmt --checkclean. -
docs/supported-models.mdupdated.
Technical Considerations
- Needs the audio-output encoder (WAV writer) and binary-response plumbing from feat(server): audio endpoint plumbing (multipart upload, binary response, WAV output) #364, and the
AudioWorkerfrom feat(models): Whisper ASR port for speech-to-text (/v1/audio/transcriptions) #365. - The vocoder decode is part of the acoustic model here (Kokoro's iSTFTNet is built in); the g2p front-end is the main new host-side piece.
Metadata
Metadata
Assignees
Labels
area:inferenceGeneration, sampling, decoding (incl. speculative, DRY)area:modelsModel architectures, weights, loading, metadatapriority:mediumMedium prioritystatus:doneCompletedtype:enhancementNew features, capabilities, or significant additions
Activity
feat(models): Kokoro-82M TTS with iSTFTNet vocoder for /v1/audio/spee…
feat(models): Kokoro-82M TTS with iSTFTNet vocoder for /v1/audio/spee…