trained_tts / app.py
Neomindapp's picture
Update app.py
a1f77c1 verified
raw
history blame
938 Bytes
import gradio as gr
import torch
from coqui_tts import TTS
from coqui_tts.utils import audio
# Load the Coqui TTS model and configuration
model_path = "best_model.pth" # Directory where the model is saved
config_path = "config.json"
# Initialize TTS with your model and configuration
tts = TTS(model_path=model_path, config_path=config_path)
def generate_speech(text):
# Generate speech using the model
audio_path = tts.tts_to_file(text, "output.wav")
# Load the generated audio file
with open(audio_path, "rb") as f:
audio_data = f.read()
return audio_data
# Define the Gradio interface
iface = gr.Interface(
fn=generate_speech,
inputs=gr.Textbox(lines=2, placeholder="Enter text here..."),
outputs=gr.Audio(type="file"),
title="Text-to-Speech with Coqui TTS",
description="Generate speech from text using a custom Coqui TTS model."
)
if __name__ == "__main__":
iface.launch()