From d23e29ea1f1d9bafec387a604de3069a3cfd00e4 Mon Sep 17 00:00:00 2001 From: Thomas Werkmeister Date: Tue, 2 Jul 2019 14:40:01 +0200 Subject: [PATCH] extracted id to torch code --- utils/synthesis.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/utils/synthesis.py b/utils/synthesis.py index b0648d82..78ae365e 100644 --- a/utils/synthesis.py +++ b/utils/synthesis.py @@ -68,6 +68,13 @@ def inv_spectrogram(postnet_output, ap, CONFIG): return wav +def id_to_torch(speaker_id): + if speaker_id is not None: + speaker_id = np.asarray(speaker_id) + speaker_id = torch.from_numpy(speaker_id).unsqueeze(0) + return speaker_id + + def synthesis(model, text, CONFIG, @@ -100,9 +107,7 @@ def synthesis(model, style_mel = compute_style_mel(style_wav, ap, use_cuda) # preprocess the given text inputs = text_to_seqvec(text, CONFIG, use_cuda) - if speaker_id is not None: - speaker_id = np.asarray(speaker_id) - speaker_id = torch.from_numpy(speaker_id).unsqueeze(0) + speaker_id = id_to_torch(speaker_id) if use_cuda: speaker_id.cuda() # synthesize voice @@ -116,4 +121,4 @@ def synthesis(model, # trim silence if trim_silence: wav = trim_silence(wav) - return wav, alignment, decoder_output, postnet_output, stop_tokens \ No newline at end of file + return wav, alignment, decoder_output, postnet_output, stop_tokens