Views
No views yet
pip install TensorFlowTTS1import soundfile as sf
2import numpy as np
3
4import tensorflow as tf
5
6from tensorflow_tts.inference import AutoProcessor
7from tensorflow_tts.inference import TFAutoModel
8
9processor = AutoProcessor.from_pretrained("tensorspeech/tts-tacotron2-baker-ch")
10tacotron2 = TFAutoModel.from_pretrained("tensorspeech/tts-tacotron2-baker-ch")
11mb_melgan = TFAutoModel.from_pretrained("tensorspeech/tts-mb_melgan-baker-ch")
12
13text = "这是一个开源的端到端中文语音合成系统"
14
15input_ids = processor.text_to_sequence(text, inference=True)
16
17# tacotron2 inference (text-to-mel)
18decoder_output, mel_outputs, stop_token_prediction, alignment_history = tacotron2.inference(
19 input_ids=tf.expand_dims(tf.convert_to_tensor(input_ids, dtype=tf.int32), 0),
20 input_lengths=tf.convert_to_tensor([len(input_ids)], tf.int32),
21 speaker_ids=tf.convert_to_tensor([0], dtype=tf.int32),
22)
23
24# melgan inference (mel-to-wav)
25audio = mb_melgan.inference(mel_outputs)[0, :, 0]
26
27# save to file
28sf.write('./audio.wav', audio, 22050, "PCM_16")@misc{yang2020multiband,
title={Multi-band MelGAN: Faster Waveform Generation for High-Quality Text-to-Speech},
author={Geng Yang and Shan Yang and Kai Liu and Peng Fang and Wei Chen and Lei Xie},
year={2020},
eprint={2005.05106},
archivePrefix={arXiv},
primaryClass={cs.SD}
}@misc{TFTTS,
author = {Minh Nguyen, Alejandro Miguel Velasquez, Erogol, Kuan Chen, Dawid Kobus, Takuya Ebata,
Trinh Le and Yunchao He},
title = {TensorflowTTS},
year = {2020},
publisher = {GitHub},
journal = {GitHub repository},
howpublished = {\\url{https://github.com/TensorSpeech/TensorFlowTTS}},
}