File size: 1,022 Bytes
f3c0815
c5fb812
f3c0815
44922b9
 
 
5622ebb
7a21455
 
5622ebb
f3c0815
f9d0c83
c5fb812
7a21455
44922b9
 
 
7a21455
 
44922b9
a9a3010
f3c0815
f9d0c83
 
f3c0815
f9d0c83
a9a3010
f9d0c83
 
f3c0815
 
 
f9d0c83
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
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()