Update srt_utils.py
Browse files- srt_utils.py +31 -31
srt_utils.py
CHANGED
|
@@ -349,39 +349,39 @@ def process_audio_for_transcription(input_file: str) -> str:
|
|
| 349 |
# Fallback will trigger below
|
| 350 |
else:
|
| 351 |
# Demucs output structure: output_dir / model_name / input_filename_no_ext / vocals.wav
|
| 352 |
-
|
| 353 |
-
|
| 354 |
-
|
| 355 |
-
vocals_path = os.path.join(output_dir, model, input_stem, "vocals.wav")
|
| 356 |
-
|
| 357 |
-
if os.path.exists(vocals_path):
|
| 358 |
-
print(f"✅ Demucs sucesso: {vocals_path}")
|
| 359 |
-
|
| 360 |
-
# Convert Wav to MP3 to save space/bandwidth if needed,
|
| 361 |
-
# OR just return the wav if Groq supports it (Groq supports wav).
|
| 362 |
-
# Let's convert to MP3 16kHz mono to optimize upload to Groq
|
| 363 |
|
| 364 |
-
|
| 365 |
-
|
| 366 |
-
ffmpeg_cmd = shutil.which("ffmpeg")
|
| 367 |
-
if ffmpeg_cmd:
|
| 368 |
-
# Compress to mono mp3
|
| 369 |
-
cmd_convert = [
|
| 370 |
-
ffmpeg_cmd, "-y",
|
| 371 |
-
"-i", vocals_path,
|
| 372 |
-
"-ac", "1", "-ar", "16000",
|
| 373 |
-
"-c:a", "libmp3lame", "-q:a", "2",
|
| 374 |
-
final_output
|
| 375 |
-
]
|
| 376 |
-
subprocess.run(cmd_convert, check=True, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
|
| 377 |
-
|
| 378 |
-
# Cleanup demucs folder? Maybe keep for cache but better safe space
|
| 379 |
-
try: shutil.rmtree(os.path.join(output_dir, model, input_stem))
|
| 380 |
-
except: pass
|
| 381 |
-
|
| 382 |
-
return final_output
|
| 383 |
|
| 384 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 385 |
|
| 386 |
except Exception as e:
|
| 387 |
print(f"⚠️ Falha no Demucs: {e}")
|
|
|
|
| 349 |
# Fallback will trigger below
|
| 350 |
else:
|
| 351 |
# Demucs output structure: output_dir / model_name / input_filename_no_ext / vocals.wav
|
| 352 |
+
input_filename = os.path.basename(input_file)
|
| 353 |
+
input_stem = os.path.splitext(input_filename)[0]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 354 |
|
| 355 |
+
vocals_path = os.path.join(output_dir, model, input_stem, "vocals.wav")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 356 |
|
| 357 |
+
if os.path.exists(vocals_path):
|
| 358 |
+
print(f"✅ Demucs sucesso: {vocals_path}")
|
| 359 |
+
|
| 360 |
+
# Convert Wav to MP3 to save space/bandwidth if needed,
|
| 361 |
+
# OR just return the wav if Groq supports it (Groq supports wav).
|
| 362 |
+
# Let's convert to MP3 16kHz mono to optimize upload to Groq
|
| 363 |
+
|
| 364 |
+
final_output = input_file + ".vocals.mp3"
|
| 365 |
+
|
| 366 |
+
ffmpeg_cmd = shutil.which("ffmpeg")
|
| 367 |
+
if ffmpeg_cmd:
|
| 368 |
+
# Compress to mono mp3
|
| 369 |
+
cmd_convert = [
|
| 370 |
+
ffmpeg_cmd, "-y",
|
| 371 |
+
"-i", vocals_path,
|
| 372 |
+
"-ac", "1", "-ar", "16000",
|
| 373 |
+
"-c:a", "libmp3lame", "-q:a", "2",
|
| 374 |
+
final_output
|
| 375 |
+
]
|
| 376 |
+
subprocess.run(cmd_convert, check=True, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
|
| 377 |
+
|
| 378 |
+
# Cleanup demucs folder? Maybe keep for cache but better safe space
|
| 379 |
+
try: shutil.rmtree(os.path.join(output_dir, model, input_stem))
|
| 380 |
+
except: pass
|
| 381 |
+
|
| 382 |
+
return final_output
|
| 383 |
+
|
| 384 |
+
return vocals_path
|
| 385 |
|
| 386 |
except Exception as e:
|
| 387 |
print(f"⚠️ Falha no Demucs: {e}")
|