SohomToom commited on
Commit
a3e2313
·
verified ·
1 Parent(s): 3a9c6ec

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +23 -18
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 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
- tts.tts_to_file(text=text, file_path="output.wav")
19
- return "output.wav"
20
 
21
- # Gradio UI
22
  interface = gr.Interface(
23
- fn=generate_audio,
24
- inputs=gr.File(file_types=[".docx"], label="Upload your DOCX script"),
25
- outputs=gr.Audio(label="Realistic Voiceover", type="filepath"),
26
- title="DOCX to Voiceover (Offline, Realistic)",
27
- description="Upload a .docx script and get a realistic WAV voiceover using Coqui TTS."
28
  )
29
 
30
- interface.launch()
 
 
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()