File size: 938 Bytes
f3c0815
f9d0c83
a1f77c1
 
f3c0815
a1f77c1
 
 
5622ebb
a1f77c1
 
5622ebb
f3c0815
f9d0c83
a1f77c1
 
 
 
 
 
 
f3c0815
f9d0c83
 
f3c0815
f9d0c83
a1f77c1
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
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()