Skip to content

caption.js 2.3.0: dual-speaker captions, leading sentences, and the speaker of each line - #292

Merged
maboa merged 1 commit into
mainfrom
feat/291-dual-speaker-captions
Sep 21, 2026
Merged

maboa merged 1 commit into
mainfrom
feat/291-dual-speaker-captions

Conversation

@maboa

@maboa maboa commented Sep 21, 2026

Copy link
Copy Markdown
Member

Closes #291.

Follows #289. With joinSentences on, a short sentence could still end up alone in a caption in two cases. The opening of an interview shows both:

[speaker-A] to start?
[speaker-B] Sure. So to start off, Dr. Ashby, can you just introduce yourself…

This generated to start? · Sure. · So to start off, Dr. Ashby,

dualSpeakers Two short sentences from different speakers share a caption, in the Netflix form: two speakers at most, one per line, each of the two lines opening with a hyphen and no space (-to start? / -Sure.). The hyphen marks two speakers sharing a caption, not a change of speaker, so a caption with one speaker never has one. Each side is one speaker's whole sentences. The tail of a long sentence cannot be a side. The hyphen counts towards the line length, a third turn starts a new caption, and paragraphBreaks wins.
leadSentences A short sentence (shorter than minLength) that could not join the caption before it is laid out as one run with the long sentence after it, when both are one speaker's and within maxJoinGap. This is never done across a speaker label or a paragraph that must break. Joining backwards comes first. No sentence is split that would not have been, because the long sentence is divided across captions either way.
speakers Every cue in result.data now carries the speaker of each of its lines (["speaker-A", "speaker-B"], or "" where the transcript names none). The speaker is carried through the whole turn, since previously only the sentence a label opened knew its speaker. [Ann] and Ann: both read as Ann. This is groundwork for #284.

Compatibility. With neither option given, vtt, srt and every cue's text are what 2.2.0 generated. The only difference is the additive speakers field. A label still ends ordinary joining, as before, including one that repeats the speaker already talking. A test pins this.

With leadSentences, the line break still falls where the splitter puts it. The opening above becomes Sure. So to start off, / Dr. Ashby, can you just, because a comma past minLength is a preferred break.

caption.d.ts and the README document the options and the field. There are 9 new tests. The caption suite is 37/37 and the whole suite is 98/98. The version header moves to 2.3.0. changelog.md and the package version are left for the release commit.

Companion: hyperaudio/hyperaudio-lite-editor#666.

…peaker of each line

With joinSentences on, a short sentence could still end up alone in a
caption: when it opened another speaker's turn, since a label always
started a new caption, and when the sentence after it was too long to
share one, since joining only worked backwards.

- dualSpeakers: two short sentences from different speakers share a
  caption in the Netflix form - two speakers at most, one per line,
  each line opening with a hyphen. A caption with one speaker never has
  a hyphen. Each side is one speaker's whole sentences, the hyphen
  counts towards the line length, and paragraphBreaks wins.
- leadSentences: a short sentence that could not join the caption
  before it is laid out as one run with the long sentence after it,
  when both are one speaker's and within maxJoinGap.
- Every cue in result.data carries speakers, the speaker of each of its
  lines, carried through the whole turn.

With neither option given, the captions are what 2.2.0 generated; the
speakers field is the only difference.

Closes #291
@maboa
maboa merged commit 0b1bc4a into main Sep 21, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

caption.js: dual-speaker captions, a short sentence leading the long one after it, and the speaker of each line in the result

1 participant