Spaces:
Sleeping
Sleeping
import gradio as gr | |
from TTS.api import TTS # Import TTS API | |
# Initialize TTS | |
tts = TTS(model_path="best_model.pth", config_path="config.json") | |
# Ensure the 'is_multi_lingual' attribute is set if it's not present | |
if not hasattr(tts, 'is_multi_lingual'): | |
tts.is_multi_lingual = False # Set to False since your model is not multilingual | |
def generate_speech(text): | |
wav = tts.tts(text) # Ensure this is the correct method for generating speech | |
audio_path = "output.wav" | |
with open(audio_path, "wb") as f: | |
f.write(wav) | |
return audio_path | |
# Define Gradio interface | |
iface = gr.Interface( | |
fn=generate_speech, | |
inputs=gr.Textbox(lines=2, placeholder="Enter text here..."), | |
outputs=gr.Audio(type="filepath"), | |
title="Text-to-Speech with Coqui TTS" | |
) | |
if __name__ == "__main__": | |
iface.launch() | |