This project provides a voice cloning Python application (XTTS-v2) that compiles to an executable. It is designed to be generic, allowing for different "agents" (voices) to be used for text-to-speech generation.
It automatically uses the GPU when a healthy CUDA device with enough free VRAM is present (quick VRAM + benchmark probe at startup) and falls back to CPU otherwise. Per-agent conditioning latents are cached to disk (latent_cache/*.pt) so startup is instant and no voice re-conditioning happens per request.
config.json drives the build: the executable name and the version stamped into the exe (voice_server.spec generates file_version.txt from it).
{
"executable_name": "valorantNarrator-agentVoices.exe",
"version": "1.5.0.0",
"company_name": "ValorantNarrator",
"product_name": "ValorantNarrator",
"file_description": "ValorantNarrator Agent Voices",
"copyright": "Copyright (C) 2025"
}- Agents: Place your reference audio files (mp3) in the
agentsfolder. The filename (without extension) will be the agent's name. - Running: Run the generated executable or the
voice_server.pyscript, server runs at localhost:5005 - API: The server exposes
POST /speakandGET /health.- Body (only
agentandtextare required):{ "agent": "agent_name", "text": "Text to speak", "language": "en", "speed": 1.0, "temperature": 0.65, "top_p": 0.80, "top_k": 50, "repetition_penalty": 10.0, "length_penalty": 1.0 } - Returns
audio/mpeg(mp3).GET /healthreports device, cached agents, and settings.
- Body (only
- Reference audio (
agents/<name>.mp3) is cleaned with ffmpeg (highpass/lowpass, silence trim, loudness) into short clips, then conditioning latents are computed and cached tolatent_cache/<name>.<key>.pt. - The cache is bundled into the exe (
voice_server.spec), so a shipped build starts instantly with all voices ready. - Querying an agent with no mp3 and no cached
.ptreturns HTTP 404. If the mp3 is present but the.ptisn't, the latent is computed on first use and cached. - Add/update an agent: drop
agents/<name>.mp3, runpython precompute_latents.py(see below) to generate the.pt, bumpconfig.jsonversion, rebuild. If you ship theagents/folder alongside the exe, a new agent can also be added by shipping just its mp3 (the server computes the latent on first request).
python precompute_latents.py # compute any missing latents
python precompute_latents.py --force # recompute all
python precompute_latents.py --list # show agents + cache status| Variable | Default | Effect |
|---|---|---|
XTTS_WARMUP |
1 |
Run a warmup inference at startup so the first /speak is fast. 0 for faster startup, slower first call. |
XTTS_PRELOAD_CACHED_VOICES |
1 |
Load all cached .pt latents into memory at startup. |
XTTS_PRELOAD_VOICES |
0 |
Compute latents for every agent at startup (only needed with no cache). |
XTTS_PREPARE_REFERENCES |
1 |
Clean/segment reference audio before conditioning. |
XTTS_TEMPERATURE, XTTS_TOP_P, XTTS_TOP_K |
0.65 / 0.80 / 50 |
Generation sampling defaults. |
XTTS_MAX_TEXT_CHARS |
900 |
Reject overly long /speak text. |
- GPU/CPU auto: uses CUDA when a healthy GPU with enough free VRAM is available, else CPU. Short callouts run ~400–600 ms warm on a laptop RTX 3050; CPU is several seconds per call.
- Size: the CPU build (
requirements.txtinstalls CPU torch) is small (~357 MB). A GPU build needs a CUDA torch env (pip install torch==2.5.1 ... --index-url https://download.pytorch.org/whl/cu121); it is much larger (~2.7 GB, exceeds GitHub's 2 GB release-asset limit — distribute via Hugging Face).
Simply run the automated build script, which will create the virtual environment, install dependencies, and build the executable:
run_cmd.batIf you prefer to set up manually:
-
Create Virtual Environment: Create a Python 3.11 virtual environment named
env311:python -m venv env311
-
Activate Environment:
env311\Scripts\activate.bat
-
Install Dependencies:
pip install -r requirements.txt
-
Build the Executable:
python -O -m PyInstaller voice_server.spec
This command uses PyInstaller with the voice_server.spec file, which reads configuration from config.json.
This project is licensed under the MIT License - see the LICENSE file for details.