This repository provides all the necessary tools for using a
DiffWave
vocoder trained with
LJSpeech
.
The pre-trained model takes as input a spectrogram and generates a waveform as output. Typically, a vocoder is used after a TTS model that converts an input text into a spectrogram.
The sampling frequency is 22050 Hz.
Install SpeechBrain
pip install speechbrain
Please notice that we encourage you to read our tutorials and learn more about
SpeechBrain
.
Using the Vocoder as reconstructor
import torch
import torchaudio
import speechbrain as sb
from speechbrain.inference.vocoders import DiffWaveVocoder
from speechbrain.lobes.models.HifiGAN import mel_spectogram
from speechbrain.utils.fetching import fetch
from speechbrain.utils.data_utils import split_path
diffwave = DiffWaveVocoder.from_hparams(source="speechbrain/tts-diffwave-ljspeech", savedir="pretrained_models/tts-diffwave-ljspeech")
source, fl = split_path("speechbrain/tts-diffwave-ljspeech/LJ050-0075.wav")
path = fetch(fl, source=source, savedir="tmpdir")
audio, fs_file = torchaudio.load(path)
audio = torch.FloatTensor(audio)
mel = mel_spectogram(
sample_rate=22050,
hop_length=256,
win_length=1024,
n_fft=1024,
n_mels=80,
f_min=0,
f_max=8000,
power=1.0,
normalized=False,
norm="slaney",
mel_scale="slaney",
compression=True,
audio=audio,
)
# Running Vocoder (spectrogram-to-waveform), a fast sampling can be realized by passing user-defined variance schedules. According to the paper, high-quality audios can be generated with only 6 steps (instead of a total of 50).
waveforms = diffwave.decode_batch(
mel,
hop_len=256, # upsample factor, should be the same as "hop_len" during the extraction of mel-spectrogram
fast_sampling=True, # fast sampling is highly recommanded
fast_sampling_noise_schedule=[0.0001, 0.001, 0.01, 0.05, 0.2, 0.5], # customized noise schedule
)
torchaudio.save('reconstructed.wav', waveforms.squeeze(1), 22050)
Using the Vocoder with TTS
import torchaudio
from speechbrain.pretrained import FastSpeech2
from speechbrain.pretrained import DiffWaveVocoder
# Intialize TTS (FastSpeech2) and Vocoder (DiffWave)
fastspeech2 = FastSpeech2.from_hparams(source="speechbrain/tts-fastspeech2-ljspeech", savedir="pretrained_models/tts-fastspeech2-ljspeech")
diffwave = DiffWaveVocoder.from_hparams(source="speechbrain/tts-diffwave-ljspeech", savedir="pretrained_models/tts-diffwave-ljspeech")
input_text = "This is a test run with FastSpeech and DiffWave."# Running the TTS
mel_output, durations, pitch, energy = fastspeech2.encode_text(
[input_text],
pace=1.0, # scale up/down the speed
pitch_rate=1.0, # scale up/down the pitch
energy_rate=1.0, # scale up/down the energy
)
# Running Vocoder (spectrogram-to-waveform), a fast sampling can be realized by passing user-defined variance schedules. According to the paper, high-quality audios can be generated with only 6 steps (instead of a total of 50).
waveforms = diffwave.decode_batch(
mel_output,
hop_len=256, # upsample factor, should be the same as "hop_len" during the extraction of mel-spectrogram
fast_sampling=True, # fast sampling is highly recommanded
fast_sampling_noise_schedule=[0.0001, 0.001, 0.01, 0.05, 0.2, 0.5], # customized noise schedule
)
# 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:
Please, cite SpeechBrain if you use it for your research or business.
@misc{speechbrain,
title={{SpeechBrain}: A General-Purpose Speech Toolkit},
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},
year={2021},
eprint={2106.04624},
archivePrefix={arXiv},
primaryClass={eess.AS},
note={arXiv:2106.04624}
}
Runs of speechbrain tts-diffwave-ljspeech on huggingface.co
41
Total runs
0
24-hour runs
0
3-day runs
4
7-day runs
28
30-day runs
More Information About tts-diffwave-ljspeech huggingface.co Model
tts-diffwave-ljspeech huggingface.co is an AI model on huggingface.co that provides tts-diffwave-ljspeech's model effect (), which can be used instantly with this speechbrain tts-diffwave-ljspeech model. huggingface.co supports a free trial of the tts-diffwave-ljspeech model, and also provides paid use of the tts-diffwave-ljspeech. Support call tts-diffwave-ljspeech model through api, including Node.js, Python, http.
tts-diffwave-ljspeech huggingface.co is an online trial and call api platform, which integrates tts-diffwave-ljspeech's modeling effects, including api services, and provides a free online trial of tts-diffwave-ljspeech, you can try tts-diffwave-ljspeech online for free by clicking the link below.
speechbrain tts-diffwave-ljspeech online free url in huggingface.co:
tts-diffwave-ljspeech is an open source model from GitHub that offers a free installation service, and any user can find tts-diffwave-ljspeech on GitHub to install. At the same time, huggingface.co provides the effect of tts-diffwave-ljspeech install, users can directly use tts-diffwave-ljspeech installed effect in huggingface.co for debugging and trial. It also supports api for free installation.
tts-diffwave-ljspeech install url in huggingface.co: