File size: 1,984 Bytes
6ab9933
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
50962bd
 
 
 
 
 
 
6ab9933
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#!/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()