2018-11-02 15:13:51 +00:00
|
|
|
import io
|
|
|
|
import time
|
|
|
|
import librosa
|
|
|
|
import torch
|
|
|
|
import numpy as np
|
2019-01-01 19:09:34 +00:00
|
|
|
from .text import text_to_sequence, phoneme_to_sequence
|
2018-11-02 15:13:51 +00:00
|
|
|
from .visual import visualize
|
|
|
|
from matplotlib import pylab as plt
|
|
|
|
|
|
|
|
|
|
|
|
def synthesis(m, s, CONFIG, use_cuda, ap):
|
|
|
|
""" Given the text, synthesising the audio """
|
|
|
|
text_cleaner = [CONFIG.text_cleaner]
|
2019-01-16 14:53:07 +00:00
|
|
|
# print(phoneme_to_sequence(s, text_cleaner))s
|
2019-01-02 10:16:36 +00:00
|
|
|
# print(sequence_to_phoneme(phoneme_to_sequence(s, text_cleaner)))
|
2019-01-16 14:53:07 +00:00
|
|
|
if CONFIG.use_phonemes:
|
|
|
|
seq = np.asarray(
|
|
|
|
phoneme_to_sequence(s, text_cleaner, CONFIG.phoneme_language),
|
|
|
|
dtype=np.int32)
|
|
|
|
else:
|
|
|
|
seq = np.asarray(text_to_sequence(s, text_cleaner), dtype=np.int32)
|
2018-11-02 15:13:51 +00:00
|
|
|
chars_var = torch.from_numpy(seq).unsqueeze(0)
|
|
|
|
if use_cuda:
|
|
|
|
chars_var = chars_var.cuda()
|
2019-01-16 14:53:07 +00:00
|
|
|
mel_spec, linear_spec, alignments, stop_tokens = m.forward(
|
|
|
|
chars_var.long())
|
2018-11-02 15:13:51 +00:00
|
|
|
linear_spec = linear_spec[0].data.cpu().numpy()
|
2018-11-13 11:10:40 +00:00
|
|
|
mel_spec = mel_spec[0].data.cpu().numpy()
|
2018-11-02 15:13:51 +00:00
|
|
|
alignment = alignments[0].cpu().data.numpy()
|
|
|
|
wav = ap.inv_spectrogram(linear_spec.T)
|
2019-01-06 17:10:54 +00:00
|
|
|
wav = wav[:ap.find_endpoint(wav)]
|
2018-11-13 11:10:40 +00:00
|
|
|
return wav, alignment, linear_spec, mel_spec, stop_tokens
|