Update app.py
Browse files
app.py
CHANGED
|
@@ -35,6 +35,10 @@ import torch
|
|
| 35 |
from TTS.tts.configs.xtts_config import XttsConfig
|
| 36 |
from pydub import AudioSegment
|
| 37 |
from pyannote.audio import Pipeline
|
|
|
|
|
|
|
|
|
|
|
|
|
| 38 |
|
| 39 |
# Accept license terms for Coqui XTTS
|
| 40 |
os.environ["COQUI_TOS_AGREED"] = "1"
|
|
@@ -157,7 +161,7 @@ def segment_background_audio(audio_path, output_path="background_segments.wav"):
|
|
| 157 |
result_audio.export(output_path, format="wav")
|
| 158 |
print(f"Saved non-speech (background) audio to: {output_path}")
|
| 159 |
|
| 160 |
-
return
|
| 161 |
|
| 162 |
def transcribe_video_with_speakers(video_path):
|
| 163 |
# Extract audio from video
|
|
@@ -166,7 +170,7 @@ def transcribe_video_with_speakers(video_path):
|
|
| 166 |
video.audio.write_audiofile(audio_path)
|
| 167 |
logger.info(f"Audio extracted from video: {audio_path}")
|
| 168 |
|
| 169 |
-
segment_background_audio(audio_path)
|
| 170 |
print(f"Saved non-speech (background) audio to local")
|
| 171 |
|
| 172 |
# Set up device
|
|
@@ -343,7 +347,6 @@ def update_translations(file, edited_table, mode):
|
|
| 343 |
except Exception as e:
|
| 344 |
raise ValueError(f"Error updating translations: {e}")
|
| 345 |
|
| 346 |
-
|
| 347 |
def create_subtitle_clip_pil(text, start_time, end_time, video_width, video_height, font_path):
|
| 348 |
try:
|
| 349 |
subtitle_width = int(video_width * 0.8)
|
|
@@ -484,14 +487,6 @@ def add_transcript_voiceover(video_path, translated_json, output_path, add_voice
|
|
| 484 |
|
| 485 |
return error_messages
|
| 486 |
|
| 487 |
-
import os
|
| 488 |
-
import traceback
|
| 489 |
-
from TTS.api import TTS
|
| 490 |
-
import wave
|
| 491 |
-
import logging
|
| 492 |
-
|
| 493 |
-
logger = logging.getLogger(__name__)
|
| 494 |
-
|
| 495 |
# Initialize TTS model only once (outside the function)
|
| 496 |
tts = TTS(model_name="tts_models/multilingual/multi-dataset/xtts_v2")
|
| 497 |
|
|
|
|
| 35 |
from TTS.tts.configs.xtts_config import XttsConfig
|
| 36 |
from pydub import AudioSegment
|
| 37 |
from pyannote.audio import Pipeline
|
| 38 |
+
import traceback
|
| 39 |
+
import wave
|
| 40 |
+
|
| 41 |
+
logger = logging.getLogger(__name__)
|
| 42 |
|
| 43 |
# Accept license terms for Coqui XTTS
|
| 44 |
os.environ["COQUI_TOS_AGREED"] = "1"
|
|
|
|
| 161 |
result_audio.export(output_path, format="wav")
|
| 162 |
print(f"Saved non-speech (background) audio to: {output_path}")
|
| 163 |
|
| 164 |
+
return True
|
| 165 |
|
| 166 |
def transcribe_video_with_speakers(video_path):
|
| 167 |
# Extract audio from video
|
|
|
|
| 170 |
video.audio.write_audiofile(audio_path)
|
| 171 |
logger.info(f"Audio extracted from video: {audio_path}")
|
| 172 |
|
| 173 |
+
segment_result = segment_background_audio(audio_path)
|
| 174 |
print(f"Saved non-speech (background) audio to local")
|
| 175 |
|
| 176 |
# Set up device
|
|
|
|
| 347 |
except Exception as e:
|
| 348 |
raise ValueError(f"Error updating translations: {e}")
|
| 349 |
|
|
|
|
| 350 |
def create_subtitle_clip_pil(text, start_time, end_time, video_width, video_height, font_path):
|
| 351 |
try:
|
| 352 |
subtitle_width = int(video_width * 0.8)
|
|
|
|
| 487 |
|
| 488 |
return error_messages
|
| 489 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 490 |
# Initialize TTS model only once (outside the function)
|
| 491 |
tts = TTS(model_name="tts_models/multilingual/multi-dataset/xtts_v2")
|
| 492 |
|