281 caption switcher fix#282
Closed
maboa wants to merge 4 commits into
Closed
Conversation
populateCaptionEditor short-circuits and reuses the cached caption editor HTML whenever captionCache is non-null, which is the right behavior for preserving caption edits across transcript edits. The bug was that the cache was never invalidated when a fresh transcript was created (Deepgram/Whisper transcription, JSON/SRT/ VTT import), so switching to the caption page after transcribing a new file showed captions from the previous transcript. Listen for hyperaudioInit — which all three new-transcript paths already dispatch — and null captionCache. The localStorage load path keeps its own explicit invalidation since it loads its own captions, and the Regenerate button is unchanged.
Both Deepgram getData() and Whisper handleFormSubmission() write the "Transcribing…" loader to #hypertranscript and later write the final transcript to the same element. While the user is in caption mode, #hypertranscript is detached from the DOM, so the loader never shows and the result never lands. Programmatically click #transcript-editor-btn at the start of each transcribe flow. The button is disabled when the user is already in transcript view (set in index.html and on the transcript-editor click handler), so this is a no-op in transcript mode and switches back in caption mode.
The short-caption path (segment.chars < maxLineLength) computed its stop time as segment.start + segment.duration, but segment.duration is the sum of word durations — not the wall-clock span. When a segment contained silent gaps between words (e.g., 0–0.64s, then 1.12–1.6s, etc.), the stop time fell short of where the last word actually ends, and the caption text visibly outran its time range. Compute the stop time from the last word's start + duration instead, with fallbacks for missing word durations. The long-segment path already used per-word end times via lastOutTime and is unaffected.
Restore the descriptive comments and surrounding whitespace in populateCaptionEditor that were inadvertently removed alongside the cache-invalidation fix in 9e1f849. Leaves out the commented- out duplicate insertAdjacentElement line that was true dead code.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Three related caption-editor bugs surfaced while testing the Deepgram flow end-to-end.
1. Stale captions after a new transcript (
9e1f849)populateCaptionEditorshort-circuits on a non-nullcaptionCache, which is the right behavior for preserving user caption edits across transcript edits — butthe cache was never invalidated when a fresh transcript was produced. After running Deepgram or Whisper, or importing JSON/SRT/VTT, switching to the caption
page showed captions from the previous transcript.
Fix: invalidate
captionCacheon thehyperaudioInitevent, which all three "new transcript" code paths already dispatch. The localStorage load path managesits own cache (it loads captions alongside the transcript), so
hyperaudioTranscriptLoadedis intentionally not used as a trigger. The Regenerate button isunchanged.
2. Transcribing from caption mode produced no visible loader and no result (
1a4a7c7)Both
getData()(Deepgram) andhandleFormSubmission()(Whisper) write the "Transcribing…" loader and the final transcript to#hypertranscript. While theuser is in caption mode,
#hypertranscriptis detached from the DOM — so the loader never showed and the result never landed.Fix: programmatically click
#transcript-editor-btnat the start of each transcribe flow. The button isdisabledwhenever the user is already in transcriptview (initial HTML state + set explicitly on switch-back), so the click is a no-op in transcript mode and a clean mode-switch in caption mode.
3. Short-caption stop times were too early (
aab08a2)In
caption-modified.js, the short-caption path (segment.chars < maxLineLength) usedsegment.start + segment.durationfor the caption's stop time, wheresegment.durationis the sum of word durations. When a segment contained silent gaps between words, the sum was shorter than the wall-clock span, and thecaption text visibly outran its time range — e.g., "So group one is the first one." with a real end at 5.04s was emitted with an Out of 3.28s.
Fix: use the last word's actual end (
lastWord.start + lastWord.duration) for the stop time, with fallbacks for missing word durations. The long-segment pathalready used per-word end times via
lastOutTimeand was unaffected.Likely latent before #277 (which bumped the paragraph-break gap from 0.5s to 4.0s); short paragraphs rarely had large internal silent gaps so sum-of-durations ≈
span.
Test plan
confirm the resulting transcript renders.
(not the truncated sum-of-durations).