import gradio as gr from TTS.api import TTS # Ensure this is the correct import path # Define paths to the model and configuration model_path = "best_model.pth" # Directory where your model is saved config_path = "config.json" # Configuration file # 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 # Ensure this is the correct method to call wav = tts.tts(text) # Save the generated audio to a temporary file audio_path = "output.wav" with open(audio_path, "wb") as f: f.write(wav) return audio_path # Define the 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", description="Generate speech from text using a custom Coqui TTS model." ) if __name__ == "__main__": iface.launch()