MockingBird/vocoder/wavernn/gen_wavernn.py
2021-09-12 17:33:39 +08:00

32 lines
1001 B
Python

from vocoder.wavernn.models.fatchord_version import WaveRNN
from vocoder.wavernn.audio import *
def gen_testset(model: WaveRNN, test_set, samples, batched, target, overlap, save_path):
k = model.get_step() // 1000
for i, (m, x) in enumerate(test_set, 1):
if i > samples:
break
print('\n| Generating: %i/%i' % (i, samples))
x = x[0].numpy()
bits = 16 if hp.voc_mode == 'MOL' else hp.bits
if hp.mu_law and hp.voc_mode != 'MOL' :
x = decode_mu_law(x, 2**bits, from_labels=True)
else :
x = label_2_float(x, bits)
save_wav(x, save_path.joinpath("%dk_steps_%d_target.wav" % (k, i)))
batch_str = "gen_batched_target%d_overlap%d" % (target, overlap) if batched else \
"gen_not_batched"
save_str = save_path.joinpath("%dk_steps_%d_%s.wav" % (k, i, batch_str))
wav = model.generate(m, batched, target, overlap, hp.mu_law)
save_wav(wav, save_str)