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