Coqui_TTS / app.py
usmanzia's picture
Update app.py
68b6b2b verified
import gradio as gr
import torch
from TTS.api import TTS
# Check for GPU availability
device = "cuda" if torch.cuda.is_available() else "cpu"
# Load Coqui TTS Model (without 'device' argument)
tts = TTS(model_name="tts_models/en/ljspeech/fast_pitch", progress_bar=False)
def generate_audio(text):
"""Function to synthesize speech from text."""
output_path = "output.wav"
print("Generating audio...") # Debugging log
# Convert text to speech
tts.tts_to_file(text, file_path=output_path)
print("Audio saved:", output_path) # Debugging log
return output_path # Returning file path to Gradio
# Gradio Interface with a button
interface = gr.Interface(
fn=generate_audio,
inputs=gr.Textbox(label="Enter text"),
outputs=gr.Audio(label="Generated Speech"),
title="Coqui TTS Text-to-Speech",
description="Enter text and click **Synthesize** to generate speech.",
live=True
)
# Launch Gradio app
if __name__ == "__main__":
interface.launch(share=True)