模型:
speechbrain/tts-hifigan-libritts-22050Hz
This repository provides all the necessary tools for using a HiFIGAN vocoder trained with LibriTTS (with multiple speakers). The sample rate used for the vocoder is 22050 Hz.
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.
Alternatives to this models are the following:
pip install speechbrain
Please notice that we encourage you to read our tutorials and learn more about SpeechBrain .
import torch from speechbrain.pretrained import HIFIGAN hifi_gan = HIFIGAN.from_hparams(source="speechbrain/tts-hifigan-libritts-22050Hz", savedir="tmpdir") mel_specs = torch.rand(2, 80,298) # Running Vocoder (spectrogram-to-waveform) waveforms = hifi_gan.decode_batch(mel_specs)
import torchaudio from speechbrain.pretrained import Tacotron2 from speechbrain.pretrained import HIFIGAN # Intialize TTS (tacotron2) and Vocoder (HiFIGAN) tacotron2 = Tacotron2.from_hparams(source="speechbrain/tts-tacotron2-ljspeech", savedir="tmpdir_tts") hifi_gan = HIFIGAN.from_hparams(source="speechbrain/tts-hifigan-libritts-22050Hz", savedir="tmpdir_vocoder") # Running the TTS mel_output, mel_length, alignment = tacotron2.encode_text("Mary had a little lamb") # Running Vocoder (spectrogram-to-waveform) waveforms = hifi_gan.decode_batch(mel_output) # Save the waverform torchaudio.save('example_TTS.wav',waveforms.squeeze(1), 22050)
To perform inference on the GPU, add run_opts={"device":"cuda"} when calling the from_hparams method.
The model was trained with SpeechBrain. To train it from scratch follow these steps:
git clone https://github.com/speechbrain/speechbrain/
cd speechbrain pip install -r requirements.txt pip install -e .
cd recipes/LibriTTS/vocoder/hifigan/ python train.py hparams/train.yaml --data_folder=/path/to/LibriTTS_data_destination --sample_rate=22050
To change the sample rate for model training go to the "recipes/LibriTTS/vocoder/hifigan/hparams/train.yaml" file and change the value for sample_rate as required. The training logs and checkpoints are available here .