speechbrain
English
Tacotron2
zero-shot
multi-speaker-tts
pradnya-hf-dev commited on
Commit
c92e5df
1 Parent(s): e184c8d

Initial README.md

Browse files
Files changed (1) hide show
  1. README.md +118 -1
README.md CHANGED
@@ -1 +1,118 @@
1
- Work in progress
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Text-to-Speech (TTS) with Zero-Shot Multi-Speaker Tacotron2 trained on LibriTTS
2
+ ### Note: This is a work in progress
3
+
4
+ This repository provides all the necessary tools for Zero-Shot Multi-Speaker Text-to-Speech (TTS) with SpeechBrain using a variation of [Tacotron2](https://arxiv.org/abs/1712.05884), extended to incorporate speaker identity information when generating speech. It is pretrained on [LibriTTS](https://www.openslr.org/60/).
5
+
6
+ The pre-trained model takes as input a short text and a reference speech sample. The model output is a mel-spectrogram corresponding to the input text with the voice characteristics of the speaker from the reference speech. One can get the final waveform by applying a vocoder (e.g., HiFIGAN) on top of the generated mel-spectrogram.
7
+
8
+ ### Install SpeechBrain
9
+
10
+ ```
11
+ pip install speechbrain
12
+ ```
13
+
14
+ Please notice that we encourage you to read our tutorials and learn more about
15
+ [SpeechBrain](https://speechbrain.github.io).
16
+
17
+ ### Perform Text-to-Speech (TTS)
18
+
19
+ ```
20
+ import torchaudio
21
+ from speechbrain.pretrained import MSTacotron2
22
+ from speechbrain.pretrained import HIFIGAN
23
+
24
+ # Intialize TTS (mstacotron2) and Vocoder (HiFIGAN)
25
+ ms_tacotron2 = MSTacotron2.from_hparams(source="speechbrain/tts-mstacotron2-libritts", savedir="tmpdir_tts")
26
+ hifi_gan = HIFIGAN.from_hparams(source="speechbrain/tts-hifigan-libritts-22050Hz", savedir="tmpdir_vocoder")
27
+
28
+ # Required input
29
+ REFERENCE_SPEECH = "speech_sample.wav"
30
+ INPUT_TEXT = "Mary had a little lamb"
31
+
32
+ # Running the Zero-Shot Multi-Speaker Tacotron2 model to generate mel-spectrogram
33
+ mel_outputs, mel_lengths, alignments = ms_tacotron2.clone_voice(INPUT_TEXT, REFERENCE_SPEECH)
34
+
35
+ # Running Vocoder (spectrogram-to-waveform)
36
+ waveforms = hifi_gan.decode_batch(mel_outputs)
37
+
38
+ # Save the waverform
39
+ torchaudio.save("synthesized_sample.wav", waveforms.squeeze(1).cpu(), 22050)
40
+ ```
41
+
42
+ If you want to generate multiple sentences in one-shot, you can do it this way:
43
+ Note: The model internally reorders the input texts in the decreasing order of their lengths.
44
+
45
+ ```
46
+ import torchaudio
47
+ from speechbrain.pretrained import MSTacotron2
48
+ from speechbrain.pretrained import HIFIGAN
49
+
50
+ # Intialize TTS (mstacotron2) and Vocoder (HiFIGAN)
51
+ ms_tacotron2 = MSTacotron2.from_hparams(source="speechbrain/tts-mstacotron2-libritts", savedir="tmpdir_tts")
52
+ hifi_gan = HIFIGAN.from_hparams(source="speechbrain/tts-hifigan-libritts-22050Hz", savedir="tmpdir_vocoder")
53
+
54
+ # Required input
55
+ REFERENCE_SPEECH = "speech_sample.wav"
56
+ INPUT_TEXT = ["Welcome to the demo", "Convert text to speech"]
57
+
58
+ # Running the Zero-Shot Multi-Speaker Tacotron2 model to generate mel-spectrogram
59
+ mel_outputs, mel_lengths, alignments = ms_tacotron2.clone_voice(INPUT_TEXT, REFERENCE_SPEECH)
60
+
61
+ # Running Vocoder (spectrogram-to-waveform)
62
+ waveforms = hifi_gan.decode_batch(mel_outputs)
63
+
64
+ # Save the waverforms
65
+ for i in range(len(waveforms)):
66
+ synthesized_audio_path = f"synthesized_sample_{i}.wav"
67
+ torchaudio.save(synthesized_audio_path, waveforms[i].squeeze(1).cpu(), 22050)
68
+
69
+ ```
70
+
71
+ ### Inference on GPU
72
+ To perform inference on the GPU, add `run_opts={"device":"cuda"}` when calling the `from_hparams` method.
73
+
74
+ ### Training
75
+ The model was trained with SpeechBrain.
76
+ To train it from scratch follow these steps:
77
+ 1. Clone SpeechBrain:
78
+ ```bash
79
+ git clone https://github.com/speechbrain/speechbrain/
80
+ ```
81
+ 2. Install it:
82
+ ```bash
83
+ cd speechbrain
84
+ pip install -r requirements.txt
85
+ pip install -e .
86
+ ```
87
+ 3. Run Training:
88
+ ```bash
89
+ cd recipes/LibriTTS/TTS/mstacotron2/
90
+ python train.py hparams/train.yaml --data_folder=/path/to/libritts_data --device=cuda:0 --max_grad_norm=1.0
91
+ ```
92
+ The training logs will be available here in the future.
93
+
94
+ The pre-trained model with an easy-inference function will be available in the future.
95
+
96
+ ### Limitations
97
+ The SpeechBrain team does not provide any warranty on the performance achieved by this model when used on other datasets.
98
+
99
+ # **About SpeechBrain**
100
+ - Website: https://speechbrain.github.io/
101
+ - Code: https://github.com/speechbrain/speechbrain/
102
+ - HuggingFace: https://huggingface.co/speechbrain/
103
+
104
+
105
+ # **Citing SpeechBrain**
106
+ Please, cite SpeechBrain if you use it for your research or business.
107
+
108
+ ```bibtex
109
+ @misc{speechbrain,
110
+ title={{SpeechBrain}: A General-Purpose Speech Toolkit},
111
+ 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},
112
+ year={2021},
113
+ eprint={2106.04624},
114
+ archivePrefix={arXiv},
115
+ primaryClass={eess.AS},
116
+ note={arXiv:2106.04624}
117
+ }
118
+ ```