<jupyter_start><jupyter_text>TTS with Tacotron2 + Waveflow<jupyter_code>import numpy as np
import paddle
from matplotlib import pyplot as plt
from IPython import display as ipd
%matplotlib inline

from paddlespeech.t2s.utils import display
from paddlespeech.t2s.utils import layer_tools
paddle.set_device("gpu:0")

import sys
sys.path.append("../..")
import examples<jupyter_output><empty_output><jupyter_text>Tacotron2: synthesizer modelTacotron2 is used here as a phonemes to spectrogram model. Here we will use an alternative config. In this config, the tacotron2 model does not have a binary classifier to predict whether the generation should stop.Instead, the peak position is used as the criterion. When the peak position of the attention reaches the end of the encoder outputs, it implies that the content is exhausted. So we stop the generated after 10 frames.<jupyter_code>from paddlespeech.t2s.models.tacotron2 import Tacotron2
from paddlespeech.t2s.frontend import EnglishCharacter
from examples.tacotron2 import config as tacotron2_config
synthesizer_config = tacotron2_config.get_cfg_defaults()
synthesizer_config.merge_from_file("configs/alternative.yaml")
print(synthesizer_config)
frontend = EnglishCharacter()
model = Tacotron2.from_pretrained(
    synthesizer_config, "../../pretrained/tacotron2/tacotron2_ljspeech_ckpt_0.3_alternative/step-50000")
model.eval()
sentence = "Life was like a box of chocolates, you never know what you're gonna get." 
sentence = paddle.to_tensor(frontend(sentence)).unsqueeze(0)

with paddle.no_grad():
    outputs = model.infer(sentence)
mel_output = outputs["mel_outputs_postnet"][0].numpy().T
alignment = outputs["alignments"][0].numpy().T
fig = display.plot_alignment(alignment)<jupyter_output><empty_output><jupyter_text>WaveFlow: vocoder modelGenerated spectrogram is converted to raw audio using a pretrained waveflow model.<jupyter_code>from paddlespeech.t2s.models.waveflow import ConditionalWaveFlow
from examples.waveflow import config as waveflow_config
vocoder_config = waveflow_config.get_cfg_defaults()
print(vocoder_config)
vocoder = ConditionalWaveFlow.from_pretrained(
    vocoder_config, 
    "../../pretrained/waveflow/waveflow_ljspeech_ckpt_0.3/step-2000000")
layer_tools.recursively_remove_weight_norm(vocoder)
vocoder.eval()
audio = vocoder.infer(paddle.transpose(outputs["mel_outputs_postnet"], [0, 2, 1]))
wav = audio[0].numpy()
ipd.Audio(wav, rate=22050)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.08699186991869919, 'fraction_numerical': 0.01951219512195122, 'mean_word_length': 6.887820512820513, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '3', 'dir': 'jupyter-structured-clean-dedup', 'id': '197861', 'license': 'Apache-2.0', 'n_tokens_mistral': 847, 'n_tokens_neox': 793, 'n_words': 203, 'path': 'paddlespeech/t2s/exps/tacotron2/synthesize.ipynb', 'repo_name': 'JamesLim-sy/PaddleSpeech', 'size': '2460'}