Spaces:
Running
Running
Poker commited on
Commit ·
648b380
1
Parent(s): 68c4618
fix: wrong kwarg in create_mixed_audio + cross-platform font paths for Linux Docker
Browse files- app.py +5 -4
- utils/audio_engine.py +24 -20
app.py
CHANGED
|
@@ -168,13 +168,14 @@ def merge_videos():
|
|
| 168 |
# Mix audio tracks if we have speech or background music
|
| 169 |
if speech_path or bg_music_path:
|
| 170 |
mixed_audio = os.path.join(UPLOAD_FOLDER, f"{job_id}_mixed.mp3")
|
| 171 |
-
|
| 172 |
-
|
| 173 |
bg_music_path=bg_music_path,
|
| 174 |
target_duration=duration,
|
| 175 |
-
output_path=mixed_audio
|
| 176 |
-
trim_to_video=trim_audio
|
| 177 |
)
|
|
|
|
|
|
|
| 178 |
|
| 179 |
# 3. Combine merged video and final audio
|
| 180 |
output_filename = f"merged_{job_id[:8]}.mp4"
|
|
|
|
| 168 |
# Mix audio tracks if we have speech or background music
|
| 169 |
if speech_path or bg_music_path:
|
| 170 |
mixed_audio = os.path.join(UPLOAD_FOLDER, f"{job_id}_mixed.mp3")
|
| 171 |
+
ok = create_mixed_audio(
|
| 172 |
+
voiceover_path=speech_path,
|
| 173 |
bg_music_path=bg_music_path,
|
| 174 |
target_duration=duration,
|
| 175 |
+
output_path=mixed_audio
|
|
|
|
| 176 |
)
|
| 177 |
+
if ok and os.path.exists(mixed_audio):
|
| 178 |
+
final_audio_path = mixed_audio
|
| 179 |
|
| 180 |
# 3. Combine merged video and final audio
|
| 181 |
output_filename = f"merged_{job_id[:8]}.mp4"
|
utils/audio_engine.py
CHANGED
|
@@ -324,34 +324,38 @@ def extract_keyword(text: str) -> str:
|
|
| 324 |
|
| 325 |
|
| 326 |
def get_font_for_lang(lang: str) -> str:
|
| 327 |
-
"""Find a suitable system font for the language to handle non-English glyphs.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 328 |
if lang.startswith("pa"):
|
| 329 |
-
|
| 330 |
"/System/Library/Fonts/Supplemental/Gurmukhi MN.ttc",
|
| 331 |
-
"/System/Library/Fonts/Supplemental/Gurmukhi Sangam MN.ttc",
|
| 332 |
-
"/System/Library/Fonts/Supplemental/Arial Unicode.ttf"
|
| 333 |
]
|
| 334 |
elif lang.startswith("hi"):
|
| 335 |
-
|
| 336 |
"/System/Library/Fonts/Supplemental/DevanagariMT.ttc",
|
| 337 |
-
"/System/Library/Fonts/Supplemental/Devanagari Sangam MN.ttc",
|
| 338 |
-
"/System/Library/Fonts/Supplemental/Arial Unicode.ttf"
|
| 339 |
-
]
|
| 340 |
-
elif lang.startswith("ur"):
|
| 341 |
-
paths = [
|
| 342 |
-
"/System/Library/Fonts/Supplemental/Arial Unicode.ttf",
|
| 343 |
-
"/System/Library/Fonts/Supplemental/Arial.ttf"
|
| 344 |
-
]
|
| 345 |
-
else:
|
| 346 |
-
paths = [
|
| 347 |
-
"/System/Library/Fonts/Supplemental/Arial Bold.ttf",
|
| 348 |
-
"/System/Library/Fonts/Supplemental/Arial.ttf"
|
| 349 |
]
|
| 350 |
-
|
| 351 |
-
for p in
|
| 352 |
if os.path.exists(p):
|
| 353 |
return p
|
| 354 |
-
return "
|
| 355 |
|
| 356 |
|
| 357 |
def make_ken_burns_frame(img_obj, target_w, target_h, t, duration, zoom_ratio=0.12):
|
|
|
|
| 324 |
|
| 325 |
|
| 326 |
def get_font_for_lang(lang: str) -> str:
|
| 327 |
+
"""Find a suitable system font for the language to handle non-English glyphs.
|
| 328 |
+
Works on both macOS and Linux (Docker/HF Spaces).
|
| 329 |
+
"""
|
| 330 |
+
# Linux (Docker) font paths — installed via apt fonts-dejavu-core, fonts-liberation
|
| 331 |
+
linux_unicode = [
|
| 332 |
+
"/usr/share/fonts/truetype/dejavu/DejaVuSans-Bold.ttf",
|
| 333 |
+
"/usr/share/fonts/truetype/dejavu/DejaVuSans.ttf",
|
| 334 |
+
"/usr/share/fonts/truetype/liberation/LiberationSans-Bold.ttf",
|
| 335 |
+
"/usr/share/fonts/truetype/liberation/LiberationSans-Regular.ttf",
|
| 336 |
+
]
|
| 337 |
+
# macOS font paths — fallback when running locally
|
| 338 |
+
macos_unicode = [
|
| 339 |
+
"/System/Library/Fonts/Supplemental/Arial Unicode.ttf",
|
| 340 |
+
"/System/Library/Fonts/Supplemental/Arial Bold.ttf",
|
| 341 |
+
"/System/Library/Fonts/Supplemental/Arial.ttf",
|
| 342 |
+
]
|
| 343 |
+
|
| 344 |
+
# Try language-specific paths first (Linux then macOS)
|
| 345 |
+
lang_paths = []
|
| 346 |
if lang.startswith("pa"):
|
| 347 |
+
lang_paths = [
|
| 348 |
"/System/Library/Fonts/Supplemental/Gurmukhi MN.ttc",
|
|
|
|
|
|
|
| 349 |
]
|
| 350 |
elif lang.startswith("hi"):
|
| 351 |
+
lang_paths = [
|
| 352 |
"/System/Library/Fonts/Supplemental/DevanagariMT.ttc",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 353 |
]
|
| 354 |
+
|
| 355 |
+
for p in lang_paths + linux_unicode + macos_unicode:
|
| 356 |
if os.path.exists(p):
|
| 357 |
return p
|
| 358 |
+
return "DejaVuSans" # Last resort — PIL will try to find it
|
| 359 |
|
| 360 |
|
| 361 |
def make_ken_burns_frame(img_obj, target_w, target_h, t, duration, zoom_ratio=0.12):
|