From 407cc662e840ae55e6997e7fd5d19c1f0afd18f7 Mon Sep 17 00:00:00 2001 From: michael Date: Sun, 28 Dec 2025 15:27:04 -0600 Subject: [PATCH] fix: insert first AD cue at video start if no sentence break found MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When the first AD cue (index 0) cannot find a sentence boundary within the ±10s search window, insert the AD at T=0:00 instead of using the potentially mid-sentence Gemini pause point. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 --- backend/app/services/whisper_service.py | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/backend/app/services/whisper_service.py b/backend/app/services/whisper_service.py index 418a6d5..017b08d 100644 --- a/backend/app/services/whisper_service.py +++ b/backend/app/services/whisper_service.py @@ -241,8 +241,21 @@ class WhisperService: refined["original_pause_point"] = original # Preserve for debugging if warning: - warnings.append(f"Cue {placement['ad_cue_index']}: {warning}") - logger.warning(f"Pause point refinement warning for cue {placement['ad_cue_index']}: {warning}") + # Special handling for first AD cue: if no sentence break found, + # insert at the very beginning of the video to avoid mid-sentence insertion + if placement["ad_cue_index"] == 0: + refined["pause_point"] = 0.0 + warnings.append( + f"Cue 0: No sentence break found within search window of {original:.2f}s, " + "inserting AD at video start (0.0s)" + ) + logger.info( + f"First AD cue: No sentence break found near {original:.2f}s, " + "using video start (0.0s) to avoid mid-sentence insertion" + ) + else: + warnings.append(f"Cue {placement['ad_cue_index']}: {warning}") + logger.warning(f"Pause point refinement warning for cue {placement['ad_cue_index']}: {warning}") elif abs(snapped - original) > 0.1: logger.info( f"Refined pause point for cue {placement['ad_cue_index']}: "