MCPcopy Create free account
hub / github.com/MoonInTheRiver/DiffSinger / save_result

Method save_result

tasks/tts/fs2.py:449–477  ·  view source on GitHub ↗
(wav_out, mel, prefix, item_name, text, gen_dir, str_phs=None, mel2ph=None)

Source from the content-addressed store, hash-verified

447
448 @staticmethod
449 def save_result(wav_out, mel, prefix, item_name, text, gen_dir, str_phs=None, mel2ph=None):
450 base_fn = f'[{item_name}][{prefix}]'
451
452 if text is not None:
453 base_fn += text
454 np.save(os.path.join(hparams['work_dir'], f'{prefix}_mels_npy', item_name), mel)
455 audio.save_wav(wav_out, f'{gen_dir}/wavs/{base_fn}.wav', hparams['audio_sample_rate'],
456 norm=hparams['out_wav_norm'])
457 fig = plt.figure(figsize=(14, 10))
458 spec_vmin = hparams['mel_vmin']
459 spec_vmax = hparams['mel_vmax']
460 heatmap = plt.pcolor(mel.T, vmin=spec_vmin, vmax=spec_vmax)
461 fig.colorbar(heatmap)
462 f0, _ = get_pitch(wav_out, mel, hparams)
463 f0 = (f0 - 100) / (800 - 100) * 80 * (f0 > 0)
464 plt.plot(f0, c='white', linewidth=1, alpha=0.6)
465 if mel2ph is not None and str_phs is not None:
466 decoded_txt = str_phs.split(" ")
467 dur = mel2ph_to_dur(torch.LongTensor(mel2ph)[None, :], len(decoded_txt))[0].numpy()
468 dur = [0] + list(np.cumsum(dur))
469 for i in range(len(dur) - 1):
470 shift = (i % 20) + 1
471 plt.text(dur[i], shift, decoded_txt[i])
472 plt.hlines(shift, dur[i], dur[i + 1], colors='b' if decoded_txt[i] != '|' else 'black')
473 plt.vlines(dur[i], 0, 5, colors='b' if decoded_txt[i] != '|' else 'black',
474 alpha=1, linewidth=1)
475 plt.tight_layout()
476 plt.savefig(f'{gen_dir}/plot/{base_fn}.png', format='png', dpi=1000)
477 plt.close(fig)
478
479 ##############
480 # utils

Callers

nothing calls this directly

Calls 2

get_pitchFunction · 0.90
mel2ph_to_durFunction · 0.90

Tested by

no test coverage detected