Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,28 +1,31 @@
|
|
1 |
-
import gradio as gr
|
2 |
-
from docx import Document
|
3 |
-
from TTS.api import TTS
|
4 |
-
import tempfile
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
text
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
)
|
27 |
-
|
28 |
-
|
|
|
|
|
|
|
|
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 once
|
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 extract_text(docx_file):
|
13 |
+
doc = Document(docx_file)
|
14 |
+
return "\n".join([para.text for para in doc.paragraphs if para.text.strip()])
|
15 |
+
|
16 |
+
def generate_audio(docx_file):
|
17 |
+
text = extract_text(docx_file.name)
|
18 |
+
with tempfile.NamedTemporaryFile(suffix=".wav", delete=False) as temp_audio:
|
19 |
+
tts.tts_to_file(text=text, file_path=temp_audio.name)
|
20 |
+
return temp_audio.name
|
21 |
+
|
22 |
+
# Gradio UI
|
23 |
+
interface = gr.Interface(
|
24 |
+
fn=generate_audio,
|
25 |
+
inputs=gr.File(file_types=[".docx"], label="Upload your DOCX script"),
|
26 |
+
outputs=gr.Audio(label="Realistic Voiceover", type="filepath"),
|
27 |
+
title="DOCX to Voiceover (Offline, Realistic)",
|
28 |
+
description="Upload a .docx script and get a realistic WAV voiceover using Coqui TTS."
|
29 |
+
)
|
30 |
+
|
31 |
+
interface.launch()
|