Skip to content

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

feat: enable system audio capture on Windows and Linux via Chromium loopback

Gabriel Steinae14ab94f190
diff --git a/main.js b/main.js
index 368655a6e..78506dcae 100644
--- a/main.js
+++ b/main.js
@@ -18,6 +18,7 @@ if (
const {
app,
+ desktopCapturer,
globalShortcut,
BrowserWindow,
dialog,
@@ -1076,6 +1077,14 @@ if (gotSingleInstanceLock) {
return new Promise((resolve) => setTimeout(resolve, delay));
})
.then(() => {
+ if (process.platform !== "darwin") {
+ session.defaultSession.setDisplayMediaRequestHandler((_request, callback) => {
+ desktopCapturer.getSources({ types: ["screen"] }).then((sources) => {
+ callback({ video: sources[0], audio: "loopback" });
+ });
+ });
+ }
+
startApp().catch((error) => {
console.error("Failed to start app:", error);
dialog.showErrorBox(
diff --git a/src/components/notes/NotesOnboarding.tsx b/src/components/notes/NotesOnboarding.tsx
index b262a2d68..5754b8c78 100644
--- a/src/components/notes/NotesOnboarding.tsx
+++ b/src/components/notes/NotesOnboarding.tsx
@@ -55,7 +55,6 @@ export default function NotesOnboarding({ onComplete }: NotesOnboardingProps) {
granted: systemAudioGranted,
mode: systemAudioMode,
request: requestSystemAudio,
- isMacOS,
} = useSystemAudioPermission();
const [isRequestingSystemAudio, setIsRequestingSystemAudio] = useState(false);
@@ -185,8 +184,8 @@ export default function NotesOnboarding({ onComplete }: NotesOnboardingProps) {
</div>
)}
- {/* System Audio Permission — macOS only */}
- {isMacOS && systemAudioMode === "native" && (
+ {/* System Audio Permission */}
+ {systemAudioMode !== "unsupported" && (
<div
className={cn(
"rounded-lg border transition-colors duration-200",
@@ -214,7 +213,7 @@ export default function NotesOnboarding({ onComplete }: NotesOnboardingProps) {
<span className="text-xs text-success/60 font-medium shrink-0">
{t("notes.onboarding.systemAudio.enabled")}
</span>
- ) : (
+ ) : systemAudioMode === "native" ? (
<Button
variant="outline"
size="sm"
@@ -228,7 +227,7 @@ export default function NotesOnboarding({ onComplete }: NotesOnboardingProps) {
t("notes.onboarding.systemAudio.grant")
)}
</Button>
- )}
+ ) : null}
</div>
</div>
)}
diff --git a/src/helpers/ipcHandlers.js b/src/helpers/ipcHandlers.js
index de4949c15..1ab7af5b9 100644
--- a/src/helpers/ipcHandlers.js
+++ b/src/helpers/ipcHandlers.js
@@ -2433,7 +2433,7 @@ class IPCHandlers {
ipcMain.handle("check-system-audio-access", async () => {
if (process.platform !== "darwin") {
- return { granted: true, status: "granted", mode: "unsupported" };
+ return { granted: true, status: "granted", mode: "loopback" };
}
if (!this.audioTapManager?.isSupported()) {
@@ -2446,7 +2446,7 @@ class IPCHandlers {
ipcMain.handle("request-system-audio-access", async () => {
if (process.platform !== "darwin") {
- return { granted: true, status: "granted", mode: "unsupported" };
+ return { granted: true, status: "granted", mode: "loopback" };
}
if (!this.audioTapManager?.isSupported()) {
@@ -2877,14 +2877,17 @@ class IPCHandlers {
return data.clientSecret;
};
- const getMeetingSystemAudioMode = () =>
- this.audioTapManager?.isSupported() ? "native" : "unsupported";
+ const getMeetingSystemAudioMode = () => {
+ if (this.audioTapManager?.isSupported()) return "native";
+ if (process.platform !== "darwin") return "loopback";
+ return "unsupported";
+ };
- const hasNativeMeetingSystemAudio = () => getMeetingSystemAudioMode() === "native";
+ const hasMeetingSystemAudio = () => getMeetingSystemAudioMode() !== "unsupported";
const isMeetingStreamingConnected = () =>
!!this._meetingMicStreaming?.isConnected &&
- (!hasNativeMeetingSystemAudio() || !!this._meetingSystemStreaming?.isConnected);
+ (!hasMeetingSystemAudio() || !!this._meetingSystemStreaming?.isConnected);
const connectRealtimeStreaming = async (event, options) => {
if (this._meetingMicStreaming?.isConnected) {
@@ -2903,7 +2906,7 @@ class IPCHandlers {
preconfigured: options.mode !== "byok",
};
let pairs;
- if (hasNativeMeetingSystemAudio()) {
+ if (hasMeetingSystemAudio()) {
const secrets = await fetchRealtimeToken(event, options, { streams: 2 });
pairs = [
{ ref: "_meetingMicStreaming", secret: secrets[0], source: "mic" },
diff --git a/src/hooks/useMeetingTranscription.ts b/src/hooks/useMeetingTranscription.ts
index 719e3466b..36d73f074 100644
--- a/src/hooks/useMeetingTranscription.ts
+++ b/src/hooks/useMeetingTranscription.ts
@@ -244,6 +244,10 @@ export function useMeetingTranscription(): UseMeetingTranscriptionReturn {
const micSourceRef = useRef<MediaStreamAudioSourceNode | null>(null);
const micProcessorRef = useRef<AudioWorkletNode | null>(null);
const micStreamRef = useRef<MediaStream | null>(null);
+ const systemContextRef = useRef<AudioContext | null>(null);
+ const systemSourceRef = useRef<MediaStreamAudioSourceNode | null>(null);
+ const systemProcessorRef = useRef<AudioWorkletNode | null>(null);
+ const systemStreamRef = useRef<MediaStream | null>(null);
const isRecordingRef = useRef(false);
const isStartingRef = useRef(false);
const isPreparedRef = useRef(false);
@@ -268,6 +272,22 @@ export function useMeetingTranscription(): UseMeetingTranscriptionReturn {
} catch {}
micContextRef.current = null;
+ await flushAndDisconnectProcessor(systemProcessorRef.current);
+ systemProcessorRef.current = null;
+
+ systemSourceRef.current?.disconnect();
+ systemSourceRef.current = null;
+
+ try {
+ systemStreamRef.current?.getTracks().forEach((t) => t.stop());
+ } catch {}
+ systemStreamRef.current = null;
+
+ try {
+ await systemContextRef.current?.close();
+ } catch {}
+ systemContextRef.current = null;
+
ipcCleanupsRef.current.forEach((fn) => fn());
ipcCleanupsRef.current = [];
isPreparedRef.current = false;
@@ -405,7 +425,7 @@ export function useMeetingTranscription(): UseMeetingTranscriptionReturn {
const systemAudioMode = startResult.systemAudioMode || "unsupported";
- if (!micResult && systemAudioMode !== "native") {
+ if (!micResult && systemAudioMode === "unsupported") {
logger.error("Meeting transcription has no available audio source", {}, "meeting");
setError(
"No microphone is available and system audio capture is unsupported on this device."
@@ -512,6 +532,40 @@ export function useMeetingTranscription(): UseMeetingTranscriptionReturn {
await micPipelinePromise;
}
+ if (systemAudioMode === "loopback") {
+ try {
+ const displayStream = await navigator.mediaDevices.getDisplayMedia({
+ video: true,
+ audio: true,
+ });
+ displayStream.getVideoTracks().forEach((t) => t.stop());
+
+ const systemContext = new AudioContext({ sampleRate: 24000 });
+ await detachFromOutputDevice(systemContext);
+ systemContextRef.current = systemContext;
+ systemStreamRef.current = displayStream;
+
+ await createAudioPipeline({
+ stream: displayStream,
+ context: systemContext,
+ label: "Meeting system",
+ onChunk: (chunk) => {
+ if (!isRecordingRef.current) return;
+ window.electronAPI?.meetingTranscriptionSend?.(chunk, "system");
+ },
+ }).then(({ source, processor }) => {
+ systemSourceRef.current = source;
+ systemProcessorRef.current = processor;
+ });
+ } catch (err) {
+ logger.warn(
+ "System audio loopback failed, continuing with mic only",
+ { error: (err as Error).message },
+ "meeting"
+ );
+ }
+ }
+
// Abort if stop was called during pipeline setup
if (!isRecordingRef.current) {
logger.info(
diff --git a/src/hooks/useSystemAudioPermission.ts b/src/hooks/useSystemAudioPermission.ts
index 5bc77cac7..283fd3de2 100644
--- a/src/hooks/useSystemAudioPermission.ts
+++ b/src/hooks/useSystemAudioPermission.ts
@@ -2,39 +2,35 @@ import { useState, useCallback, useEffect, useRef } from "react";
import { getCachedPlatform } from "../utils/platform";
import type { SystemAudioAccessResult } from "../types/electron";
-const NON_MACOS_ACCESS: SystemAudioAccessResult = {
- granted: true,
- status: "granted",
+const DEFAULT_ACCESS: SystemAudioAccessResult = {
+ granted: false,
+ status: "unsupported",
mode: "unsupported",
};
export function useSystemAudioPermission() {
const isMacOS = getCachedPlatform() === "darwin";
- const [access, setAccess] = useState<SystemAudioAccessResult | null>(
- isMacOS ? null : NON_MACOS_ACCESS
- );
+ const [access, setAccess] = useState<SystemAudioAccessResult | null>(null);
const [isChecking, setIsChecking] = useState(false);
const checkingRef = useRef(false);
const check = useCallback(async () => {
- if (!isMacOS || checkingRef.current) return;
+ if (checkingRef.current) return;
checkingRef.current = true;
setIsChecking(true);
try {
const result = await window.electronAPI?.checkSystemAudioAccess?.();
- setAccess(result ?? { granted: false, status: "unsupported", mode: "unsupported" });
+ setAccess(result ?? DEFAULT_ACCESS);
} finally {
checkingRef.current = false;
setIsChecking(false);
}
- }, [isMacOS]);
+ }, []);
- // Check on mount
useEffect(() => {
check();
}, [check]);
- // Re-check when the window regains focus (user may have just toggled it in System Settings)
useEffect(() => {
if (!isMacOS) return;
const handleFocus = () => check();
@@ -47,22 +43,20 @@ export function useSystemAudioPermission() {
}, []);
const request = useCallback(async (): Promise<boolean> => {
- if (!isMacOS) return true;
+ const currentAccess = access ?? (await window.electronAPI?.checkSystemAudioAccess?.()) ?? DEFAULT_ACCESS;
- setIsChecking(true);
- try {
- const currentAccess = access ??
- (await window.electronAPI?.checkSystemAudioAccess?.()) ?? {
- granted: false,
- status: "unsupported" as const,
- mode: "unsupported" as const,
- };
+ if (currentAccess.mode === "loopback") {
+ setAccess(currentAccess);
+ return currentAccess.granted;
+ }
- if (currentAccess.mode !== "native") {
- setAccess(currentAccess);
- return false;
- }
+ if (currentAccess.mode !== "native") {
+ setAccess(currentAccess);
+ return false;
+ }
+ setIsChecking(true);
+ try {
const result = await window.electronAPI?.requestSystemAudioAccess?.();
const nextAccess = result ?? currentAccess;
setAccess(nextAccess);
@@ -72,7 +66,7 @@ export function useSystemAudioPermission() {
} finally {
setIsChecking(false);
}
- }, [access, isMacOS]);
+ }, [access]);
const granted = access?.granted ?? false;
const status = access?.status ?? "unknown";
diff --git a/src/types/electron.ts b/src/types/electron.ts
index f6a17f9cd..59523c5f1 100644
--- a/src/types/electron.ts
+++ b/src/types/electron.ts
@@ -125,7 +125,7 @@ export interface AudioDiagnosticsResult {
export interface SystemAudioAccessResult {
granted: boolean;
status: "granted" | "denied" | "not-determined" | "restricted" | "unknown" | "unsupported";
- mode: "native" | "unsupported";
+ mode: "native" | "loopback" | "unsupported";
error?: string;
}
@@ -1295,7 +1295,7 @@ declare global {
}) => Promise<{
success: boolean;
error?: string;
- systemAudioMode?: "native" | "unsupported";
+ systemAudioMode?: "native" | "loopback" | "unsupported";
}>;
meetingTranscriptionSend?: (buffer: ArrayBuffer, source: "mic" | "system") => void;
meetingTranscriptionStop?: () => Promise<{