SohomToom commited on
Commit
b9bf9b2
·
verified ·
1 Parent(s): f2cde60

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +31 -28
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
- # 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()
 
 
 
 
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()