Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions __TEST__/caption.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -472,6 +472,22 @@ test("dualSpeakers: two speakers at most, whole sentences only, and the hyphen c
expect(lineTexts(run({ joinSentences: true, dualSpeakers: true }, 10, 5))).toEqual([["-Yes. No.", "-Fine."]]);
});

test("dualSpeakers: a turn without closing punctuation is no sentence, and shares with nothing (hyperaudio-lite-editor#749)", () => {
// a diarizer gave the one word opening "This is Marusa." to the other
// speaker: "This" neither joins the sentence before it nor opens a shared
// caption with the one after it
buildFromText("@Ann And we're sitting at Mozfest. @Bob This @Ann is Marusa.");
const result = run({ joinSentences: true, dualSpeakers: true });
expect(lineTexts(result)).toEqual([["And we're sitting at Mozfest."], ["This"], ["is Marusa."]]);
expect(result.data.map((c) => c.speakers)).toEqual([["Ann"], ["Bob"], ["Ann"]]);
// the same on the first side: a label cutting a sentence short
buildFromText("@Ann Ready @Bob Sure.");
expect(lineTexts(run({ dualSpeakers: true }))).toEqual([["Ready"], ["Sure."]]);
// a dotted abbreviation still closes a sentence, as the segmenter has it
buildFromText("@Ann See you at 5 p.m. @Bob Fine.");
expect(lineTexts(run({ dualSpeakers: true }))).toEqual([["-See you at 5 p.m.", "-Fine."]]);
});

test("dualSpeakers: paragraphBreaks wins, and a transcript with no labels is untouched", () => {
buildFromText("@Ann Ready? | @Bob Sure.");
expect(lineTexts(run({ dualSpeakers: true, paragraphBreaks: true }))).toEqual([["Ready?"], ["Sure."]]);
Expand Down
6 changes: 4 additions & 2 deletions js/caption.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,10 @@ export interface CaptionOptions {
paragraphBreaks?: boolean;
/**
* Two short sentences from different speakers may share a caption: two
* speakers at most, one per line, each line opening with a hyphen. A
* caption with one speaker never has a hyphen. `paragraphBreaks` wins.
* speakers at most, one per line, each line opening with a hyphen. Each
* line is a sentence closed by its own punctuation: a turn a label cut
* mid-sentence keeps its own caption. A caption with one speaker never
* has a hyphen. `paragraphBreaks` wins.
*/
dualSpeakers?: boolean;
/**
Expand Down
8 changes: 7 additions & 1 deletion js/caption.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*! (C) The Hyperaudio Project. MIT @license: en.wikipedia.org/wiki/MIT_License. */
/*! Version 2.3.0 */
/*! Version 2.3.1 */
'use strict';

const caption = function () {
Expand Down Expand Up @@ -305,6 +305,12 @@ const caption = function () {
const first = prev.text.replace(/\n+$/, '');
if (first.includes('\n')) return false;
if (('-' + first).length > maxLineLength || ('-' + text).length > maxLineLength) return false;
// Each side is a sentence, closed by its own punctuation. A segment a
// label closed mid-sentence - "This", where a diarizer gave the one
// word of "This is Marusa." to the other speaker - is a fragment, and
// keeps its own caption on either side (hyperaudio-lite-editor#749).
const closes = (line) => endsSentence(line.trim().split(/\s+/).pop(), null);
if (!closes(first) || !closes(text)) return false;
lineSpeakers.set(prev, [owner.get(prev) || '', segment.speakerName]);
prev.text = '-' + first + '\n-' + text;
prev.stop = formatSeconds(segmentStop);
Expand Down
Loading