gen_wavernn.py 985 B

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