|
import gradio as gr |
|
from TTS.api import TTS |
|
|
|
|
|
tts = TTS(model_name="tts_models/en/ljspeech/tacotron2-DDC", progress_bar=False) |
|
|
|
def generate_speech(text): |
|
""" |
|
Generate speech from the input text. |
|
Saves the audio to a temporary file and returns the file path. |
|
""" |
|
output_file = "/tmp/output.wav" |
|
try: |
|
tts.tts_to_file(text=text, file_path=output_file) |
|
return output_file |
|
except Exception as e: |
|
return f"Error generating speech: {str(e)}" |
|
|
|
|
|
with gr.Blocks() as demo: |
|
gr.Markdown("# Coqui TTS Demo") |
|
gr.Markdown("Type some text and hear it spoken!") |
|
|
|
with gr.Row(): |
|
input_text = gr.Textbox(label="Enter Text", placeholder="Type something...", lines=3) |
|
|
|
with gr.Row(): |
|
submit_button = gr.Button("Generate Speech") |
|
|
|
with gr.Row(): |
|
output_audio = gr.Audio(label="Generated Speech", type="filepath") |
|
|
|
|
|
submit_button.click(generate_speech, inputs=input_text, outputs=output_audio) |
|
|
|
|
|
demo.launch(share=True) |