|
|
from TTS.api import TTS |
|
|
import gradio as gr |
|
|
import torch |
|
|
import os |
|
|
|
|
|
os.environ["CUDA_VISIBLE_DEVICES"] = "0" |
|
|
|
|
|
tts = TTS(model_name="tts_models/en/ljspeech/tacotron2-DDC") |
|
|
tts.to("cuda" if torch.cuda.is_available() else "cpu") |
|
|
|
|
|
def synthesize(text): |
|
|
output_path = "output.wav" |
|
|
tts.tts_to_file(text=text, file_path=output_path) |
|
|
return output_path |
|
|
|
|
|
iface = gr.Interface( |
|
|
fn=synthesize, |
|
|
inputs=gr.Textbox(lines=3, label="Enter text to synthesize"), |
|
|
outputs=gr.Audio(type="filepath", label="Generated Speech"), |
|
|
title="Mozilla Tacotron2 TTS - Smooth & Clean", |
|
|
description="Simple text-to-speech using Mozilla's Tacotron2-DDC model. No voice samples required." |
|
|
) |
|
|
|
|
|
if __name__ == "__main__": |
|
|
iface.launch() |
|
|
|