gepard-onnx / scripts /words4_ref.py
matthiastl's picture
gepard-1.0 for CPUs (ONNX)
2d4936d
Raw History Blame Contribute Delete
1.02 kB
"""RULE-4: the original with voices, 4 seed sets x 600 new sentences."""
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, texts4
half = np.array([4, 3, 3, 3] * 8, np.float32); r, c = R.Reference(), codec.load()
pre = [torch.from_numpy(np.load(R.ROOT / f"runs/clips/{k}.npz")["prefix"])[None] for k in range(3)]
for base in (20000, 21000, 22000, 23000):
out = R.ROOT / "runs" / f"words4-ref-{base}"; out.mkdir(parents=True, exist_ok=True)
for i, t in enumerate(texts4.TEXTS):
if (out / f"{i:03d}.npy").exists(): continue
codes = r.generate(t, seed=base + i, max_frames=600, prefix=pre[i % 3])
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)