Views
No views yet
1git clone https://github.com/speechbrain/speechbrain.git
2cd speechbrain
3pip install -r requirements.txt
4pip install --editable . 1import torchaudio
2from speechbrain.inference.TTS import FastSpeech2
3from speechbrain.inference.vocoders import HIFIGAN
4
5# Intialize TTS (tacotron2) and Vocoder (HiFIGAN)
6fastspeech2 = FastSpeech2.from_hparams(source="speechbrain/tts-fastspeech2-ljspeech", savedir="pretrained_models/tts-fastspeech2-ljspeech")
7hifi_gan = HIFIGAN.from_hparams(source="speechbrain/tts-hifigan-ljspeech", savedir="pretrained_models/tts-hifigan-ljspeech")
8
9# Run TTS with text input
10input_text = "were the leaders in this luckless change; though our own Baskerville; who was at work some years before them; went much on the same lines;"
11
12mel_output, durations, pitch, energy = fastspeech2.encode_text(
13 [input_text],
14 pace=1.0, # scale up/down the speed
15 pitch_rate=1.0, # scale up/down the pitch
16 energy_rate=1.0, # scale up/down the energy
17)
18
19# Running Vocoder (spectrogram-to-waveform)
20waveforms = hifi_gan.decode_batch(mel_output)
21
22# Save the waverform
23torchaudio.save('example_TTS_input_text.wav', waveforms.squeeze(1), 22050)
24
25
26# Run TTS with phoneme input
27input_phonemes = ['W', 'ER', 'DH', 'AH', 'L', 'IY', 'D', 'ER', 'Z', 'IH', 'N', 'DH', 'IH', 'S', 'L', 'AH', 'K', 'L', 'AH', 'S', 'CH', 'EY', 'N', 'JH', 'spn', 'DH', 'OW', 'AW', 'ER', 'OW', 'N', 'B', 'AE', 'S', 'K', 'ER', 'V', 'IH', 'L', 'spn', 'HH', 'UW', 'W', 'AA', 'Z', 'AE', 'T', 'W', 'ER', 'K', 'S', 'AH', 'M', 'Y', 'IH', 'R', 'Z', 'B', 'IH', 'F', 'AO', 'R', 'DH', 'EH', 'M', 'spn', 'W', 'EH', 'N', 'T', 'M', 'AH', 'CH', 'AA', 'N', 'DH', 'AH', 'S', 'EY', 'M', 'L', 'AY', 'N', 'Z', 'spn']
28mel_output, durations, pitch, energy = fastspeech2.encode_phoneme(
29 [input_phonemes],
30 pace=1.0, # scale up/down the speed
31 pitch_rate=1.0, # scale up/down the pitch
32 energy_rate=1.0, # scale up/down the energy
33)
34
35# Running Vocoder (spectrogram-to-waveform)
36waveforms = hifi_gan.decode_batch(mel_output)
37
38# Save the waverform
39torchaudio.save('example_TTS_input_phoneme.wav', waveforms.squeeze(1), 22050)1from speechbrain.inference.TTS import FastSpeech2
2fastspeech2 = FastSpeech2.from_hparams(source="speechbrain/tts-fastspeech2-ljspeech", savedir="pretrained_models/tts-fastspeech2-ljspeech")
3items = [
4 "A quick brown fox jumped over the lazy dog",
5 "How much wood would a woodchuck chuck?",
6 "Never odd or even"
7 ]
8mel_outputs, durations, pitch, energy = fastspeech2.encode_text(
9 items,
10 pace=1.0, # scale up/down the speed
11 pitch_rate=1.0, # scale up/down the pitch
12 energy_rate=1.0, # scale up/down the energy
13)run_opts={"device":"cuda"} when calling the from_hparams method.git clone https://github.com/speechbrain/speechbrain/1cd speechbrain
2pip install -r requirements.txt
3pip install -e .1cd recipes/LJSpeech/TTS/fastspeech2/
2python train.py --device=cuda:0 --max_grad_norm=1.0 --data_folder=/your_folder/LJSpeech-1.1 hparams/train.yaml1@misc{speechbrain,
2 title={{SpeechBrain}: A General-Purpose Speech Toolkit},
3 author={Mirco Ravanelli and Titouan Parcollet and Peter Plantinga and Aku Rouhe and Samuele Cornell and Loren Lugosch and Cem Subakan and Nauman Dawalatabad and Abdelwahab Heba and Jianyuan Zhong and Ju-Chieh Chou and Sung-Lin Yeh and Szu-Wei Fu and Chien-Feng Liao and Elena Rastorgueva and François Grondin and William Aris and Hwidong Na and Yan Gao and Renato De Mori and Yoshua Bengio},
4 year={2021},
5 eprint={2106.04624},
6 archivePrefix={arXiv},
7 primaryClass={eess.AS},
8 note={arXiv:2106.04624}
9}