<jupyter_start><jupyter_text>Transformer TTS: A Text-to-Speech Transformer in TensorFlow 2      Audio synthesis with Autoregressive Transformer TTS and MelGAN Vocoder Autoregressive Model<jupyter_code># Clone the Transformer TTS and MelGAN repos
!git clone https://github.com/as-ideas/TransformerTTS.git
!git clone https://github.com/seungwonpark/melgan.git
# Install requirements
!apt-get install -y espeak
!pip install -r TransformerTTS/requirements.txt
# Download the pre-trained weights
! wget https://public-asai-dl-models.s3.eu-central-1.amazonaws.com/TransformerTTS/ljspeech_melgan_autoregressive_transformer.zip
! unzip ljspeech_melgan_autoregressive_transformer.zip
!cd TransformerTTS/; git checkout 1c1cb03
# Set up the paths
from pathlib import Path
MelGAN_path = 'melgan/'
TTS_path = 'TransformerTTS/'
config_path = Path('ljspeech_melgan_autoregressive_transformer/melgan')

import sys
sys.path.append(TTS_path)
# Load pretrained models
from utils.config_manager import ConfigManager
from utils.audio import Audio

import IPython.display as ipd

config_loader = ConfigManager(str(config_path), model_kind='autoregressive')
audio = Audio(config_loader.config)
model = config_loader.load_model(str(config_path / 'autoregressive_weights/ckpt-90'))
# Synthesize text
sentence = 'Scientists at the CERN laboratory, say that they have discovered a new particle.'
out = model.predict(sentence)
# Convert spectrogram to wav (with griffin lim)
wav = audio.reconstruct_waveform(out['mel'].numpy().T)
ipd.display(ipd.Audio(wav, rate=config_loader.config['sampling_rate']))<jupyter_output><empty_output><jupyter_text>MelGAN<jupyter_code># Do some sys cleaning
sys.path.remove(TTS_path)
sys.modules.pop('model')
sys.path.append(MelGAN_path)
import torch
import numpy as np

vocoder = torch.hub.load('seungwonpark/melgan', 'melgan')
vocoder.eval()

mel = torch.tensor(out['mel'].numpy().T[np.newaxis,:,:])
if torch.cuda.is_available():
    vocoder = vocoder.cuda()
    mel = mel.cuda()

with torch.no_grad():
    audio = vocoder.inference(mel)
# Display audio
ipd.display(ipd.Audio(audio.cpu().numpy(), rate=22050))<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.11152589827344844, 'fraction_numerical': 0.006532897806812879, 'mean_word_length': 6.496503496503497, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 3, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '2', 'dir': 'jupyter-structured-clean-dedup', 'id': '206816', 'license': 'MIT', 'n_tokens_mistral': 764, 'n_tokens_neox': 734, 'n_words': 157, 'path': 'notebooks/synthesize_autoregressive_melgan.ipynb', 'repo_name': 'koder-abc123/TransformerTTS', 'size': '2143'}