sulaimank commited on
Commit
b913a7e
1 Parent(s): 4690304

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +132 -1
README.md CHANGED
@@ -1,3 +1,134 @@
1
  ---
2
- license: cc-by-4.0
 
 
 
 
 
 
 
 
 
 
 
3
  ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  ---
2
+ language: "en"
3
+ inference: false
4
+ tags:
5
+ - Vocoder
6
+ - HiFIGAN
7
+ - text-to-speech
8
+ - TTS
9
+ - speech-synthesis
10
+ - speechbrain
11
+ license: "apache-2.0"
12
+ datasets:
13
+ - LJSpeech
14
  ---
15
+
16
+ # Vocoder with HiFIGAN trained on LJSpeech
17
+
18
+ This repository provides all the necessary tools for using a [HiFIGAN](https://arxiv.org/abs/2010.05646) vocoder trained with [LJSpeech](https://keithito.com/LJ-Speech-Dataset/).
19
+
20
+ The pre-trained model takes in input a spectrogram and produces a waveform in output. Typically, a vocoder is used after a TTS model that converts an input text into a spectrogram.
21
+
22
+ The sampling frequency is 22050 Hz.
23
+
24
+ **NOTES**
25
+ - This vocoder model is trained on a single speaker. Although it has some ability to generalize to different speakers, for better results, we recommend using a multi-speaker vocoder like [this model trained on LibriTTS at 16,000 Hz](https://huggingface.co/speechbrain/tts-hifigan-libritts-16kHz) or [this one trained on LibriTTS at 22,050 Hz](https://huggingface.co/speechbrain/tts-hifigan-libritts-22050Hz).
26
+ - If you specifically require a vocoder with a 16,000 Hz sampling rate, please follow the provided link above for a suitable option.
27
+
28
+ ## Install SpeechBrain
29
+
30
+ ```bash
31
+ pip install speechbrain
32
+ ```
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
+ ### Using the Vocoder
39
+
40
+ - *Basic Usage:*
41
+ ```python
42
+ import torch
43
+ from speechbrain.inference.vocoders import HIFIGAN
44
+ hifi_gan = HIFIGAN.from_hparams(source="speechbrain/tts-hifigan-ljspeech", savedir="pretrained_models/tts-hifigan-ljspeech")
45
+ mel_specs = torch.rand(2, 80,298)
46
+ waveforms = hifi_gan.decode_batch(mel_specs)
47
+ ```
48
+
49
+ - *Convert a Spectrogram into a Waveform:*
50
+
51
+ ```python
52
+ import torchaudio
53
+ from speechbrain.inference.vocoders import HIFIGAN
54
+ from speechbrain.lobes.models.FastSpeech2 import mel_spectogram
55
+
56
+ # Load a pretrained HIFIGAN Vocoder
57
+ hifi_gan = HIFIGAN.from_hparams(source="speechbrain/tts-hifigan-ljspeech", savedir="pretrained_models/tts-hifigan-ljspeech")
58
+
59
+ # Load an audio file (an example file can be found in this repository)
60
+ # Ensure that the audio signal is sampled at 22050 Hz; refer to the provided link for a 16 kHz Vocoder.
61
+ signal, rate = torchaudio.load('speechbrain/tts-hifigan-ljspeech/example.wav')
62
+
63
+ # Compute the mel spectrogram.
64
+ # IMPORTANT: Use these specific parameters to match the Vocoder's training settings for optimal results.
65
+ spectrogram, _ = mel_spectogram(
66
+ audio=signal.squeeze(),
67
+ sample_rate=22050,
68
+ hop_length=256,
69
+ win_length=None,
70
+ n_mels=80,
71
+ n_fft=1024,
72
+ f_min=0.0,
73
+ f_max=8000.0,
74
+ power=1,
75
+ normalized=False,
76
+ min_max_energy_norm=True,
77
+ norm="slaney",
78
+ mel_scale="slaney",
79
+ compression=True
80
+ )
81
+
82
+ # Convert the spectrogram to waveform
83
+ waveforms = hifi_gan.decode_batch(spectrogram)
84
+
85
+ # Save the reconstructed audio as a waveform
86
+ torchaudio.save('waveform_reconstructed.wav', waveforms.squeeze(1), 22050)
87
+
88
+ # If everything is set up correctly, the original and reconstructed audio should be nearly indistinguishable.
89
+ # Keep in mind that this Vocoder is trained for a single speaker; for multi-speaker Vocoder options, refer to the provided links.
90
+
91
+ ```
92
+
93
+ ### Using the Vocoder with the TTS
94
+ ```python
95
+ import torchaudio
96
+ from speechbrain.inference.TTS import Tacotron2
97
+ from speechbrain.inference.vocoders import HIFIGAN
98
+
99
+ # Intialize TTS (tacotron2) and Vocoder (HiFIGAN)
100
+ tacotron2 = Tacotron2.from_hparams(source="speechbrain/tts-tacotron2-ljspeech", savedir="pretrained_models/tts-tacotron2-ljspeech")
101
+ hifi_gan = HIFIGAN.from_hparams(source="speechbrain/tts-hifigan-ljspeech", savedir="pretrained_model/tts-hifigan-ljspeech")
102
+
103
+ # Running the TTS
104
+ mel_output, mel_length, alignment = tacotron2.encode_text("Mary had a little lamb")
105
+
106
+ # Running Vocoder (spectrogram-to-waveform)
107
+ waveforms = hifi_gan.decode_batch(mel_output)
108
+
109
+ # Save the waverform
110
+ torchaudio.save('example_TTS.wav',waveforms.squeeze(1), 22050)
111
+ ```
112
+
113
+ ### Inference on GPU
114
+ To perform inference on the GPU, add `run_opts={"device":"cuda"}` when calling the `from_hparams` method.
115
+
116
+ ### Training
117
+ The model was trained with SpeechBrain.
118
+ To train it from scratch follow these steps:
119
+ 1. Clone SpeechBrain:
120
+ ```bash
121
+ git clone https://github.com/speechbrain/speechbrain/
122
+ ```
123
+ 2. Install it:
124
+ ```bash
125
+ cd speechbrain
126
+ pip install -r requirements.txt
127
+ pip install -e .
128
+ ```
129
+ 3. Run Training:
130
+ ```bash
131
+ cd recipes/LJSpeech/TTS/vocoder/hifi_gan/
132
+ python train.py hparams/train.yaml --data_folder /path/to/LJspeech
133
+ ```
134
+ You can find our training results (models, logs, etc) [here](https://drive.google.com/drive/folders/19sLwV7nAsnUuLkoTu5vafURA9Fo2WZgG?usp=sharing).