Skip to content

Voice-to-text dictation app with local (Nvidia Parakeet/Whisper) and cloud models (BYOK). Privacy-first and available cross-platform.

fix(diarization): diarize the mic track for in-person meetings — fixes #1627

Gabriel Stein0a10184c3a40
diff --git a/src/helpers/diarization.js b/src/helpers/diarization.js
index f8906a0d5..63b364aee 100644
--- a/src/helpers/diarization.js
+++ b/src/helpers/diarization.js
@@ -430,7 +430,7 @@ class DiarizationManager {
return segments.map((s) => (keep.has(s.speaker) ? s : { ...s, speaker: primary }));
}
- mergeWithTranscript(transcriptSegments, diarizationSegments) {
+ mergeWithTranscript(transcriptSegments, diarizationSegments, { diarizedSource = "system" } = {}) {
if (!transcriptSegments || transcriptSegments.length === 0) return [];
const deduped = dedupeMicAgainstSystem(transcriptSegments);
if (!diarizationSegments || diarizationSegments.length === 0) {
@@ -446,10 +446,15 @@ class DiarizationManager {
idx++;
}
- const nextSystemTimestampAt = (startIndex) => {
+ // Mic-mode softening: a single cluster on a mic-only session is the user
+ // talking alone (e.g. a call where the remote never spoke audibly), so it
+ // stays "you" instead of becoming a stranger's speaker_0.
+ const micSingleCluster = diarizedSource === "mic" && speakerSet.size === 1;
+
+ const nextTimestampAt = (startIndex, source) => {
for (let i = startIndex + 1; i < deduped.length; i += 1) {
const candidate = deduped[i];
- if (candidate.source === "system" && candidate.timestamp != null) {
+ if (candidate.source === source && candidate.timestamp != null) {
return candidate.timestamp;
}
}
@@ -459,7 +464,7 @@ class DiarizationManager {
return deduped.map((seg, index) => {
const enriched = { ...seg };
- if (seg.source === "mic") {
+ if (seg.source === "mic" && (diarizedSource !== "mic" || micSingleCluster)) {
applyConfirmedSpeaker(enriched, {
speaker: "you",
speakerIsPlaceholder: false,
@@ -467,9 +472,9 @@ class DiarizationManager {
return enriched;
}
- if (seg.source === "system" && seg.timestamp != null) {
+ if (seg.source === diarizedSource && seg.timestamp != null) {
const segStart = seg.timestamp;
- const segEnd = nextSystemTimestampAt(index) ?? segStart + 2.5;
+ const segEnd = nextTimestampAt(index, diarizedSource) ?? segStart + 2.5;
const midpoint = segStart + (segEnd - segStart) / 2;
let overlapSpeaker = null;
let nearestSpeaker = null;
diff --git a/src/helpers/ipcHandlers.js b/src/helpers/ipcHandlers.js
index 00df09ea5..a3d16a1fe 100644
--- a/src/helpers/ipcHandlers.js
+++ b/src/helpers/ipcHandlers.js
@@ -75,7 +75,13 @@ const {
selectRacingMicEntryIndices,
partitionOverlappingPendingMicFinals,
} = require("./meetingMicHoldback");
-const { computeChunkStats, resolveMicChunkAction } = require("./meetingMicGate");
+const {
+ computeChunkStats,
+ resolveMicChunkAction,
+ MEETING_MIC_SILENCE_RMS,
+ MEETING_MIC_SILENCE_PEAK,
+} = require("./meetingMicGate");
+const { resolveDiarizationInput } = require("./meetingDiarizationInput");
const { applySmartSpacing } = require("./smartSpacing");
const { applyAutoLearnSetting } = require("./autoLearnSetting");
const {
@@ -5665,17 +5671,42 @@ class IPCHandlers {
};
const captureMeetingDiarizationState = async () => {
- const diarizationPcmPath = meetingDiarizationPath;
+ const systemPcmPath = meetingDiarizationPath;
+ const systemStartedAt = meetingDiarizationStartedAt;
+ const micPcmPath = meetingMicDiarizationPath;
+ const micStartedAt = meetingMicDiarizationStartedAt;
+ const systemAudioHeard = meetingSystemAudioHeard;
const diarizationSegments = meetingDiarizationSegments;
- const diarizationStartedAt = meetingDiarizationStartedAt;
if (meetingDiarizationStream) {
await new Promise((resolve) => meetingDiarizationStream.end(resolve));
meetingDiarizationStream = null;
}
+ if (meetingMicDiarizationStream) {
+ await new Promise((resolve) => meetingMicDiarizationStream.end(resolve));
+ meetingMicDiarizationStream = null;
+ }
meetingDiarizationPath = null;
meetingDiarizationStartedAt = null;
+ meetingMicDiarizationPath = null;
+ meetingMicDiarizationStartedAt = null;
+ meetingSystemAudioHeard = false;
meetingDiarizationSegments = [];
- return { diarizationPcmPath, diarizationSegments, diarizationStartedAt };
+ const { pcmPath, startedAt, diarizedSource, cleanupPcmPaths } = resolveDiarizationInput({
+ systemPcmPath,
+ micPcmPath,
+ systemAudioHeard,
+ systemStartedAt,
+ micStartedAt,
+ });
+ for (const stalePath of cleanupPcmPaths) {
+ fs.unlink(stalePath, () => {});
+ }
+ return {
+ diarizationPcmPath: pcmPath,
+ diarizationSegments,
+ diarizationStartedAt: startedAt,
+ diarizedSource,
+ };
};
const attachMeetingStreamingHandlers = (streaming, win, source) => {
@@ -6175,6 +6206,12 @@ class IPCHandlers {
let meetingDiarizationStream = null;
let meetingDiarizationPath = null;
let meetingDiarizationStartedAt = null;
+ // Parallel raw mic capture so an in-person session (no audible system
+ // audio) can be diarized; dropped as soon as the session proves to be a call.
+ let meetingMicDiarizationStream = null;
+ let meetingMicDiarizationPath = null;
+ let meetingMicDiarizationStartedAt = null;
+ let meetingSystemAudioHeard = false;
let meetingDiarizationSegments = [];
let meetingLiveSpeakerActive = false;
let meetingLiveSpeakerState = null;
@@ -6717,6 +6754,18 @@ class IPCHandlers {
}
};
+ const dropMeetingMicDiarizationCapture = () => {
+ if (meetingMicDiarizationStream) {
+ meetingMicDiarizationStream.end();
+ meetingMicDiarizationStream = null;
+ }
+ if (meetingMicDiarizationPath) {
+ fs.unlink(meetingMicDiarizationPath, () => {});
+ meetingMicDiarizationPath = null;
+ }
+ meetingMicDiarizationStartedAt = null;
+ };
+
const resetMeetingLocalState = () => {
if (meetingLocalTimer) {
clearInterval(meetingLocalTimer);
@@ -6744,6 +6793,8 @@ class IPCHandlers {
meetingDiarizationPath = null;
}
meetingDiarizationStartedAt = null;
+ dropMeetingMicDiarizationCapture();
+ meetingSystemAudioHeard = false;
meetingDiarizationSegments = [];
meetingLocalWin = null;
meetingLocalTranscript = "";
@@ -7262,11 +7313,38 @@ class IPCHandlers {
meetingDiarizationStartedAt = receivedAt;
}
meetingDiarizationStream.write(outboundBuffer);
+
+ if (!meetingSystemAudioHeard) {
+ const { rms, peak } = computeChunkStats(outboundBuffer);
+ if (rms >= MEETING_MIC_SILENCE_RMS || peak >= MEETING_MIC_SILENCE_PEAK) {
+ // A call is audibly underway: diarization stays on the system
+ // channel, so stop paying the mic capture's disk cost.
+ meetingSystemAudioHeard = true;
+ dropMeetingMicDiarizationCapture();
+ }
+ }
+
dispatchMeetingAudioBuffer(outboundBuffer, "system");
return;
}
if (source === "mic") {
+ // Until the session proves to be a call (audible system audio), keep a
+ // raw mic capture so an in-person recording can be diarized. Written
+ // pre-AEC/pre-gate so the timeline stays continuous, like the system
+ // capture above.
+ if (!meetingSystemAudioHeard) {
+ if (!meetingMicDiarizationStream) {
+ meetingMicDiarizationPath = path.join(
+ os.tmpdir(),
+ `ow-diarize-raw-mic-${Date.now()}.pcm`
+ );
+ meetingMicDiarizationStream = fs.createWriteStream(meetingMicDiarizationPath);
+ meetingMicDiarizationStartedAt = Date.now();
+ }
+ meetingMicDiarizationStream.write(outboundBuffer);
+ }
+
if (processMeetingMicWithAec(outboundBuffer)) {
return;
}
@@ -7437,7 +7515,7 @@ class IPCHandlers {
debugLogger.error("Local meeting final transcription failed", { error: err.message });
}
flushPendingMicFinals(true);
- const { diarizationPcmPath, diarizationSegments, diarizationStartedAt } =
+ const { diarizationPcmPath, diarizationSegments, diarizationStartedAt, diarizedSource } =
await captureMeetingDiarizationState();
const transcript =
buildOrderedTranscriptText(diarizationSegments) || meetingLocalTranscript;
@@ -7455,14 +7533,15 @@ class IPCHandlers {
diarizationWin,
liveSpeakerState,
sessionSpeakerConfigSnapshot,
- noteIdSnapshot
+ noteIdSnapshot,
+ diarizedSource
);
return { success: true, transcript, diarizationSessionId };
}
const results = await disconnectMeetingStreaming({ flushPending: true });
- const { diarizationPcmPath, diarizationSegments, diarizationStartedAt } =
+ const { diarizationPcmPath, diarizationSegments, diarizationStartedAt, diarizedSource } =
await captureMeetingDiarizationState();
const transcript =
buildOrderedTranscriptText(diarizationSegments) ||
@@ -7481,7 +7560,8 @@ class IPCHandlers {
diarizationWin,
liveSpeakerState,
sessionSpeakerConfigSnapshot,
- noteIdSnapshot
+ noteIdSnapshot,
+ diarizedSource
);
return { success: true, transcript, diarizationSessionId };
@@ -10251,7 +10331,7 @@ class IPCHandlers {
return reconciledSpeakers;
}
- _resolveSpeakerExpectation({ sessionConfig, noteId, observedSpeakerIds }) {
+ _resolveSpeakerExpectation({ sessionConfig, noteId, observedSpeakerIds, diarizedSource }) {
// Only a count the user set explicitly outranks the note: participants added
// mid-meeting postdate the config snapshot taken at recording start.
let expectedTotal = sessionConfig?.explicit ? sessionConfig.expectedCount : null;
@@ -10264,9 +10344,14 @@ class IPCHandlers {
}
}
+ // Diarizing the mic track (in-person session) means the user is one of the
+ // diarized voices, so the expected total applies without the -1 the
+ // system-audio branches use.
+ const micMode = diarizedSource === "mic";
+
if (expectedTotal) {
const total = Math.min(expectedTotal, MAX_SPEAKER_COUNT);
- const numSpeakers = Math.max(1, total - 1);
+ const numSpeakers = micMode ? total : Math.max(1, total - 1);
return { numSpeakers, cap: numSpeakers };
}
@@ -10275,6 +10360,10 @@ class IPCHandlers {
return { numSpeakers, cap: numSpeakers };
}
+ if (micMode) {
+ return { numSpeakers: -1, cap: DEFAULT_EXPECTED_SPEAKER_COUNT };
+ }
+
// Only system audio reaches the diarizer (the mic track is "you"), so the cap
// counts other speakers — same total - 1 basis as the branches above.
return { numSpeakers: -1, cap: Math.max(1, DEFAULT_EXPECTED_SPEAKER_COUNT - 1) };
@@ -10288,7 +10377,8 @@ class IPCHandlers {
win,
liveSpeakerState = null,
sessionConfig = null,
- noteId = null
+ noteId = null,
+ diarizedSource = "system"
) {
const send = (payload) => {
if (win && !win.isDestroyed()) {
@@ -10333,6 +10423,7 @@ class IPCHandlers {
sessionConfig,
noteId,
observedSpeakerIds,
+ diarizedSource,
});
let diarizationSegments = await this.diarizationManager.diarize(
tmpWav,
@@ -10347,7 +10438,7 @@ class IPCHandlers {
const startMs =
(Number.isFinite(audioStartedAt) && audioStartedAt) ||
- transcriptSegments.find((segment) => segment.source === "system")?.timestamp ||
+ transcriptSegments.find((segment) => segment.source === diarizedSource)?.timestamp ||
transcriptSegments[0]?.timestamp ||
0;
const isEpochMs = startMs > 1e9;
@@ -10363,7 +10454,8 @@ class IPCHandlers {
const enrichedSegments = this.diarizationManager.mergeWithTranscript(
normalized,
- diarizationSegments
+ diarizationSegments,
+ { diarizedSource }
);
const speakerSet = new Set(diarizationSegments.map((d) => d.speaker));
diff --git a/src/helpers/meetingDiarizationInput.js b/src/helpers/meetingDiarizationInput.js
new file mode 100644
index 000000000..df6c36661
--- /dev/null
+++ b/src/helpers/meetingDiarizationInput.js
@@ -0,0 +1,34 @@
+/**
+ * Pure input-selection policy for post-meeting diarization.
+ *
+ * A meeting session records two parallel raw PCM captures: the system-audio
+ * tap (calls) and the microphone (in-person sessions, kept only until system
+ * audio turns audible). At stop, exactly one of them feeds the diarizer and
+ * the other is deleted. Call sessions keep today's behavior: any session that
+ * heard audible system audio diarizes the system channel.
+ */
+function resolveDiarizationInput({
+ systemPcmPath = null,
+ micPcmPath = null,
+ systemAudioHeard = false,
+ systemStartedAt = null,
+ micStartedAt = null,
+} = {}) {
+ if (systemAudioHeard || !micPcmPath) {
+ return {
+ pcmPath: systemPcmPath,
+ startedAt: systemStartedAt,
+ diarizedSource: "system",
+ cleanupPcmPaths: micPcmPath ? [micPcmPath] : [],
+ };
+ }
+
+ return {
+ pcmPath: micPcmPath,
+ startedAt: micStartedAt,
+ diarizedSource: "mic",
+ cleanupPcmPaths: systemPcmPath ? [systemPcmPath] : [],
+ };
+}
+
+module.exports = { resolveDiarizationInput };
diff --git a/test/helpers/diarizationSpeakerMerge.test.js b/test/helpers/diarizationSpeakerMerge.test.js
index a3e0ffee6..dd57f4b8f 100644
--- a/test/helpers/diarizationSpeakerMerge.test.js
+++ b/test/helpers/diarizationSpeakerMerge.test.js
@@ -18,6 +18,7 @@ require.cache[require.resolve("electron")] = {
const DiarizationManager = require("../../src/helpers/diarization.js");
const systemSegment = (timestamp, text) => ({ source: "system", timestamp, text });
+const micSegment = (timestamp, text) => ({ source: "mic", timestamp, text });
test("a segment between clusters takes the nearest cluster, not the first", () => {
const manager = new DiarizationManager();
@@ -77,3 +78,88 @@ test("mic segments stay owned by you and survive an empty diarization run", () =
const withoutClusters = manager.mergeWithTranscript([systemSegment(1, "morning")], []);
assert.equal(withoutClusters[0].speaker, undefined);
});
+
+test("mic segments stay owned by you under an explicit system diarizedSource", () => {
+ const manager = new DiarizationManager();
+
+ const merged = manager.mergeWithTranscript(
+ [micSegment(1, "morning")],
+ [{ start: 0, end: 5, speaker: "speaker_0" }],
+ { diarizedSource: "system" }
+ );
+
+ assert.equal(merged[0].speaker, "you");
+});
+
+test("mic mode assigns mic segments to clusters by overlap and nearest distance", () => {
+ const manager = new DiarizationManager();
+
+ const merged = manager.mergeWithTranscript(
+ [
+ micSegment(1, "so what did everyone think of the draft"),
+ // Midpoint 51.25s: 46.25s past speaker_00, 8.75s before speaker_01.
+ micSegment(50, "honestly the second section needs work"),
+ ],
+ [
+ { start: 0, end: 5, speaker: "speaker_00" },
+ { start: 60, end: 70, speaker: "speaker_01" },
+ ],
+ { diarizedSource: "mic" }
+ );
+
+ assert.equal(merged[0].speaker, "speaker_0");
+ assert.equal(merged[1].speaker, "speaker_1");
+});
+
+test("mic mode with a single cluster keeps the mic track as you", () => {
+ // A call where the remote party never speaks audibly diarizes the mic track;
+ // its lone cluster is the user, not a stranger named speaker_0.
+ const manager = new DiarizationManager();
+
+ const merged = manager.mergeWithTranscript(
+ [micSegment(1, "hello can you hear me"), micSegment(30, "okay I will follow up by email")],
+ [{ start: 0, end: 40, speaker: "speaker_00" }],
+ { diarizedSource: "mic" }
+ );
+
+ assert.equal(merged[0].speaker, "you");
+ assert.equal(merged[1].speaker, "you");
+});
+
+test("mic mode leaves system segments unlabeled", () => {
+ const manager = new DiarizationManager();
+
+ const merged = manager.mergeWithTranscript(
+ [systemSegment(1, "notification ding"), micSegment(2, "as I was saying")],
+ [
+ { start: 0, end: 5, speaker: "speaker_00" },
+ { start: 10, end: 20, speaker: "speaker_01" },
+ ],
+ { diarizedSource: "mic" }
+ );
+
+ assert.equal(merged[0].speaker, undefined);
+ assert.equal(merged[1].speaker, "speaker_0");
+});
+
+test("mic mode still dedupes bleed-flagged mic echoes of system text first", () => {
+ const manager = new DiarizationManager();
+
+ const merged = manager.mergeWithTranscript(
+ [
+ systemSegment(10, "the quarterly revenue forecast slipped again"),
+ {
+ ...micSegment(10.5, "the quarterly revenue forecast slipped again"),
+ likelyRenderBleed: true,
+ },
+ ],
+ [
+ { start: 0, end: 5, speaker: "speaker_00" },
+ { start: 10, end: 20, speaker: "speaker_01" },
+ ],
+ { diarizedSource: "mic" }
+ );
+
+ assert.equal(merged.length, 1);
+ assert.equal(merged[0].source, "system");
+});
diff --git a/test/helpers/meetingDiarizationInput.test.js b/test/helpers/meetingDiarizationInput.test.js
new file mode 100644
index 000000000..ce272aea6
--- /dev/null
+++ b/test/helpers/meetingDiarizationInput.test.js
@@ -0,0 +1,85 @@
+const test = require("node:test");
+const assert = require("node:assert/strict");
+
+const { resolveDiarizationInput } = require("../../src/helpers/meetingDiarizationInput");
+
+test("audible system audio diarizes the system capture", () => {
+ const input = resolveDiarizationInput({
+ systemPcmPath: "/tmp/ow-diarize-raw-1.pcm",
+ micPcmPath: "/tmp/ow-diarize-raw-mic-1.pcm",
+ systemAudioHeard: true,
+ systemStartedAt: 1000,
+ micStartedAt: 900,
+ });
+
+ assert.deepEqual(input, {
+ pcmPath: "/tmp/ow-diarize-raw-1.pcm",
+ startedAt: 1000,
+ diarizedSource: "system",
+ cleanupPcmPaths: ["/tmp/ow-diarize-raw-mic-1.pcm"],
+ });
+});
+
+test("a silent system capture yields to the mic capture", () => {
+ const input = resolveDiarizationInput({
+ systemPcmPath: "/tmp/ow-diarize-raw-1.pcm",
+ micPcmPath: "/tmp/ow-diarize-raw-mic-1.pcm",
+ systemAudioHeard: false,
+ systemStartedAt: 1000,
+ micStartedAt: 900,
+ });
+
+ assert.deepEqual(input, {
+ pcmPath: "/tmp/ow-diarize-raw-mic-1.pcm",
+ startedAt: 900,
+ diarizedSource: "mic",
+ cleanupPcmPaths: ["/tmp/ow-diarize-raw-1.pcm"],
+ });
+});
+
+test("a silent system capture with no mic capture keeps today's system path", () => {
+ const input = resolveDiarizationInput({
+ systemPcmPath: "/tmp/ow-diarize-raw-1.pcm",
+ micPcmPath: null,
+ systemAudioHeard: false,
+ systemStartedAt: 1000,
+ micStartedAt: null,
+ });
+
+ assert.deepEqual(input, {
+ pcmPath: "/tmp/ow-diarize-raw-1.pcm",
+ startedAt: 1000,
+ diarizedSource: "system",
+ cleanupPcmPaths: [],
+ });
+});
+
+test("no capture at all skips diarization without cleanup work", () => {
+ const input = resolveDiarizationInput({});
+
+ assert.deepEqual(input, {
+ pcmPath: null,
+ startedAt: null,
+ diarizedSource: "system",
+ cleanupPcmPaths: [],
+ });
+});
+
+test("mic-only capture (no system channel) diarizes the mic", () => {
+ // Linux "unsupported" system-audio mode never delivers a system chunk, so
+ // only the mic capture exists.
+ const input = resolveDiarizationInput({
+ systemPcmPath: null,
+ micPcmPath: "/tmp/ow-diarize-raw-mic-1.pcm",
+ systemAudioHeard: false,
+ systemStartedAt: null,
+ micStartedAt: 900,
+ });
+
+ assert.deepEqual(input, {
+ pcmPath: "/tmp/ow-diarize-raw-mic-1.pcm",
+ startedAt: 900,
+ diarizedSource: "mic",
+ cleanupPcmPaths: [],
+ });
+});