Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,30 +1,35 @@
|
|
|
|
|
|
|
|
1 |
import gradio as gr
|
2 |
from docx import Document
|
3 |
from TTS.api import TTS
|
4 |
import tempfile
|
5 |
-
import os
|
6 |
-
os.environ["LIBROSA_CACHE_DIR"] = "/tmp/librosa_cache"
|
7 |
|
8 |
-
# Load TTS model
|
9 |
-
#tts = TTS(model_name="tts_models/en/vctk/vits", progress_bar=False, gpu=False)
|
10 |
tts = TTS(model_name="tts_models/en/ljspeech/tacotron2-DDC", progress_bar=False, gpu=False)
|
11 |
|
12 |
-
def
|
13 |
-
|
14 |
-
|
|
|
|
|
|
|
|
|
|
|
15 |
|
16 |
-
|
17 |
-
text =
|
18 |
-
|
19 |
-
return "output.wav"
|
20 |
|
21 |
-
# Gradio
|
22 |
interface = gr.Interface(
|
23 |
-
fn=
|
24 |
-
inputs=gr.File(
|
25 |
-
outputs=gr.Audio(
|
26 |
-
title="
|
27 |
-
description="Upload a .docx
|
28 |
)
|
29 |
|
30 |
-
|
|
|
|
1 |
+
import os
|
2 |
+
os.environ["NUMBA_DISABLE_CACHE"] = "1" # Fix for Numba caching issue in cloud
|
3 |
+
|
4 |
import gradio as gr
|
5 |
from docx import Document
|
6 |
from TTS.api import TTS
|
7 |
import tempfile
|
|
|
|
|
8 |
|
9 |
+
# Load Coqui TTS model (offline + realistic)
|
|
|
10 |
tts = TTS(model_name="tts_models/en/ljspeech/tacotron2-DDC", progress_bar=False, gpu=False)
|
11 |
|
12 |
+
def docx_to_audio(doc_file):
|
13 |
+
# Read text from .docx file
|
14 |
+
document = Document(doc_file.name)
|
15 |
+
full_text = "\n".join([para.text for para in document.paragraphs if para.text.strip()])
|
16 |
+
|
17 |
+
# Create temporary output .wav file
|
18 |
+
with tempfile.NamedTemporaryFile(suffix=".wav", delete=False) as f:
|
19 |
+
audio_path = f.name
|
20 |
|
21 |
+
# Generate audio
|
22 |
+
tts.tts_to_file(text=full_text, file_path=audio_path)
|
23 |
+
return audio_path
|
|
|
24 |
|
25 |
+
# Gradio interface
|
26 |
interface = gr.Interface(
|
27 |
+
fn=docx_to_audio,
|
28 |
+
inputs=gr.File(label="Upload .docx File"),
|
29 |
+
outputs=gr.Audio(type="filepath", label="Download Audio"),
|
30 |
+
title="Docx to Realistic Voiceover",
|
31 |
+
description="Upload a .docx file and get realistic speech audio."
|
32 |
)
|
33 |
|
34 |
+
if __name__ == "__main__":
|
35 |
+
interface.launch()
|