#!/usr/bin/env python3 """Rebuild the Jarvis LVM style vectors from Kokoro's built-in voices. The package ships the resulting .npy files. This script documents exactly how they were derived and can be rerun after a Kokoro voices update: python scripts/build_styles.py --voices voices/voices-v1.0.bin --out voices """ from __future__ import annotations import argparse from pathlib import Path import numpy as np RECIPES = { # Headline preset since v1.1: more chest resonance than classic (a heavier # lewis base) while keeping a little george crispness on the consonants. "jarvis-prime": { "bm_lewis": 0.55, "bm_daniel": 0.30, "bm_george": 0.15, }, "jarvis-classic": { "bm_george": 0.25, "bm_daniel": 0.35, "bm_lewis": 0.40, }, "jarvis-deep": { "bm_lewis": 0.50, "bm_daniel": 0.50, }, } def build(voices_path: Path, out_dir: Path) -> None: source = np.load(voices_path) out_dir.mkdir(parents=True, exist_ok=True) for name, weights in RECIPES.items(): missing = set(weights) - set(source.files) if missing: raise SystemExit(f"{voices_path} is missing: {sorted(missing)}") total = sum(weights.values()) style = sum( source[voice] * (weight / total) for voice, weight in weights.items() ).astype(np.float32) destination = out_dir / f"{name}.npy" np.save(destination, style) print( f"{destination} shape={style.shape} dtype={style.dtype} " f"weights={weights}" ) def main() -> None: parser = argparse.ArgumentParser(description=__doc__) parser.add_argument( "--voices", type=Path, default=Path("voices/voices-v1.0.bin"), ) parser.add_argument("--out", type=Path, default=Path("voices")) args = parser.parse_args() build(args.voices, args.out) if __name__ == "__main__": main()