Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,31 +1,30 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
import torch
|
| 3 |
-
from
|
|
|
|
| 4 |
|
| 5 |
-
# Load the model and
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
model.eval() # Set the model to evaluation mode
|
| 9 |
|
| 10 |
-
|
|
|
|
| 11 |
|
| 12 |
def generate_speech(text):
|
| 13 |
-
# Process the input text
|
| 14 |
-
inputs = processor(text, return_tensors="pt")
|
| 15 |
-
|
| 16 |
# Generate speech using the model
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
|
|
|
| 23 |
|
| 24 |
# Define the Gradio interface
|
| 25 |
iface = gr.Interface(
|
| 26 |
fn=generate_speech,
|
| 27 |
inputs=gr.Textbox(lines=2, placeholder="Enter text here..."),
|
| 28 |
-
outputs=gr.Audio(type="
|
| 29 |
title="Text-to-Speech with Coqui TTS",
|
| 30 |
description="Generate speech from text using a custom Coqui TTS model."
|
| 31 |
)
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
import torch
|
| 3 |
+
from coqui_tts import TTS
|
| 4 |
+
from coqui_tts.utils import audio
|
| 5 |
|
| 6 |
+
# Load the Coqui TTS model and configuration
|
| 7 |
+
model_path = "best_model.pth" # Directory where the model is saved
|
| 8 |
+
config_path = "config.json"
|
|
|
|
| 9 |
|
| 10 |
+
# Initialize TTS with your model and configuration
|
| 11 |
+
tts = TTS(model_path=model_path, config_path=config_path)
|
| 12 |
|
| 13 |
def generate_speech(text):
|
|
|
|
|
|
|
|
|
|
| 14 |
# Generate speech using the model
|
| 15 |
+
audio_path = tts.tts_to_file(text, "output.wav")
|
| 16 |
+
|
| 17 |
+
# Load the generated audio file
|
| 18 |
+
with open(audio_path, "rb") as f:
|
| 19 |
+
audio_data = f.read()
|
| 20 |
+
|
| 21 |
+
return audio_data
|
| 22 |
|
| 23 |
# Define the Gradio interface
|
| 24 |
iface = gr.Interface(
|
| 25 |
fn=generate_speech,
|
| 26 |
inputs=gr.Textbox(lines=2, placeholder="Enter text here..."),
|
| 27 |
+
outputs=gr.Audio(type="file"),
|
| 28 |
title="Text-to-Speech with Coqui TTS",
|
| 29 |
description="Generate speech from text using a custom Coqui TTS model."
|
| 30 |
)
|