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