kokoro: persist custom voices across container recreate
Wrapper only enumerates one voice directory (settings.voices_dir, default /app/api/src/voices/v1_0 — inside the container's writable layer, not bind-mounted). Override via VOICES_DIR=/app/user_voices (host bind mount) and add a command shim that cp -r's built-ins from the in-image v1_0 into user_voices on every start. Built-ins re-seed fresh from the image (so upgrades that add voices propagate); custom .pt files in user_voices are preserved (cp -r is additive). Also adds scripts/blend_kokoro_voice.py + a playbook around it that mirrors the wrapper's request-time voice="a(w)+b(w)" math but writes the result as a named .pt to user_voices, making it discoverable via GET /v1/audio/voices and persistent across recreate. Defaults to athena = af_bella(2)+af_aoede(1) normalized.
This commit is contained in:
+30
-4
@@ -59,10 +59,36 @@ Supported `response_format`: `mp3 | wav | opus | flac | pcm`.
|
||||
Discoverable via `GET /v1/audio/voices` — naming convention is
|
||||
`<lang_code><gender_letter>_<name>` (e.g. `af_bella`, `am_adam`,
|
||||
`jf_alpha`, `zf_xiaobei`).
|
||||
- **Custom**: drop `.pt` voicepacks into `/worktank/kokoro/user_voices/`
|
||||
on the host. Wrapper auto-discovers them on next request (no
|
||||
restart). Training Kokoro voices is non-trivial — consult the
|
||||
hexgrad community for how-to.
|
||||
- **Custom blends**: weighted-average existing voicepacks into a new
|
||||
named voice using `playbooks/blend-kokoro-voice.yaml` (script:
|
||||
`scripts/blend_kokoro_voice.py`). Mirrors the wrapper's request-time
|
||||
`voice="a(w)+b(w)"` math but persists the result so it shows up in
|
||||
`/v1/audio/voices`. Example shipped: `athena = af_bella(2)+af_aoede(1)`
|
||||
normalized.
|
||||
|
||||
```bash
|
||||
scripts/elway irv-ml1 --playbook playbooks/blend-kokoro-voice.yaml \
|
||||
--var 'recipe=af_bella(1)+am_adam(1)' --var out_name=androgyne
|
||||
# add --var force=1 to overwrite an existing voice
|
||||
```
|
||||
|
||||
Persistence design: the wrapper enumerates exactly one directory
|
||||
(`VOICES_DIR`, default in-image `/app/api/src/voices/v1_0`).
|
||||
compose.yaml overrides `VOICES_DIR=/app/user_voices` (host bind
|
||||
mount `/worktank/kokoro/user_voices`) and adds a `command:` shim
|
||||
that `cp -r`'s the in-image built-ins into that dir on every
|
||||
container start. Result:
|
||||
* built-in voicepacks re-seed on each start, so image upgrades that
|
||||
add/change built-ins propagate automatically
|
||||
* custom blends written by the script live on the host bind mount —
|
||||
survive `docker restart`, `up --force-recreate`, image upgrade,
|
||||
and host reboot
|
||||
* one-time prereq: the host dir must be chowned to `1001:1001`
|
||||
(uid of `appuser` inside the container) so the shim's cp can
|
||||
write — handled by `playbooks/deploy-kokoro.yaml`
|
||||
- **Cloned voices**: training a Kokoro voice from samples is non-
|
||||
trivial — consult the hexgrad community for how-to. For voice
|
||||
cloning use Chatterbox Turbo or IndexTTS-2 instead.
|
||||
|
||||
## Deploy
|
||||
|
||||
|
||||
@@ -27,18 +27,30 @@ services:
|
||||
# that env var harmlessly; the gpu variant honors it.
|
||||
ports:
|
||||
- "${KOKORO_BIND:-0.0.0.0}:${KOKORO_PORT}:8880"
|
||||
# Persistent custom voices: the wrapper only enumerates one voice
|
||||
# directory (controlled by VOICES_DIR; default in-image is
|
||||
# /app/api/src/voices/v1_0 which is NOT bind-mounted). We point it
|
||||
# at /app/user_voices (which IS host-bind-mounted) and seed the
|
||||
# built-ins into it on every container start. Custom voices written
|
||||
# by scripts/blend_kokoro_voice.py land directly on the host bind
|
||||
# mount and survive `up --force-recreate` and image upgrade.
|
||||
# `cp -r` (no `-n`): always refresh built-ins from the image so
|
||||
# upgrades that add/change built-in voicepacks propagate.
|
||||
# Custom-named .pt files in user_voices that don't exist in v1_0
|
||||
# are NOT touched (cp -r only copies entries from src).
|
||||
command: ["/bin/bash", "-c", "cp -r /app/api/src/voices/v1_0/. /app/user_voices/ && exec ./entrypoint.sh"]
|
||||
environment:
|
||||
- NVIDIA_VISIBLE_DEVICES=${KOKORO_GPU_DEVICES:-}
|
||||
- USE_GPU=${KOKORO_USE_GPU:-false}
|
||||
- API_LOG_LEVEL=${KOKORO_LOG_LEVEL:-INFO}
|
||||
- VOICES_DIR=/app/user_voices
|
||||
volumes:
|
||||
# Optional voice-overlay mount — drop a custom <name>.pt into the
|
||||
# host dir to make it available alongside the 60+ built-ins. The
|
||||
# image already ships voicepacks at this path, so the bind mount
|
||||
# SHADOWS them — only do this if you actually want to manage the
|
||||
# full voice library yourself. For most deploys, leave the mount
|
||||
# commented out and use the in-image voices.
|
||||
# - ${KOKORO_VOICES_DIR}:/app/api/src/voices/v1_0
|
||||
# Host-bind-mounted voice directory. Hosts both the image's
|
||||
# built-ins (re-seeded on each container start by the command
|
||||
# shim above) and any custom voices created via the blend
|
||||
# script. Must be chowned to uid 1001 (appuser inside the
|
||||
# container) on the host so the shim's cp can write — handled
|
||||
# by playbooks/deploy-kokoro.yaml.
|
||||
- ${KOKORO_USER_VOICES_DIR}:/app/user_voices
|
||||
healthcheck:
|
||||
# The image is python-based with curl available. /v1/audio/voices
|
||||
|
||||
Reference in New Issue
Block a user