The voice library lets you save voice profiles and reuse them across requests
using the clone:ProfileName voice prefix. The server loads the reference
audio from disk, computes the speaker embedding, and caches it — saving roughly
0.7 s per repeated request compared to uploading the raw audio each time.
$VOICE_LIBRARY_DIR/ # default: ./voice_library (override with env var)
└── profiles/
├── alice/
│ ├── meta.json
│ └── reference.wav
└── bob/
├── meta.json
└── reference.wav
Set the VOICE_LIBRARY_DIR environment variable to point anywhere on the filesystem.
{
"name": "Alice",
"profile_id": "alice",
"ref_audio_filename": "reference.wav",
"ref_text": "Optional verbatim transcript of the reference audio.",
"x_vector_only_mode": false,
"language": "English"
}| Field | Required | Description |
|---|---|---|
name |
✓ | Display name and lookup key (case-insensitive). |
profile_id |
— | Optional alternate lookup key (exact match). |
ref_audio_filename |
✓ | Filename of the reference WAV/MP3 inside the profile directory. |
ref_text |
— | Transcript of the reference audio. Required for ICL mode (x_vector_only_mode: false). |
x_vector_only_mode |
— | true → use speaker-embedding only (no transcript needed). false → ICL mode (higher quality, requires ref_text). Default: false. |
language |
— | Language hint used when the request does not specify one (e.g. "English", "German"). Default: "Auto". |
Pass the profile name with the clone: prefix as the voice field in a
standard /v1/audio/speech request:
# Non-streaming — returns MP3
curl -X POST http://localhost:8880/v1/audio/speech \
-H "Content-Type: application/json" \
-d '{"input": "Hello!", "voice": "clone:Alice", "model": "tts-1"}' \
--output speech.mp3
# Real-time streaming — returns raw PCM (requires optimized backend)
curl -X POST http://localhost:8880/v1/audio/speech \
-H "Content-Type: application/json" \
-d '{
"input": "Hello!",
"voice": "clone:Alice",
"model": "tts-1",
"stream": true,
"response_format": "pcm"
}' \
--output speech.pcmOr with the OpenAI Python SDK:
from openai import OpenAI
client = OpenAI(base_url="http://localhost:8880/v1", api_key="not-needed")
response = client.audio.speech.create(
model="tts-1",
voice="clone:Alice",
input="This is Alice speaking.",
)
response.stream_to_file("alice.mp3")Saved profiles appear in the /v1/voices (or /v1/audio/voices) endpoint
response under the voices array, with their id prefixed by clone::
{
"voices": [
{"id": "clone:Alice", "name": "clone:Alice", "description": "Voice library profile: Alice"},
...
]
}- The reference audio file is read and decoded once per server process and
then kept in memory (
_ref_audio_cache). - The speaker embedding (voice prompt) is computed on first use and then
cached for the lifetime of the loaded model (
_voice_prompt_cacheinside the backend). If the model is swapped out (e.g. CustomVoice → Base), the voice prompt cache is cleared and rebuilt on the next request.
- Voice library profiles require the Base model.
- When using the optimized backend (
TTS_BACKEND=optimized), the server automatically switches to the Base model when it receives aclone:request. - For other backends,
clone:profiles only work if a Base model is already loaded/selected; no automatic model switch is performed.
- When using the optimized backend (
- If
x_vector_only_modeisfalse(ICL mode) andref_textis empty, the request will fail with amissing_ref_texterror. - The
VOICE_LIBRARY_DIRenv var must be set consistently between the API server and any tools (e.g. Gradio Voice Studio) that write profiles.