Detect Scribe hallucinations + filter from SRT + auto-retry

Bug found in Žena ME TEPE third re-test:
- Scribe transcribed only verse 1 (0-33s) properly
- Then returned a single 98s segment [34.7-133.2] with just 1 word 'sam'
- This is a known Scribe hallucination on instrumental sections
- Result: SRT showed 'SAM SAM SAM SAM...' 14 times across the chorus
- Looked completely wrong because the chorus audio was correct but
  subtitles showed 'SAM' repeatedly

Three-part fix:

1. SRT GENERATOR: skip segments > 15s with < 5 words.
   These are hallucinations and have no real transcription value.

2. SCRIBE TRANSCRIBE: detect hallucinations in returned segments.
   - Mark segments > 15s with < 5 words as hallucinations
   - Compute true coverage % (excluding hallucinations)
   - Add _hallucination_count and _coverage_pct to result

3. TRANSCRIBE_FULL: auto-retry Scribe if quality is poor.
   - If hallucinations detected OR coverage < 50%, retry once
   - Keep retry result only if it has better stats
   - Otherwise fall back to first attempt (still better than nothing)

This makes the pipeline robust against Scribe's occasional bad transcripts
on songs with long instrumental breaks. Most second attempts succeed
where the first failed (random Scribe variance).
This commit is contained in:
2026-04-29 18:08:35 +00:00
parent d3b71942d2
commit df6011c3cf
2 changed files with 57 additions and 0 deletions
+12
View File
@@ -230,6 +230,18 @@ def generate_srt_from_segments(segments, clip_start, clip_end, output_path):
if s_end <= clip_start or s_start >= clip_end:
continue
# ── HALLUCINATION FILTER ──
# STT (Scribe, Whisper) občasno halucinira pri dolgih instrumentalih:
# vrne segment 60-100s z 1-2 besedama. Tak segment ne smemo dati v SRT.
# Pravilo: če je segment > 15s IN ima < 5 besed (ali words array < 5),
# je verjetno halucinacija.
seg_dur = s_end - s_start
word_count = len(words) if words else len(text.split())
if seg_dur > 15 and word_count < 5:
print(f"[SRT] Preskočil halucinacijski segment [{s_start:.1f}-{s_end:.1f}] "
f"({seg_dur:.1f}s, {word_count} besed): {text[:50]!r}", flush=True)
continue
# Če segment delno štrli iz clip range-a IN imamo word-level timestampe,
# uporabi samo tiste besede ki dejansko padejo v clip range
# (sicer subtitle vsebuje besedilo iz prejšnjega/naslednjega refrena/verza)