Deepfake Authenticator commited on
Commit
fa1d723
·
1 Parent(s): d89b78a

fix: audio timeout 20s, cap chunks to 3, cap extraction to 30s — fix stuck at 80%

Browse files
Files changed (2) hide show
  1. backend/audio_detector.py +10 -1
  2. backend/detector.py +4 -1
backend/audio_detector.py CHANGED
@@ -45,9 +45,15 @@ class AudioExtractorAgent:
45
  clip.close()
46
  return None, 0
47
 
 
 
 
 
 
 
48
  # Write to temp WAV
49
  tmp_wav = tempfile.mktemp(suffix=".wav")
50
- clip.audio.write_audiofile(
51
  tmp_wav,
52
  fps=self.TARGET_SR,
53
  nbytes=2,
@@ -277,6 +283,9 @@ class AudioDecisionAgent:
277
  if not chunks:
278
  return 0.5
279
 
 
 
 
280
  fake_probs = []
281
  for chunk in chunks:
282
  try:
 
45
  clip.close()
46
  return None, 0
47
 
48
+ # Cap at 30s — enough for detection, avoids slow extraction on long videos
49
+ MAX_AUDIO_SEC = 30
50
+ audio_clip = clip.audio
51
+ if clip.duration > MAX_AUDIO_SEC:
52
+ audio_clip = clip.audio.subclipped(0, MAX_AUDIO_SEC)
53
+
54
  # Write to temp WAV
55
  tmp_wav = tempfile.mktemp(suffix=".wav")
56
+ audio_clip.write_audiofile(
57
  tmp_wav,
58
  fps=self.TARGET_SR,
59
  nbytes=2,
 
283
  if not chunks:
284
  return 0.5
285
 
286
+ # Cap at 3 chunks max — Wav2Vec2 is slow on CPU, 30s of audio is enough
287
+ chunks = chunks[:3]
288
+
289
  fake_probs = []
290
  for chunk in chunks:
291
  try:
backend/detector.py CHANGED
@@ -968,7 +968,10 @@ class DeepfakeAuthenticator:
968
  face_crops_per_frame = face_future.result()
969
  if audio_future:
970
  try:
971
- audio_result = audio_future.result(timeout=30)
 
 
 
972
  except Exception as e:
973
  logger.warning(f"Audio analysis failed: {e}")
974
 
 
968
  face_crops_per_frame = face_future.result()
969
  if audio_future:
970
  try:
971
+ # Hard 20s timeout — never block the whole pipeline for audio
972
+ audio_result = audio_future.result(timeout=20)
973
+ except concurrent.futures.TimeoutError:
974
+ logger.warning("Audio analysis timed out after 20s — skipping")
975
  except Exception as e:
976
  logger.warning(f"Audio analysis failed: {e}")
977