Voice-to-text dictation app with local (Nvidia Parakeet/Whisper) and cloud models (BYOK). Privacy-first and available cross-platform.
JavaScript aianthropiccross-platformgeminigroqlinuxmacosnvidiaopen-sourceopenaiparakeetspeech-to-texttranscribewhisperwindows
fix(export): merge consecutive speaker-less segments within gap threshold (#1335)
Henry Su356753633a47
diff --git a/src/helpers/transcriptFormatter.js b/src/helpers/transcriptFormatter.jsindex ee4c8e9d5..5432539ed 100644--- a/src/helpers/transcriptFormatter.js+++ b/src/helpers/transcriptFormatter.js@@ -13,6 +13,14 @@ function resolveSpeaker(seg, speakerMappings) {return "Unknown Speaker";}+// Segments merge only when they resolve to the same display name, so the key has+// to cover every field resolveSpeaker reads — a manually named segment would+// otherwise absorb the un-named one beside it.+function speakerKey(seg) {+ const named = seg.speakerName && !seg.speakerIsPlaceholder ? seg.speakerName : "";+ return [seg.speaker || "", named, seg.speaker ? "" : seg.source || ""].join("\u0000");+}+function mergeSegments(segments) {const merged = [];let lastTimestamp = null;@@ -20,7 +28,7 @@ function mergeSegments(segments) {if (!seg.text?.trim()) continue;const ts = seg.timestamp || 0;const last = merged[merged.length - 1];- if (last && last.speaker === (seg.speaker || "") && ts - lastTimestamp < 2) {+ if (last && speakerKey(last) === speakerKey(seg) && ts - lastTimestamp < 2) {last.text = last.text + " " + seg.text.trim();last.endTimestamp = ts;} else {diff --git a/test/helpers/transcriptFormatter.test.js b/test/helpers/transcriptFormatter.test.jsindex c18858f8d..1635f473f 100644--- a/test/helpers/transcriptFormatter.test.js+++ b/test/helpers/transcriptFormatter.test.js@@ -124,3 +124,56 @@ test("JSON duration reflects the last merged segment's timestamp", () => {assert.equal(JSON.parse(output).metadata.duration_seconds, 3);});++test("consecutive speaker-less segments within 2s merge across SRT, TXT and Markdown exports", () => {+ const segments = [+ { timestamp: 0, text: "Hello world," },+ { timestamp: 1, text: "this is a test." },+ { timestamp: 5, text: "Later sentence." },+ ];++ const srtOutput = formatSrt(segments, {});+ assert.match(+ srtOutput,+ /^1\n00:00:00,000 --> 00:00:05,000\nUnknown Speaker: Hello world, this is a test\./+ );+ assert.match(srtOutput, /\n2\n00:00:05,000 --> 00:00:08,000\nUnknown Speaker: Later sentence\./);++ const txtOutput = formatTxt(+ { title: "Test Note", created_at: "2026-01-01T00:00:00Z" },+ segments,+ {}+ );+ assert.ok(txtOutput.includes("[00:00:00] Unknown Speaker:\nHello world, this is a test."));+ assert.ok(txtOutput.includes("[00:00:05] Unknown Speaker:\nLater sentence."));++ const mdOutput = formatMd(+ { title: "Test Note", created_at: "2026-01-01T00:00:00Z" },+ segments,+ {}+ );+ assert.ok(mdOutput.includes("**Unknown Speaker** `00:00:00`\nHello world, this is a test."));+ assert.ok(mdOutput.includes("**Unknown Speaker** `00:00:05`\nLater sentence."));+});++test("a manually named segment does not absorb the adjacent un-named one", () => {+ const segments = [+ {+ source: "mic",+ timestamp: 0,+ text: "Alice said this.",+ speakerName: "Alice",+ speakerIsPlaceholder: false,+ },+ { source: "mic", timestamp: 1, text: "And this is me talking." },+ ];++ const txtOutput = formatTxt(+ { title: "Test Note", created_at: "2026-01-01T00:00:00Z" },+ segments,+ {}+ );++ assert.ok(txtOutput.includes("[00:00:00] Alice:\nAlice said this."));+ assert.ok(txtOutput.includes("[00:00:01] You:\nAnd this is me talking."));+});