|
import gradio as gr |
|
import torch |
|
from speechbrain.pretrained import Tacotron2 |
|
from speechbrain.pretrained import HIFIGAN |
|
|
|
|
|
hifi_gan = HIFIGAN.from_hparams(source="speechbrain/tts-hifigan-ljspeech", savedir="tmpdir_vocoder") |
|
tacotron2 = Tacotron2.from_hparams(source="speechbrain/tts-tacotron2-ljspeech", savedir="tmpdir_tts") |
|
|
|
|
|
def synthesize_speech(text): |
|
|
|
mel_output, _, _ = tacotron2.encode_text(text) |
|
|
|
|
|
waveforms = hifi_gan.decode_batch(mel_output) |
|
|
|
|
|
torch.save(waveforms, "speech.pt") |
|
return "speech.pt" |
|
|
|
|
|
iface = gr.Interface( |
|
fn=synthesize_speech, |
|
inputs=gr.Textbox(lines=5, label="Input Text"), |
|
outputs=gr.Audio(label="Output Audio", type="filepath"), |
|
title="TTS Demo", |
|
description="Enter text to synthesize speech." |
|
) |
|
|
|
iface.launch() |