Spaces:
Running
Running
liuxin Cursor commited on
Commit ·
111eded
1
Parent(s): eff9a41
fix: support M4A and other audio formats via ffprobe fallback
Browse files
app.py
CHANGED
|
@@ -297,9 +297,23 @@ def _safe_prompt_wav_recognition(
|
|
| 297 |
|
| 298 |
def _get_audio_duration_seconds(audio_path: str) -> float:
|
| 299 |
import soundfile as sf
|
| 300 |
-
|
| 301 |
-
|
| 302 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 303 |
|
| 304 |
|
| 305 |
def _validate_reference_audio_duration(
|
|
|
|
| 297 |
|
| 298 |
def _get_audio_duration_seconds(audio_path: str) -> float:
|
| 299 |
import soundfile as sf
|
| 300 |
+
try:
|
| 301 |
+
info = sf.info(audio_path)
|
| 302 |
+
return float(info.frames) / float(info.samplerate)
|
| 303 |
+
except Exception:
|
| 304 |
+
pass
|
| 305 |
+
import subprocess
|
| 306 |
+
try:
|
| 307 |
+
result = subprocess.run(
|
| 308 |
+
["ffprobe", "-v", "error", "-show_entries", "format=duration",
|
| 309 |
+
"-of", "default=noprint_wrappers=1:nokey=1", audio_path],
|
| 310 |
+
capture_output=True, text=True, timeout=10,
|
| 311 |
+
)
|
| 312 |
+
if result.returncode == 0 and result.stdout.strip():
|
| 313 |
+
return float(result.stdout.strip())
|
| 314 |
+
except (FileNotFoundError, subprocess.TimeoutExpired, ValueError):
|
| 315 |
+
pass
|
| 316 |
+
raise RuntimeError(f"Cannot determine audio duration: {audio_path}")
|
| 317 |
|
| 318 |
|
| 319 |
def _validate_reference_audio_duration(
|