Skip to content

feat(models): TTS model + vocoder for text-to-speech (/v1/audio/speech) #366

Closed

Description

@inureyes

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 AudioModelProvider seam (synthesize) and run it on the shared AudioWorker (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_speech in src/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/ (repo prince-canuma/Kokoro-82M; the identical mlx-community/Kokoro-82M-bf16 works 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; default af_heart). The redundant .pt copies are unused (read the .safetensors voice packs).
  • config.json carries the architecture under an istftnet block plus dim_in / hidden_dim / max_conv_dim / max_dur and related fields.

Key design notes

  • Detection: Kokoro's config.json has NO top-level model_type field, so the model_type-based dispatch in src/models/detection.rs will not auto-detect it. Detection must key off another signal, for example the presence of the istftnet config block or the kokoro-v1_0.safetensors weight filename. Decide this so -m models/kokoro-82m resolves 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 the voice request field.
  • Reuse: the AudioWorker from 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 on spawn_blocking threads 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/speech end-to-end, returning playable audio (verify by decoding the response and checking sample rate / duration).
  • voice (selects a voices/ pack), speed, and response_format are honored.
  • The server resolves a Kokoro checkpoint to the TTS provider (detection works without a model_type field).
  • mlxcel list shows the TTS architecture.
  • Unit tests added; cargo test, cargo clippy --all-targets -- -D warnings, and cargo fmt --check clean.
  • docs/supported-models.md updated.

Technical Considerations

Activity

  1. added
    status:ready
    type:enhancement
    priority:medium
    area:models
    area:inference
    status:in-progress
    status:review
    status:done
    and removed
    status:ready
    status:in-progress
    status:review
    on Jun 19, 2026
  2. added this to the 0.3 milestone on Jun 21, 2026
  3. self-assigned this
    on Jun 21, 2026
  4. added a commit that references this issue on Jun 23, 2026
    16102e9
  5. added a commit that references this issue on Oct 27, 2026
    66ee3ee
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

area:inferencearea:modelspriority:mediumstatus:donetype:enhancement

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions