This repository has been archived on 2025-08-26. You can view files and clone it, but cannot push or open issues or pull requests.
Files
enginex_bi_series-sherpa-onnx/scripts/kokoro/v0.19/generate_voices_bin.py
Fangjun Kuang 59d118c256 Refactor kokoro export (#2302)
- generate samples for https://k2-fsa.github.io/sherpa/onnx/tts/all/
- provide int8 model for kokoro v0.19 kokoro-int8-en-v0_19.tar.bz2
2025-06-18 20:30:10 +08:00

43 lines
905 B
Python
Executable File

#!/usr/bin/env python3
# Copyright 2025 Xiaomi Corp. (authors: Fangjun Kuang)
import torch
from pathlib import Path
id2speaker = {
0: "af",
1: "af_bella",
2: "af_nicole",
3: "af_sarah",
4: "af_sky",
5: "am_adam",
6: "am_michael",
7: "bf_emma",
8: "bf_isabella",
9: "bm_george",
10: "bm_lewis",
}
speaker2id = {speaker: idx for idx, speaker in id2speaker.items()}
def main():
if Path("./voices.bin").is_file():
print("./voices.bin exists - skip")
return
with open("voices.bin", "wb") as f:
for _, speaker in id2speaker.items():
m = torch.load(
f"kLegacy/v0.19/voices/{speaker}.pt",
weights_only=True,
map_location="cpu",
).numpy()
# m.shape (511, 1, 256)
f.write(m.tobytes())
if __name__ == "__main__":
main()