gepard-onnx / scripts /words_ref.py
matthiastl's picture
gepard-1.0 for CPUs (ONNX)
2d4936d
Raw History Blame Contribute Delete
828 Bytes
import sys; from pathlib import Path
sys.path.insert(0, str(Path(__file__).parent))
import numpy as np, torch, soundfile as sf, codec, reference as R, texts
half = np.array([4, 3, 3, 3] * 8, np.float32); r, c = R.Reference(), codec.load()
for base in map(int, sys.argv[1:]):
out = R.ROOT / "runs" / f"words-ref-{base}"; out.mkdir(parents=True, exist_ok=True); n = 0
for i, t in enumerate(texts.ALL):
if (out / f"{i:03d}.wav").exists(): continue
codes = r.generate(t, seed=base + i, max_frames=600)
with torch.no_grad(): a, _ = c.decode_audio(inputs=torch.from_numpy((codes.astype(np.float32) - half) / half).T[None], input_len=torch.tensor([len(codes)]))
sf.write(out / f"{i:03d}.wav", a[0].numpy(), 22050); np.save(out / f"{i:03d}.npy", codes)
print("ref", base, "done", flush=True)