Views
No views yet
pip install TensorFlowTTS1import numpy as np
2import soundfile as sf
3import yaml
4import IPython.display as ipd
5
6import tensorflow as tf
7
8from tensorflow_tts.inference import AutoProcessor
9from tensorflow_tts.inference import TFAutoModel
10
11processor = AutoProcessor.from_pretrained("MarcNg/fastspeech2-vi-infore")
12fastspeech2 = TFAutoModel.from_pretrained("MarcNg/fastspeech2-vi-infore")
13
14text = "xin chào đây là một ví dụ về chuyển đổi văn bản thành giọng nói"
15
16input_ids = processor.text_to_sequence(text)
17
18mel_before, mel_after, duration_outputs, _, _ = fastspeech2.inference(
19 input_ids=tf.expand_dims(tf.convert_to_tensor(input_ids, dtype=tf.int32), 0),
20 speaker_ids=tf.convert_to_tensor([0], dtype=tf.int32),
21 speed_ratios=tf.convert_to_tensor([1.0], dtype=tf.float32),
22 f0_ratios =tf.convert_to_tensor([1.0], dtype=tf.float32),
23 energy_ratios =tf.convert_to_tensor([1.0], dtype=tf.float32),
24)1mb_melgan = TFAutoModel.from_pretrained("tensorspeech/tts-mb_melgan-ljspeech-en")
2
3audio_before = mb_melgan.inference(mel_before)[0, :, 0]
4audio_after = mb_melgan.inference(mel_after)[0, :, 0]
5
6sf.write("audio_before.wav", audio_before, 22050, "PCM_16")
7sf.write("audio_after.wav", audio_after, 22050, "PCM_16")
8
9ipd.Audio('audio_after.wav')@misc{ren2021fastspeech,
title={FastSpeech 2: Fast and High-Quality End-to-End Text to Speech},
author={Yi Ren and Chenxu Hu and Xu Tan and Tao Qin and Sheng Zhao and Zhou Zhao and Tie-Yan Liu},
year={2021},
eprint={2006.04558},
archivePrefix={arXiv},
primaryClass={eess.AS}
}