Update app.py
Browse files
app.py
CHANGED
|
@@ -2,26 +2,33 @@ import gradio as gr
|
|
| 2 |
import torch
|
| 3 |
from TTS.api import TTS
|
| 4 |
|
| 5 |
-
#
|
| 6 |
-
tts = TTS(model_name="tts_models/en/ljspeech/fast_pitch")
|
| 7 |
-
|
| 8 |
-
# Set the device manually if CUDA is available
|
| 9 |
device = "cuda" if torch.cuda.is_available() else "cpu"
|
| 10 |
-
|
|
|
|
|
|
|
| 11 |
|
| 12 |
def generate_audio(text):
|
| 13 |
-
|
| 14 |
output_path = "output.wav"
|
| 15 |
-
|
| 16 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 17 |
|
| 18 |
# Gradio Interface with a button
|
| 19 |
interface = gr.Interface(
|
| 20 |
-
fn=generate_audio,
|
| 21 |
-
inputs=
|
| 22 |
-
outputs="
|
| 23 |
-
|
|
|
|
|
|
|
| 24 |
)
|
| 25 |
|
| 26 |
# Launch Gradio app
|
| 27 |
-
|
|
|
|
|
|
| 2 |
import torch
|
| 3 |
from TTS.api import TTS
|
| 4 |
|
| 5 |
+
# Check for GPU availability
|
|
|
|
|
|
|
|
|
|
| 6 |
device = "cuda" if torch.cuda.is_available() else "cpu"
|
| 7 |
+
|
| 8 |
+
# Load Coqui TTS Model (without 'device' argument)
|
| 9 |
+
tts = TTS(model_name="tts_models/en/ljspeech/fast_pitch", progress_bar=False)
|
| 10 |
|
| 11 |
def generate_audio(text):
|
| 12 |
+
"""Function to synthesize speech from text."""
|
| 13 |
output_path = "output.wav"
|
| 14 |
+
print("Generating audio...") # Debugging log
|
| 15 |
+
|
| 16 |
+
# Convert text to speech
|
| 17 |
+
tts.tts_to_file(text, file_path=output_path)
|
| 18 |
+
|
| 19 |
+
print("Audio saved:", output_path) # Debugging log
|
| 20 |
+
return output_path # Returning file path to Gradio
|
| 21 |
|
| 22 |
# Gradio Interface with a button
|
| 23 |
interface = gr.Interface(
|
| 24 |
+
fn=generate_audio,
|
| 25 |
+
inputs=gr.Textbox(label="Enter text"),
|
| 26 |
+
outputs=gr.Audio(label="Generated Speech"),
|
| 27 |
+
title="Coqui TTS Text-to-Speech",
|
| 28 |
+
description="Enter text and click **Synthesize** to generate speech.",
|
| 29 |
+
live=True
|
| 30 |
)
|
| 31 |
|
| 32 |
# Launch Gradio app
|
| 33 |
+
if __name__ == "__main__":
|
| 34 |
+
interface.launch(share=True)
|