Skip to content

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

fix(meetings): align mic to the system reference on Windows and Linux helpers (#2818)

Chad Piha0944cb111c8b
diff --git a/src/helpers/debugLogger.js b/src/helpers/debugLogger.js
index 3f87b85d5..bdd242654 100644
--- a/src/helpers/debugLogger.js
+++ b/src/helpers/debugLogger.js
@@ -1,4 +1,5 @@
const fs = require("fs");
+const os = require("os");
const path = require("path");
const { app } = require("electron");
@@ -76,6 +77,11 @@ class DebugLogger {
this.info("System Info", {
appVersion: app.getVersion(),
platform: process.platform,
+ // The OS build decides which system-audio capture a meeting can use
+ // (Windows process loopback needs 10 2004+, the macOS tap 14.2+).
+ osRelease: os.release(),
+ osVersion: os.version(),
+ arch: process.arch,
nodeVersion: process.version,
electronVersion: process.versions.electron,
appPath: app.getAppPath(),
diff --git a/src/helpers/ipcHandlers.js b/src/helpers/ipcHandlers.js
index 340173915..61efd1e59 100644
--- a/src/helpers/ipcHandlers.js
+++ b/src/helpers/ipcHandlers.js
@@ -7910,8 +7910,6 @@ class IPCHandlers {
return { mode, strategy: "unsupported" };
};
- const hasNativeMeetingSystemAudio = () => getMeetingSystemAudioMode() === "native";
-
const isMeetingStreamingConnected = (systemAudioMode = getMeetingSystemAudioCapabilityMode()) =>
!!this._meetingMicStreaming?.isConnected &&
(systemAudioMode === "unsupported" || !!this._meetingSystemStreaming?.isConnected);
@@ -7990,13 +7988,28 @@ class IPCHandlers {
return win;
};
- const MEETING_MIC_REFERENCE_ALIGNMENT_MS = 320;
+ // System audio captured in main (the macOS tap, the Windows and Linux
+ // helpers) arrives on its own schedule, unsynchronized with the renderer's
+ // mic, so mic chunks wait for that reference before echo analysis. Each
+ // waits only as long as its reference lags: the echo detector searches
+ // 500 ms back, and every millisecond held comes out of what's left for
+ // speaker latency.
+ const MEETING_MIC_REFERENCE_ALIGNMENT_MS = {
+ native: 320,
+ "wasapi-loopback": 100,
+ "pipewire-loopback": 100,
+ };
+ // Only a reference chunk received this recently holds the mic, so a capture
+ // that stopped or went idle doesn't delay it.
+ const MEETING_MIC_REFERENCE_RECENT_MS = 1000;
const MEETING_STARTUP_WARMUP_MS = 1500;
const MEETING_MIC_BLEED_LOOKBACK_MS = 500;
const MEETING_MIC_STATS_LOG_LIMIT = 200;
const MEETING_SYSTEM_AUDIO_SILENCE_WARNING_MS = 45000;
const MEETING_SYSTEM_AUDIO_TICK_MS = 2000;
let meetingMicStatsLogCount = 0;
+ let meetingSystemAudioStrategy = null;
+ let meetingSystemChunkReceivedAt = null;
let meetingSystemAudioSilenceTimer = null;
let meetingSystemAudioTicker = null;
let meetingSystemAudioWatchdogWin = null;
@@ -8264,9 +8277,13 @@ class IPCHandlers {
}
const now = Date.now();
+ const holdMs =
+ force || !meetingMicNeedsReferenceAlignment()
+ ? 0
+ : MEETING_MIC_REFERENCE_ALIGNMENT_MS[meetingSystemAudioStrategy];
while (meetingPendingMicChunks.length > 0) {
const next = meetingPendingMicChunks[0];
- if (!force && now - next.queuedAt < MEETING_MIC_REFERENCE_ALIGNMENT_MS) {
+ if (holdMs && now - next.queuedAt < holdMs) {
break;
}
@@ -8286,6 +8303,20 @@ class IPCHandlers {
}
};
+ const meetingMicNeedsReferenceAlignment = () =>
+ Object.hasOwn(MEETING_MIC_REFERENCE_ALIGNMENT_MS, meetingSystemAudioStrategy) &&
+ meetingSystemChunkReceivedAt !== null &&
+ Date.now() - meetingSystemChunkReceivedAt < MEETING_MIC_REFERENCE_RECENT_MS;
+
+ const setMeetingSystemAudioStrategy = (strategy) => {
+ meetingSystemAudioStrategy = strategy;
+ // A capture that fell back no longer delivers the reference these
+ // chunks are waiting for, so release them now.
+ if (!meetingMicNeedsReferenceAlignment()) {
+ flushPendingMeetingMicChunks(true);
+ }
+ };
+
const processMeetingMicWithAec = (buffer) => {
if (!meetingAecEnabled) {
return false;
@@ -8683,6 +8714,7 @@ class IPCHandlers {
meetingLocalModel = null;
meetingLocalLanguage = null;
meetingPendingMicChunks = [];
+ meetingSystemChunkReceivedAt = null;
resetPendingMicFinals();
meetingAecEnabled = false;
meetingStartedAt = null;
@@ -8816,8 +8848,10 @@ class IPCHandlers {
this._meetingMicStreaming = null;
this._meetingSystemStreaming = null;
meetingSendCounts = { mic: 0, system: 0 };
+ meetingMicStatsLogCount = 0;
meetingLiveSpeakerStartedAt = null;
meetingPendingMicChunks = [];
+ meetingSystemChunkReceivedAt = null;
resetPendingMicFinals();
meetingAecEnabled = false;
meetingEchoLeakDetector.reset();
@@ -9230,6 +9264,7 @@ class IPCHandlers {
// Auto-end stays fail-safe until the renderer confirms a real source.
systemAudioAvailable: false,
});
+ setMeetingSystemAudioStrategy(result.systemAudioStrategy);
// Arms on any active system-audio strategy — capture follows platform
// capability, not call detection — so the warning copy also covers
// in-person recordings where a silent system tap is expected.
@@ -9247,6 +9282,7 @@ class IPCHandlers {
try {
const systemAudioPlan = await getMeetingSystemAudioPlan({ refreshWindowsCapability: true });
let { mode: systemAudioMode, strategy: systemAudioStrategy } = systemAudioPlan;
+ setMeetingSystemAudioStrategy(systemAudioStrategy);
const requestedConnectionKey = getMeetingConnectionKey(options, credentialGeneration);
meetingEchoLeakDetector.reset();
meetingOneOnOneAttendee = resolveOneOnOneAttendeeForNote(options.noteId);
@@ -9375,6 +9411,7 @@ class IPCHandlers {
// evidence or an AEC reference for the mic arriving now.
if (!synthetic) {
meetingEchoLeakDetector.recordSystemChunk(outboundBuffer, receivedAt);
+ meetingSystemChunkReceivedAt = receivedAt;
if (meetingAecEnabled && !this.meetingAecManager?.processSystemBuffer(outboundBuffer)) {
meetingAecEnabled = false;
}
@@ -9438,19 +9475,6 @@ class IPCHandlers {
return;
}
- if (!hasNativeMeetingSystemAudio()) {
- const analysis = meetingEchoLeakDetector.analyzeMicChunk(outboundBuffer);
- if (analysis?.shouldMute && !meetingAecEnabled) {
- if (!meetingLocalMode) {
- dispatchMeetingAudioBuffer(Buffer.alloc(outboundBuffer.length), "mic");
- }
- return;
- }
-
- dispatchMeetingAudioBuffer(outboundBuffer, "mic");
- return;
- }
-
meetingPendingMicChunks.push({
buffer: outboundBuffer,
queuedAt: Date.now(),
@@ -9480,6 +9504,8 @@ class IPCHandlers {
const completeMeetingSystemAudioHandover = () => {
debugLogger.info("Renderer loopback took over system audio capture", {}, "meeting");
meetingSystemAudioWatchdog.detachCapture();
+ // Renderer loopback runs on the mic's clock, so the mic stops waiting.
+ setMeetingSystemAudioStrategy("loopback");
void this.windowsLoopbackAudioManager?.stop().catch(() => {});
};
diff --git a/test/helpers/debugLogger.test.js b/test/helpers/debugLogger.test.js
index 74dfb672b..bb3f8f16f 100644
--- a/test/helpers/debugLogger.test.js
+++ b/test/helpers/debugLogger.test.js
@@ -43,6 +43,10 @@ test("debug log System Info header includes the app version", async () => {
assert.match(contents, /System Info/);
assert.match(contents, /appVersion/);
assert.match(contents, /9\.9\.9-test/);
+ // Which system-audio capture a meeting gets depends on the OS build.
+ assert.match(contents, /osRelease/);
+ assert.match(contents, /osVersion/);
+ assert.match(contents, /"arch"/);
} finally {
delete require.cache[debugLoggerPath];
if (originalLoggerCache) require.cache[debugLoggerPath] = originalLoggerCache;
diff --git a/test/helpers/meetingLocalStopRace.test.js b/test/helpers/meetingLocalStopRace.test.js
index dfa556be0..36705fc5a 100644
--- a/test/helpers/meetingLocalStopRace.test.js
+++ b/test/helpers/meetingLocalStopRace.test.js
@@ -26,7 +26,10 @@ const settle = () => new Promise((resolve) => setImmediate(resolve));
// Runs the real local-meeting stop, rollback and start paths over stubbed
// capture, transcription and diarization so the closure state is observable.
-function harness() {
+function harness({
+ plannedSystemAudio = { mode: "unsupported", strategy: "unsupported" },
+ startedStrategy = plannedSystemAudio.strategy,
+} = {}) {
const events = [];
const sent = [];
const diarizations = [];
@@ -46,6 +49,8 @@ function harness() {
chunkGates,
lateStreamingFinals,
win,
+ plannedSystemAudio,
+ startedStrategy,
debugLogger: { debug() {}, error() {} },
meetingDetectionEngine: engine,
windowManager: { controlPanelWindow: null },
@@ -93,6 +98,7 @@ function harness() {
const armMeetingSystemAudioSilenceTimer = noop;
const startMeetingSystemAudioWatchdog = noop;
const flushPendingMeetingMicChunks = noop;
+ const setMeetingSystemAudioStrategy = (strategy) => events.push("strategy:" + strategy);
const flushPendingMicFinals = () => events.push("flush");
const stopMeetingAec = asyncNoop;
const startMeetingAec = asyncNoop;
@@ -102,13 +108,10 @@ function harness() {
const resolveOneOnOneAttendeeForNote = () => null;
const isMeetingStreamingConnected = () => false;
const getMeetingConnectionKey = () => "local";
- const getMeetingSystemAudioPlan = async () => ({
- mode: "unsupported",
- strategy: "unsupported",
- });
- const startMeetingSystemAudio = async (_event, systemAudioMode, systemAudioStrategy) => ({
+ const getMeetingSystemAudioPlan = async () => plannedSystemAudio;
+ const startMeetingSystemAudio = async (_event, systemAudioMode) => ({
systemAudioMode,
- systemAudioStrategy,
+ systemAudioStrategy: startedStrategy,
});
const toPolicyFailure = (error) => ({ success: false, error: error.message });
const buildOrderedTranscriptText = (segments) =>
@@ -264,3 +267,18 @@ test("a new session starts with no segments from an earlier one", async () => {
assert.equal(result.success, true);
assert.deepEqual(plain(api.segments), []);
});
+
+test("start sets the mic alignment strategy from the plan, then from the start result", async () => {
+ const { api, events } = harness({
+ plannedSystemAudio: { mode: "loopback", strategy: "wasapi-loopback" },
+ startedStrategy: "loopback",
+ });
+
+ const result = await api.start({ provider: "local", sessionId: "session-1" });
+
+ assert.equal(result.success, true);
+ assert.deepEqual(
+ events.filter((event) => event.startsWith("strategy:")),
+ ["strategy:wasapi-loopback", "strategy:loopback"]
+ );
+});
diff --git a/test/helpers/meetingMicReferenceAlignment.test.js b/test/helpers/meetingMicReferenceAlignment.test.js
new file mode 100644
index 000000000..682c1c6a0
--- /dev/null
+++ b/test/helpers/meetingMicReferenceAlignment.test.js
@@ -0,0 +1,124 @@
+const test = require("node:test");
+const assert = require("node:assert/strict");
+const fs = require("node:fs");
+const path = require("node:path");
+const vm = require("node:vm");
+const micGate = require("../../src/helpers/meetingMicGate");
+
+// Runs the real mic alignment and sendMeetingAudio from ipcHandlers.js with
+// only the echo detector, the watchdog and the stream dispatch replaced.
+const source = fs.readFileSync(path.join(__dirname, "../../src/helpers/ipcHandlers.js"), "utf8");
+
+const sliceBetween = (startMarker, endMarker) => {
+ const start = source.indexOf(startMarker);
+ const end = source.indexOf(endMarker, start);
+ assert.ok(start >= 0 && end > start, `${startMarker} not found in ipcHandlers.js`);
+ return source.slice(start, end);
+};
+
+function harness() {
+ let now = 1_000_000;
+ const dispatched = [];
+ const context = {
+ Buffer,
+ Date: { now: () => now },
+ ...micGate,
+ meetingPendingMicChunks: [],
+ meetingSystemAudioStrategy: null,
+ meetingSystemChunkReceivedAt: null,
+ meetingAecEnabled: false,
+ meetingLocalMode: false,
+ meetingLiveSpeakerActive: false,
+ meetingDiarizationStream: { write() {} },
+ meetingSystemAudioHeard: true,
+ meetingSystemAudioWatchdog: { recordChunk() {} },
+ meetingEchoLeakDetector: {
+ recordSystemChunk() {},
+ analyzeMicChunk: () => ({ shouldMute: false }),
+ },
+ dispatchMeetingAudioBuffer: (buffer, source) => {
+ if (source === "mic") dispatched.push(String(buffer));
+ },
+ };
+ vm.createContext(context);
+ vm.runInContext(
+ `
+ ${sliceBetween("const MEETING_MIC_REFERENCE_ALIGNMENT_MS =", "const MEETING_STARTUP_WARMUP_MS =")}
+ ${sliceBetween("const flushPendingMeetingMicChunks =", "const stopLiveSpeakerIdentification =")}
+ ${sliceBetween("const sendMeetingAudio =", "// The Windows helper reports capture_silent")}
+ globalThis.api = {
+ setStrategy: setMeetingSystemAudioStrategy,
+ system: () => sendMeetingAudio(Buffer.alloc(4), "system"),
+ mic: (text) => sendMeetingAudio(Buffer.from(text), "mic"),
+ };
+ `,
+ context
+ );
+ return {
+ api: context.api,
+ dispatched,
+ advance: (ms) => {
+ now += ms;
+ },
+ };
+}
+
+test("each capture holds the mic only as long as its reference lags", () => {
+ for (const [strategy, holdMs] of [
+ ["native", 320],
+ ["wasapi-loopback", 100],
+ ["pipewire-loopback", 100],
+ ["loopback", 0],
+ ["unsupported", 0],
+ ]) {
+ const { api, dispatched, advance } = harness();
+ api.setStrategy(strategy);
+ api.system();
+ api.mic("a");
+ if (holdMs > 0) {
+ advance(holdMs - 1);
+ api.system();
+ assert.deepEqual(dispatched, [], strategy);
+ advance(1);
+ api.system();
+ }
+ assert.deepEqual(dispatched, ["a"], strategy);
+ }
+});
+
+test("a reference that went quiet stops holding the mic, releasing what it held first", () => {
+ const { api, dispatched, advance } = harness();
+ api.setStrategy("wasapi-loopback");
+ api.system();
+ api.mic("a");
+
+ advance(1000);
+ api.mic("b");
+
+ assert.deepEqual(dispatched, ["a", "b"]);
+});
+
+test("a capture that falls back releases the mic it was holding", () => {
+ const { api, dispatched } = harness();
+ api.setStrategy("wasapi-loopback");
+ api.system();
+ api.mic("a");
+ api.mic("b");
+ assert.deepEqual(dispatched, []);
+
+ api.setStrategy("loopback");
+
+ assert.deepEqual(dispatched, ["a", "b"]);
+});
+
+test("a fallback releases held mic even after the wall clock steps back", () => {
+ const { api, dispatched, advance } = harness();
+ api.setStrategy("wasapi-loopback");
+ api.system();
+ api.mic("a");
+
+ advance(-5000);
+ api.setStrategy("loopback");
+
+ assert.deepEqual(dispatched, ["a"]);
+});
diff --git a/test/helpers/meetingSystemAudioDegrade.test.js b/test/helpers/meetingSystemAudioDegrade.test.js
index 24f1a4907..0c72c231b 100644
--- a/test/helpers/meetingSystemAudioDegrade.test.js
+++ b/test/helpers/meetingSystemAudioDegrade.test.js
@@ -28,6 +28,7 @@ function harness({ systemAudioHeard = false } = {}) {
meetingSystemAudioHeard: systemAudioHeard,
meetingSystemAudioHandover: createMeetingSystemAudioHandover({ now: () => now }),
meetingSystemAudioWatchdog: { detachCapture: () => events.push("detach") },
+ setMeetingSystemAudioStrategy: (strategy) => events.push(`strategy:${strategy}`),
debugLogger: { warn() {}, debug() {}, error() {}, info() {} },
windowsLoopbackAudioManager: { stop: async () => events.push("stop") },
BrowserWindow: {
@@ -80,7 +81,7 @@ test("renderer chunks are held back until loopback hears what the helper misses"
sendRenderer(AUDIBLE);
sendRenderer(AUDIBLE);
- assert.deepEqual(events, ["detach", "stop", "send:system", "send:system"]);
+ assert.deepEqual(events, ["detach", "strategy:loopback", "stop", "send:system", "send:system"]);
});
test("renderer chunks pass straight through when no helper handover is pending", () => {