This repository provides all the necessary tools for using a
HiFIGAN
vocoder trained with
LJSpeech
.
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.
import torchaudio
from speechbrain.inference.vocoders import HIFIGAN
from speechbrain.lobes.models.FastSpeech2 import mel_spectogram
# Load a pretrained HIFIGAN Vocoder
hifi_gan = HIFIGAN.from_hparams(source="speechbrain/tts-hifigan-ljspeech", savedir="pretrained_models/tts-hifigan-ljspeech")
# Load an audio file (an example file can be found in this repository)# Ensure that the audio signal is sampled at 22050 Hz; refer to the provided link for a 16 kHz Vocoder.
signal, rate = torchaudio.load('speechbrain/tts-hifigan-ljspeech/example.wav')
# Compute the mel spectrogram.# IMPORTANT: Use these specific parameters to match the Vocoder's training settings for optimal results.
spectrogram, _ = mel_spectogram(
audio=signal.squeeze(),
sample_rate=22050,
hop_length=256,
win_length=None,
n_mels=80,
n_fft=1024,
f_min=0.0,
f_max=8000.0,
power=1,
normalized=False,
min_max_energy_norm=True,
norm="slaney",
mel_scale="slaney",
compression=True
)
# Convert the spectrogram to waveform
waveforms = hifi_gan.decode_batch(spectrogram)
# Save the reconstructed audio as a waveform
torchaudio.save('waveform_reconstructed.wav', waveforms.squeeze(1), 22050)
# If everything is set up correctly, the original and reconstructed audio should be nearly indistinguishable.# Keep in mind that this Vocoder is trained for a single speaker; for multi-speaker Vocoder options, refer to the provided links.
Using the Vocoder with the TTS
import torchaudio
from speechbrain.inference.TTS import Tacotron2
from speechbrain.inference.vocoders import HIFIGAN
# Intialize TTS (tacotron2) and Vocoder (HiFIGAN)
tacotron2 = Tacotron2.from_hparams(source="speechbrain/tts-tacotron2-ljspeech", savedir="pretrained_models/tts-tacotron2-ljspeech")
hifi_gan = HIFIGAN.from_hparams(source="speechbrain/tts-hifigan-ljspeech", savedir="pretrained_model/tts-hifigan-ljspeech")
# 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)
Inference on GPU
To perform inference on the GPU, add
run_opts={"device":"cuda"}
when calling the
from_hparams
method.
Training
The model was trained with SpeechBrain.
To train it from scratch follow these steps:
tts-hifigan-ljspeech huggingface.co is an AI model on huggingface.co that provides tts-hifigan-ljspeech's model effect (), which can be used instantly with this speechbrain tts-hifigan-ljspeech model. huggingface.co supports a free trial of the tts-hifigan-ljspeech model, and also provides paid use of the tts-hifigan-ljspeech. Support call tts-hifigan-ljspeech model through api, including Node.js, Python, http.
tts-hifigan-ljspeech huggingface.co is an online trial and call api platform, which integrates tts-hifigan-ljspeech's modeling effects, including api services, and provides a free online trial of tts-hifigan-ljspeech, you can try tts-hifigan-ljspeech online for free by clicking the link below.
speechbrain tts-hifigan-ljspeech online free url in huggingface.co:
tts-hifigan-ljspeech is an open source model from GitHub that offers a free installation service, and any user can find tts-hifigan-ljspeech on GitHub to install. At the same time, huggingface.co provides the effect of tts-hifigan-ljspeech install, users can directly use tts-hifigan-ljspeech installed effect in huggingface.co for debugging and trial. It also supports api for free installation.
tts-hifigan-ljspeech install url in huggingface.co: