Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,28 +1,25 @@
|
|
1 |
import os
|
2 |
-
|
|
|
|
|
|
|
3 |
from TTS.api import TTS
|
|
|
4 |
|
5 |
-
# Load
|
6 |
tts = TTS("tts_models/en/ljspeech/vits", progress_bar=False).to("cpu")
|
7 |
|
8 |
def text_to_speech(text):
|
9 |
"""Generate Speech from Text"""
|
10 |
output_path = "output.wav"
|
11 |
-
|
12 |
-
# Generate TTS audio
|
13 |
tts.tts_to_file(text=text, file_path=output_path)
|
14 |
-
|
15 |
-
# Ensure the file exists before returning
|
16 |
-
if os.path.exists(output_path):
|
17 |
-
return output_path
|
18 |
-
else:
|
19 |
-
return "Error generating speech"
|
20 |
|
21 |
# Gradio UI
|
22 |
gr.Interface(
|
23 |
fn=text_to_speech,
|
24 |
inputs=gr.Textbox(placeholder="Enter text to convert to speech"),
|
25 |
-
outputs=gr.Audio(type="filepath"),
|
26 |
title="Coqui TTS - Text to Speech",
|
27 |
description="Enter text and listen to the generated speech.",
|
28 |
).launch()
|
|
|
1 |
import os
|
2 |
+
|
3 |
+
# Install espeak-ng before running the model
|
4 |
+
os.system("apt-get update && apt-get install -y espeak-ng")
|
5 |
+
|
6 |
from TTS.api import TTS
|
7 |
+
import gradio as gr
|
8 |
|
9 |
+
# Load Coqui TTS Model (VITS)
|
10 |
tts = TTS("tts_models/en/ljspeech/vits", progress_bar=False).to("cpu")
|
11 |
|
12 |
def text_to_speech(text):
|
13 |
"""Generate Speech from Text"""
|
14 |
output_path = "output.wav"
|
|
|
|
|
15 |
tts.tts_to_file(text=text, file_path=output_path)
|
16 |
+
return output_path
|
|
|
|
|
|
|
|
|
|
|
17 |
|
18 |
# Gradio UI
|
19 |
gr.Interface(
|
20 |
fn=text_to_speech,
|
21 |
inputs=gr.Textbox(placeholder="Enter text to convert to speech"),
|
22 |
+
outputs=gr.Audio(type="filepath"),
|
23 |
title="Coqui TTS - Text to Speech",
|
24 |
description="Enter text and listen to the generated speech.",
|
25 |
).launch()
|