yingzhi commited on
Commit
50e2109
1 Parent(s): 531b1f2

initial_commit

Browse files
Files changed (4) hide show
  1. README.md +144 -1
  2. config.json +6 -0
  3. hyperparams.yaml +1 -0
  4. model.ckpt +3 -0
README.md CHANGED
@@ -1,3 +1,146 @@
1
  ---
2
- license: apache-2.0
 
 
 
 
 
 
 
 
 
 
 
3
  ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  ---
2
+ language: "en"
3
+ tags:
4
+ - text-to-speech
5
+ - TTS
6
+ - speech-synthesis
7
+ - fastspeech2
8
+ - speechbrain
9
+ license: "apache-2.0"
10
+ datasets:
11
+ - LJSpeech
12
+ metrics:
13
+ - mos
14
  ---
15
+
16
+ <iframe src="https://ghbtns.com/github-btn.html?user=speechbrain&repo=speechbrain&type=star&count=true&size=large&v=2" frameborder="0" scrolling="0" width="170" height="30" title="GitHub"></iframe>
17
+ <br/><br/>
18
+
19
+ # Text-to-Speech (TTS) with FastSpeech2-Internal-Alignment trained on LJSpeech
20
+
21
+ This repository provides all the necessary tools for Text-to-Speech (TTS) with SpeechBrain using a [FastSpeech2](https://arxiv.org/abs/2006.04558) with internal alignment pretrained on [LJSpeech](https://keithito.com/LJ-Speech-Dataset/).
22
+
23
+ The pre-trained model takes texts or phonemes as input and produces a spectrogram in output. One can get the final waveform by applying a vocoder (e.g., HiFIGAN) on top of the generated spectrogram. It should be noted that if the input is text, we use a state-of-the-art grapheme-to-phoneme module to convert it to phonemes and then pass the phonemes to fastspeech2-internal-alignment model.
24
+
25
+
26
+ ## Install SpeechBrain
27
+
28
+ ```bash
29
+ git clone https://github.com/speechbrain/speechbrain.git
30
+ cd speechbrain
31
+ pip install -r requirements.txt
32
+ pip install --editable .
33
+ ```
34
+
35
+ Please notice that we encourage you to read our tutorials and learn more about
36
+ [SpeechBrain](https://speechbrain.github.io).
37
+
38
+ ### Perform Text-to-Speech (TTS) with FastSpeech2-Internal-Alignment
39
+
40
+ ```python
41
+ import torchaudio
42
+ from speechbrain.pretrained import FastSpeech2InternalAlignment
43
+ from speechbrain.pretrained import HIFIGAN
44
+
45
+ # Intialize TTS (tacotron2) and Vocoder (HiFIGAN)
46
+ fastspeech2 = FastSpeech2InternalAlignment.from_hparams(source="speechbrain/tts-fastspeech2-internal-alignment-ljspeech", savedir="tmpdir_tts")
47
+ hifi_gan = HIFIGAN.from_hparams(source="speechbrain/tts-hifigan-ljspeech", savedir="tmpdir_vocoder")
48
+
49
+ # Run TTS with text input
50
+ input_text = "Welcome to speechbrain, this is a test run with fastspeech internal alignment."
51
+
52
+ mel_output, durations, pitch, energy = fastspeech2.encode_text(
53
+ [input_text],
54
+ pace=1.0, # scale up/down the speed
55
+ pitch_rate=1.0, # scale up/down the pitch
56
+ energy_rate=1.0, # scale up/down the energy
57
+ )
58
+
59
+ # Running Vocoder (spectrogram-to-waveform)
60
+ waveforms = hifi_gan.decode_batch(mel_output)
61
+
62
+ # Save the waverform
63
+ torchaudio.save('example_TTS_input_text.wav', waveforms.squeeze(1), 22050)
64
+
65
+
66
+ # Run TTS with phoneme input
67
+ input_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', ';', " ", 'DH', 'OW', ' ', 'AW', 'ER', ' ', 'OW', 'N', ' ', 'B', 'AE', 'S', 'K', 'ER', 'V', 'IH', 'L', ';', " ", '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', ';', " ", 'W', 'EH', 'N', 'T', ' ', 'M', 'AH', 'CH', ' ', 'AA', 'N', ' ', 'DH', 'AH', ' ', 'S', 'EY', 'M', ' ', 'L', 'AY', 'N', 'Z', ';']
68
+
69
+ mel_output, durations, pitch, energy = fastspeech2.encode_phoneme(
70
+ [input_phonemes],
71
+ pace=1.0, # scale up/down the speed
72
+ pitch_rate=1.0, # scale up/down the pitch
73
+ energy_rate=1.0, # scale up/down the energy
74
+ )
75
+
76
+ # Running Vocoder (spectrogram-to-waveform)
77
+ waveforms = hifi_gan.decode_batch(mel_output)
78
+
79
+ # Save the waverform
80
+ torchaudio.save('example_TTS_input_phoneme.wav', waveforms.squeeze(1), 22050)
81
+ ```
82
+
83
+ If you want to generate multiple sentences in one-shot, you can do in this way:
84
+
85
+ ```python
86
+ from speechbrain.pretrained import FastSpeech2InternalAlignment
87
+ fastspeech2 = FastSpeech2InternalAlignment.from_hparams(source="speechbrain/tts-fastspeech2-internal-alignment-ljspeech", savedir="tmpdir_tts")
88
+ items = [
89
+ "A quick brown fox jumped over the lazy dog",
90
+ "How much wood would a woodchuck chuck?",
91
+ "Never odd or even"
92
+ ]
93
+ mel_outputs, durations, pitch, energy = fastspeech2.encode_text(
94
+ items,
95
+ pace=1.0, # scale up/down the speed
96
+ pitch_rate=1.0, # scale up/down the pitch
97
+ energy_rate=1.0, # scale up/down the energy
98
+ )
99
+ ```
100
+
101
+ ### Inference on GPU
102
+ To perform inference on the GPU, add `run_opts={"device":"cuda"}` when calling the `from_hparams` method.
103
+
104
+ ### Training
105
+ The model was trained with SpeechBrain.
106
+ To train it from scratch follow these steps:
107
+ 1. Clone SpeechBrain:
108
+ ```bash
109
+ git clone https://github.com/speechbrain/speechbrain/
110
+ ```
111
+ 2. Install it:
112
+ ```bash
113
+ cd speechbrain
114
+ pip install -r requirements.txt
115
+ pip install -e .
116
+ ```
117
+ 3. Run Training:
118
+ ```bash
119
+ cd recipes/LJSpeech/TTS/fastspeech2/
120
+ python train_internal_alignment.py hparams/train_internal_alignment.yaml --data_folder=/your_folder/LJSpeech-1.1
121
+ ```
122
+ You can find our training results (models, logs, etc) [here](https://www.dropbox.com/sh/ca2rjc5x1ypm7aj/AADTJXxTina5Lt8BcdWs7LP5a?dl=0).
123
+
124
+ ### Limitations
125
+ The SpeechBrain team does not provide any warranty on the performance achieved by this model when used on other datasets.
126
+
127
+ # **About SpeechBrain**
128
+ - Website: https://speechbrain.github.io/
129
+ - Code: https://github.com/speechbrain/speechbrain/
130
+ - HuggingFace: https://huggingface.co/speechbrain/
131
+
132
+
133
+ # **Citing SpeechBrain**
134
+ Please, cite SpeechBrain if you use it for your research or business.
135
+
136
+ ```bibtex
137
+ @misc{speechbrain,
138
+ title={{SpeechBrain}: A General-Purpose Speech Toolkit},
139
+ 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},
140
+ year={2021},
141
+ eprint={2106.04624},
142
+ archivePrefix={arXiv},
143
+ primaryClass={eess.AS},
144
+ note={arXiv:2106.04624}
145
+ }
146
+ ```
config.json ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
 
1
+ {
2
+ "speechbrain_interface": "FastSpeech2",
3
+ "vocoder_interface": "HiFIGAN",
4
+ "vocoder_model_id": "speechbrain/tts-hifigan-ljspeech",
5
+ "sample_rate": 22050
6
+ }
hyperparams.yaml ADDED
@@ -0,0 +1 @@
 
 
1
+ /home/ywang/.cache/huggingface/hub/models--speechbrain--tts-fastspeech2-ljspeech/snapshots/3df449681f33a0dbb17376bee5a7b7a3d4950c87/hyperparams.yaml
model.ckpt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:3bf42d37ad3c9d2a23068def924dc1c486c33252f06d879f3bc7ef5a538c9d59
3
+ size 245013993