forked from acids-ircam/RAVE
-
Notifications
You must be signed in to change notification settings - Fork 0
/
generation.py
37 lines (26 loc) · 895 Bytes
/
generation.py
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
import torch
import torch.nn as nn
torch.set_grad_enabled(False)
from effortless_config import Config
from rave.core import search_for_run
from prior import Prior
import math
import soundfile as sf
class args(Config):
PRIOR_CKPT = None # path to prior .ckpt file
EXPORTED_RAVE = None # path to .ts file
LENGTH = 10 # in second
OUT_PATH = "unconditional.wav"
args.parse_args()
args.PRIOR_CKPT = search_for_run(args.PRIOR_CKPT)
prior = Prior.load_from_checkpoint(args.PRIOR_CKPT).eval()
rave = torch.jit.load(args.EXPORTED_RAVE).eval()
sr = int(rave.sampling_rate.item())
n_samples = math.ceil(sr * args.LENGTH)
x = torch.zeros(1, 1, n_samples)
z = rave.encode(x).zero_()
z = prior.quantized_normal.encode(z)
z = prior.generate(z)
z = prior.diagonal_shift.inverse(prior.quantized_normal.decode(z))
y = rave.decode(z).reshape(-1).numpy()
sf.write(args.OUT_PATH, y, sr)