Skip to content

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

Native Windows system audio capture for meeting notes (#960)

Gabriel Stein01f8557b0cce
diff --git a/.github/workflows/build-windows-system-audio-helper.yml b/.github/workflows/build-windows-system-audio-helper.yml
new file mode 100644
index 000000000..536882da8
--- /dev/null
+++ b/.github/workflows/build-windows-system-audio-helper.yml
@@ -0,0 +1,85 @@
+name: Build Windows System Audio Helper
+
+on:
+ push:
+ paths:
+ - 'resources/windows-system-audio-helper.c'
+ - '.github/workflows/build-windows-system-audio-helper.yml'
+ branches:
+ - main
+ workflow_dispatch:
+ inputs:
+ version:
+ description: 'Version tag (e.g., 1.0.0)'
+ required: false
+ default: '1.0.0'
+ type: string
+
+permissions:
+ contents: write
+
+jobs:
+ build:
+ runs-on: windows-latest
+ steps:
+ - uses: actions/checkout@v4
+
+ - name: Setup MSVC
+ uses: microsoft/setup-msbuild@v2
+
+ - name: Setup MSVC environment
+ uses: ilammy/msvc-dev-cmd@v1
+
+ - name: Compile Windows System Audio Helper
+ run: |
+ cl /O2 /nologo resources/windows-system-audio-helper.c /Fe:windows-system-audio-helper.exe ole32.lib mmdevapi.lib
+ shell: cmd
+
+ - name: Verify binary
+ run: |
+ if (Test-Path "windows-system-audio-helper.exe") {
+ Write-Host "Binary built successfully"
+ Get-Item "windows-system-audio-helper.exe" | Select-Object Name, Length
+ } else {
+ Write-Error "Binary not found"
+ exit 1
+ }
+ shell: pwsh
+
+ - name: Smoke test probe
+ run: |
+ $output = & .\windows-system-audio-helper.exe probe
+ Write-Host "Probe output: $output"
+ if ($output -notmatch '"ok":') {
+ Write-Error "Probe did not return JSON"
+ exit 1
+ }
+ shell: pwsh
+
+ - name: Create zip archive
+ run: |
+ Compress-Archive -Path windows-system-audio-helper.exe -DestinationPath windows-system-audio-helper-win32-x64.zip
+ shell: pwsh
+
+ - name: Upload artifact
+ uses: actions/upload-artifact@v4
+ with:
+ name: windows-system-audio-helper
+ path: windows-system-audio-helper-win32-x64.zip
+
+ - name: Create or update release
+ uses: softprops/action-gh-release@v2
+ with:
+ tag_name: windows-system-audio-helper-v${{ inputs.version || '1.0.0' }}
+ name: Windows System Audio Helper v${{ inputs.version || '1.0.0' }}
+ body: |
+ Prebuilt Windows system audio helper binary for meeting transcription.
+
+ Captures system audio via WASAPI process loopback (exclude mode),
+ hearing every application on every output device while excluding
+ OpenWhispr's own audio. Requires Windows 10 2004 or later; older
+ systems automatically fall back to Chromium display-media loopback.
+ files: windows-system-audio-helper-win32-x64.zip
+ make_latest: false
+ env:
+ GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml
index 7c1c415d6..ecd3bdc02 100644
--- a/.github/workflows/release.yml
+++ b/.github/workflows/release.yml
@@ -115,7 +115,9 @@ jobs:
uses: actions/cache@v4
with:
path: resources/bin
- key: windows-x64-bin-${{ hashFiles('scripts/download-*.js') }}
+ # The system-audio helper source is in the key so a republished
+ # helper binary invalidates the cached copy.
+ key: windows-x64-bin-${{ hashFiles('scripts/download-*.js', 'resources/windows-system-audio-helper.c') }}
- name: Download whisper.cpp binaries
run: node scripts/download-whisper-cpp.js --current
@@ -162,6 +164,15 @@ jobs:
env:
GITHUB_TOKEN: ${{ secrets.GH_TOKEN }}
+ - name: Download windows-system-audio-helper.exe
+ run: node scripts/download-windows-system-audio-helper.js
+ env:
+ GITHUB_TOKEN: ${{ secrets.GH_TOKEN }}
+
+ - name: Verify windows-system-audio-helper.exe
+ shell: bash
+ run: test -f resources/bin/windows-system-audio-helper.exe
+
- name: Cache Electron
uses: actions/cache@v4
with:
diff --git a/CLAUDE.md b/CLAUDE.md
index ecd655b6d..afa08dc14 100644
--- a/CLAUDE.md
+++ b/CLAUDE.md
@@ -46,6 +46,7 @@ OpenWhispr is an Electron-based desktop dictation application that uses whisper.
- **windows-key-listener.c**: C source for Windows low-level keyboard hook (Push-to-Talk)
- **windows-mic-listener.c**: C source for WASAPI mic session monitor (event-driven mic detection)
+- **windows-system-audio-helper.c**: C source for WASAPI process-loopback system audio capture (meeting transcription). Excludes OpenWhispr's own process tree, so it hears every app on every output device. Requires Windows 10 2004+; falls back to Chromium display-media loopback when unavailable. Outputs 24 kHz mono s16le PCM on stdout, line-delimited JSON events on stderr (same protocol as linux-system-audio-helper)
- **macos-mic-listener.swift**: Swift source for CoreAudio mic property listener (event-driven mic detection)
- **globe-listener.swift**: Swift source for macOS Globe/Fn key detection
- **bin/**: Directory for compiled native binaries (whisper-cpp, nircmd, key/mic listeners)
diff --git a/TROUBLESHOOTING.md b/TROUBLESHOOTING.md
index 60161aadc..581c11658 100644
--- a/TROUBLESHOOTING.md
+++ b/TROUBLESHOOTING.md
@@ -144,6 +144,12 @@ OpenWhispr tries clipboard methods in order: `wl-copy` (most reliable) → rende
2. Restart the app after granting permission
3. Ensure Google Calendar is connected in Integrations
+**Windows:**
+
+1. System audio is captured by `windows-system-audio-helper.exe` (WASAPI process loopback), which hears every app on every output device — no permission prompt is needed
+2. If the helper is missing or fails (requires Windows 10 2004+), OpenWhispr automatically falls back to Chromium loopback, which only hears the _default_ output device — make sure your meeting app plays through the default device in that case
+3. If transcription shows "Continuing with microphone only", system audio capture failed entirely; check debug logs for `windows-system-audio-helper` entries
+
**All Platforms:**
1. Check that meeting detection is enabled in settings
diff --git a/electron-builder.json b/electron-builder.json
index 530439a09..96d988d39 100644
--- a/electron-builder.json
+++ b/electron-builder.json
@@ -117,6 +117,7 @@
"meeting-aec-helper-*",
"windows-key-listener*",
"windows-mic-listener*",
+ "windows-system-audio-helper*",
"windows-text-monitor*",
"windows-fast-paste*",
"all-MiniLM-L6-v2/**/*",
diff --git a/main.js b/main.js
index abe3bcbb9..a52fa62b2 100644
--- a/main.js
+++ b/main.js
@@ -284,6 +284,7 @@ const MeetingProcessDetector = require("./src/helpers/meetingProcessDetector");
const AudioActivityDetector = require("./src/helpers/audioActivityDetector");
const AudioTapManager = require("./src/helpers/audioTapManager");
const LinuxPortalAudioManager = require("./src/helpers/linuxPortalAudioManager");
+const WindowsLoopbackAudioManager = require("./src/helpers/windowsLoopbackAudioManager");
const MeetingAecManager = require("./src/helpers/meetingAecManager");
const MeetingDetectionEngine = require("./src/helpers/meetingDetectionEngine");
const { i18nMain, changeLanguage } = require("./src/helpers/i18nMain");
@@ -312,6 +313,7 @@ let googleCalendarManager = null;
let meetingDetectionEngine = null;
let audioTapManager = null;
let linuxPortalAudioManager = null;
+let windowsLoopbackAudioManager = null;
let meetingAecManager = null;
let qdrantManager = null;
let ipcHandlers = null;
@@ -406,6 +408,10 @@ function initializeCoreManagers() {
textEditMonitor = new TextEditMonitor();
audioTapManager = new AudioTapManager();
linuxPortalAudioManager = new LinuxPortalAudioManager();
+ windowsLoopbackAudioManager = new WindowsLoopbackAudioManager();
+ // Warm the capability cache off the hot path so the first meeting start
+ // doesn't pay the probe spawn. No-ops on non-Windows.
+ windowsLoopbackAudioManager.getCapability().catch(() => {});
cleanupOrphanedLinuxRestoreToken();
meetingAecManager = new MeetingAecManager();
windowManager.textEditMonitor = textEditMonitor;
@@ -430,6 +436,7 @@ function initializeCoreManagers() {
meetingDetectionEngine,
audioTapManager,
linuxPortalAudioManager,
+ windowsLoopbackAudioManager,
meetingAecManager,
getTrayManager: () => trayManager,
oauthProtocolRegistered: protocolRegistered,
@@ -1481,9 +1488,21 @@ if (gotSingleInstanceLock) {
.then(() => {
if (process.platform === "win32") {
session.defaultSession.setDisplayMediaRequestHandler((_request, callback) => {
- desktopCapturer.getSources({ types: ["screen"] }).then((sources) => {
- callback({ video: sources[0], audio: "loopback" });
- });
+ // Only the loopback audio track is used; the video source is
+ // discarded by the renderer, so skip thumbnail generation.
+ desktopCapturer
+ .getSources({ types: ["screen"], thumbnailSize: { width: 0, height: 0 } })
+ .then((sources) => {
+ if (sources.length > 0) {
+ callback({ video: sources[0], audio: "loopback" });
+ } else {
+ callback(null);
+ }
+ })
+ .catch((error) => {
+ console.error("Display media request failed:", error);
+ callback(null);
+ });
});
}
@@ -1594,6 +1613,7 @@ function performSyncTeardown() {
if (googleCalendarManager) googleCalendarManager.stop();
if (audioTapManager) audioTapManager.stop().catch(() => {});
if (linuxPortalAudioManager) linuxPortalAudioManager.stop().catch(() => {});
+ if (windowsLoopbackAudioManager) windowsLoopbackAudioManager.stop().catch(() => {});
if (meetingAecManager) meetingAecManager.stop().catch(() => {});
if (ipcHandlers) ipcHandlers._cleanupTextEditMonitor();
if (textEditMonitor) textEditMonitor.stopMonitoring();
diff --git a/package.json b/package.json
index db2c57825..c06e6a25e 100644
--- a/package.json
+++ b/package.json
@@ -36,7 +36,7 @@
"build:mac": "npm run build:renderer && electron-builder --mac",
"build:mac:arm64": "npm run build:renderer && electron-builder --mac --arm64",
"build:mac:x64": "npm run build:renderer && electron-builder --mac --x64",
- "prebuild:win": "npm run compile:native && npm run download:whisper-cpp && npm run download:llama-server && npm run download:sherpa-onnx && npm run download:qdrant && npm run download:meeting-aec-helper && npm run download:whisper-vad-model && npm run download:diarization-models -- --output-dir resources/bin/diarization-models && npm run download:nircmd && npm run download:windows-fast-paste && npm run download:windows-key-listener && npm run download:windows-mic-listener",
+ "prebuild:win": "npm run compile:native && npm run download:whisper-cpp && npm run download:llama-server && npm run download:sherpa-onnx && npm run download:qdrant && npm run download:meeting-aec-helper && npm run download:whisper-vad-model && npm run download:diarization-models -- --output-dir resources/bin/diarization-models && npm run download:nircmd && npm run download:windows-fast-paste && npm run download:windows-key-listener && npm run download:windows-mic-listener && npm run download:windows-system-audio-helper",
"build:win": "npm run build:renderer && electron-builder --win",
"prebuild:linux": "npm run compile:native && npm run download:whisper-cpp && npm run download:llama-server && npm run download:sherpa-onnx && npm run download:qdrant && npm run download:meeting-aec-helper && npm run download:whisper-vad-model && npm run download:diarization-models -- --output-dir resources/bin/diarization-models",
"build:linux": "npm run build:renderer && electron-builder --linux",
@@ -58,6 +58,7 @@
"download:windows-fast-paste": "node scripts/download-windows-fast-paste.js",
"download:windows-key-listener": "node scripts/download-windows-key-listener.js",
"download:windows-mic-listener": "node scripts/download-windows-mic-listener.js",
+ "download:windows-system-audio-helper": "node scripts/download-windows-system-audio-helper.js",
"download:meeting-aec-helper": "node scripts/download-meeting-aec-helper.js --current",
"download:meeting-aec-helper:all": "node scripts/download-meeting-aec-helper.js --all",
"download:qdrant": "node scripts/download-qdrant.js --current",
diff --git a/resources/windows-system-audio-helper.c b/resources/windows-system-audio-helper.c
new file mode 100644
index 000000000..08a218c11
--- /dev/null
+++ b/resources/windows-system-audio-helper.c
@@ -0,0 +1,624 @@
+/**
+ * Windows System Audio Helper
+ *
+ * Captures system audio for meeting transcription via WASAPI process
+ * loopback (VAD\Process_Loopback, Windows 10 2004+). Runs in EXCLUDE mode
+ * against OpenWhispr's own process tree, so it hears every application on
+ * every render endpoint — independent of the default output device — while
+ * never re-capturing OpenWhispr's own sounds.
+ *
+ * Commands:
+ * windows-system-audio-helper.exe probe
+ * Prints a single JSON capability object to stdout and exits.
+ * windows-system-audio-helper.exe start [--exclude-pid N] [--sample-rate N]
+ * Streams raw PCM (mono, 16-bit signed little-endian, --sample-rate Hz,
+ * default 24000) to stdout. Emits line-delimited JSON events to stderr:
+ * {"type":"start"} once capture is running,
+ * {"type":"warning","code":...,"message":...} for recoverable issues,
+ * {"type":"error","code":...,"message":...} before exiting with code 2.
+ * Exits when stdin closes (parent death), on Ctrl+C/SIGTERM, or on a
+ * fatal capture error. Injects silence while no application renders
+ * audio so the output timeline stays continuous.
+ *
+ * Compile with: cl /O2 windows-system-audio-helper.c /Fe:windows-system-audio-helper.exe ole32.lib mmdevapi.lib
+ * Or with MinGW: gcc -O2 windows-system-audio-helper.c -o windows-system-audio-helper.exe -lole32 -lmmdevapi
+ */
+
+#define WIN32_LEAN_AND_MEAN
+#define COBJMACROS
+#define CINTERFACE
+
+#include <windows.h>
+#include <initguid.h>
+#include <mmdeviceapi.h>
+#include <audioclient.h>
+#include <fcntl.h>
+#include <io.h>
+#include <stdarg.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#if defined(__has_include)
+#if __has_include(<audioclientactivationparams.h>)
+#include <audioclientactivationparams.h>
+#define HAVE_ACTIVATION_PARAMS_HEADER 1
+#endif
+#endif
+
+#ifndef HAVE_ACTIVATION_PARAMS_HEADER
+#define VIRTUAL_AUDIO_DEVICE_PROCESS_LOOPBACK L"VAD\\Process_Loopback"
+
+typedef enum {
+ PROCESS_LOOPBACK_MODE_INCLUDE_TARGET_PROCESS_TREE = 0,
+ PROCESS_LOOPBACK_MODE_EXCLUDE_TARGET_PROCESS_TREE = 1
+} PROCESS_LOOPBACK_MODE;
+
+typedef enum {
+ AUDIOCLIENT_ACTIVATION_TYPE_DEFAULT = 0,
+ AUDIOCLIENT_ACTIVATION_TYPE_PROCESS_LOOPBACK = 1
+} AUDIOCLIENT_ACTIVATION_TYPE;
+
+typedef struct {
+ DWORD TargetProcessId;
+ PROCESS_LOOPBACK_MODE ProcessLoopbackMode;
+} AUDIOCLIENT_PROCESS_LOOPBACK_PARAMS;
+
+typedef struct {
+ AUDIOCLIENT_ACTIVATION_TYPE ActivationType;
+ union {
+ AUDIOCLIENT_PROCESS_LOOPBACK_PARAMS ProcessLoopbackParams;
+ } DUMMYUNIONNAME;
+} AUDIOCLIENT_ACTIVATION_PARAMS;
+#endif
+
+#ifndef AUDCLNT_STREAMFLAGS_AUTOCONVERTPCM
+#define AUDCLNT_STREAMFLAGS_AUTOCONVERTPCM 0x80000000
+#endif
+#ifndef AUDCLNT_STREAMFLAGS_SRC_DEFAULT_QUALITY
+#define AUDCLNT_STREAMFLAGS_SRC_DEFAULT_QUALITY 0x08000000
+#endif
+
+DEFINE_GUID(HELPER_IID_IAgileObject,
+ 0x94ea2b94, 0xe9cc, 0x49e0, 0xc0, 0xff, 0xee, 0x64, 0xca, 0x8f, 0x5b, 0x90);
+
+#define DEFAULT_SAMPLE_RATE 24000
+#define CAPTURE_CHANNELS 2
+#define BYTES_PER_SAMPLE 2
+#define ACTIVATION_TIMEOUT_MS 4000
+#define CAPTURE_WAIT_TIMEOUT_MS 100
+/* Fill silence once the emitted timeline lags the wall clock by this much. */
+#define SILENCE_GAP_THRESHOLD_MS 100
+/* Beyond this the clock jumped (system sleep/resume); rebase instead of
+ * flooding the pipe with hours of silence. */
+#define SILENCE_GAP_MAX_MS 5000
+#define SILENCE_FILL_CHUNK_FRAMES 2400
+#define BUFFER_DURATION_HNS 200000 /* 20 ms, matches the Microsoft sample */
+
+static volatile LONG g_running = TRUE;
+
+/* ========================================================================
+ * JSON events on stderr (all message content is static or numeric, so no
+ * string escaping is required)
+ * ======================================================================== */
+
+static void emit_event(const char *type, const char *code, const char *format, ...)
+{
+ fprintf(stderr, "{\"type\":\"%s\"", type);
+ if (code) {
+ fprintf(stderr, ",\"code\":\"%s\"", code);
+ }
+ if (format) {
+ va_list args;
+ va_start(args, format);
+ fputs(",\"message\":\"", stderr);
+ vfprintf(stderr, format, args);
+ fputs("\"", stderr);
+ va_end(args);
+ }
+ fputs("}\n", stderr);
+ fflush(stderr);
+}
+
+static void emit_probe_result(BOOL ok, const char *error, HRESULT hr)
+{
+ if (ok) {
+ printf("{\"ok\":true,\"supportsSystemAudio\":true,\"supportsNativeCapture\":true,"
+ "\"source\":\"wasapi-process-loopback\"}\n");
+ } else {
+ printf("{\"ok\":false,\"supportsSystemAudio\":false,\"supportsNativeCapture\":false,"
+ "\"source\":\"wasapi-process-loopback\",\"error\":\"%s (hr=0x%08lx)\"}\n",
+ error, (unsigned long)hr);
+ }
+ fflush(stdout);
+}
+
+/* ========================================================================
+ * IActivateAudioInterfaceCompletionHandler implementation
+ * ======================================================================== */
+
+/* Heap-allocated and refcounted: ActivateAudioInterfaceAsync holds its own
+ * reference, so a completion that arrives after our wait timed out still
+ * finds a live object and a valid event handle. */
+typedef struct {
+ IActivateAudioInterfaceCompletionHandlerVtbl *lpVtbl;
+ LONG refCount;
+ HANDLE completedEvent;
+} CompletionHandler;
+
+static HRESULT STDMETHODCALLTYPE CH_QueryInterface(
+ IActivateAudioInterfaceCompletionHandler *This, REFIID riid, void **ppvObject)
+{
+ if (IsEqualIID(riid, &IID_IUnknown) ||
+ IsEqualIID(riid, &HELPER_IID_IAgileObject) ||
+ IsEqualIID(riid, &IID_IActivateAudioInterfaceCompletionHandler)) {
+ *ppvObject = This;
+ This->lpVtbl->AddRef(This);
+ return S_OK;
+ }
+ *ppvObject = NULL;
+ return E_NOINTERFACE;
+}
+
+static ULONG STDMETHODCALLTYPE CH_AddRef(IActivateAudioInterfaceCompletionHandler *This)
+{
+ CompletionHandler *self = (CompletionHandler *)This;
+ return InterlockedIncrement(&self->refCount);
+}
+
+static ULONG STDMETHODCALLTYPE CH_Release(IActivateAudioInterfaceCompletionHandler *This)
+{
+ CompletionHandler *self = (CompletionHandler *)This;
+ LONG count = InterlockedDecrement(&self->refCount);
+ if (count == 0) {
+ CloseHandle(self->completedEvent);
+ free(self);
+ }
+ return count;
+}
+
+static HRESULT STDMETHODCALLTYPE CH_ActivateCompleted(
+ IActivateAudioInterfaceCompletionHandler *This,
+ IActivateAudioInterfaceAsyncOperation *activateOperation)
+{
+ CompletionHandler *self = (CompletionHandler *)This;
+ (void)activateOperation;
+ SetEvent(self->completedEvent);
+ return S_OK;
+}
+
+static IActivateAudioInterfaceCompletionHandlerVtbl g_completionHandlerVtbl = {
+ CH_QueryInterface,
+ CH_AddRef,
+ CH_Release,
+ CH_ActivateCompleted,
+};
+
+static CompletionHandler *create_completion_handler(void)
+{
+ CompletionHandler *handler = (CompletionHandler *)calloc(1, sizeof(CompletionHandler));
+ if (!handler) {
+ return NULL;
+ }
+
+ handler->lpVtbl = &g_completionHandlerVtbl;
+ handler->refCount = 1;
+ handler->completedEvent = CreateEventW(NULL, TRUE, FALSE, NULL);
+ if (!handler->completedEvent) {
+ free(handler);
+ return NULL;
+ }
+ return handler;
+}
+
+/* ========================================================================
+ * Process-loopback activation
+ * ======================================================================== */
+
+static HRESULT activate_process_loopback(
+ DWORD excludePid, UINT32 sampleRate, IAudioClient **outClient, const char **outErrorCode)
+{
+ AUDIOCLIENT_ACTIVATION_PARAMS activationParams;
+ PROPVARIANT activateParams;
+ CompletionHandler *handler;
+ IActivateAudioInterfaceAsyncOperation *asyncOp = NULL;
+ IUnknown *audioClientUnknown = NULL;
+ IAudioClient *audioClient = NULL;
+ WAVEFORMATEX format;
+ HRESULT hr;
+ HRESULT activateResult = E_FAIL;
+
+ *outClient = NULL;
+ *outErrorCode = "activation_failed";
+
+ ZeroMemory(&activationParams, sizeof(activationParams));
+ activationParams.ActivationType = AUDIOCLIENT_ACTIVATION_TYPE_PROCESS_LOOPBACK;
+ activationParams.ProcessLoopbackParams.TargetProcessId = excludePid;
+ activationParams.ProcessLoopbackParams.ProcessLoopbackMode =
+ PROCESS_LOOPBACK_MODE_EXCLUDE_TARGET_PROCESS_TREE;
+
+ PropVariantInit(&activateParams);
+ activateParams.vt = VT_BLOB;
+ activateParams.blob.cbSize = sizeof(activationParams);
+ activateParams.blob.pBlobData = (BYTE *)&activationParams;
+
+ handler = create_completion_handler();
+ if (!handler) {
+ return E_OUTOFMEMORY;
+ }
+
+ hr = ActivateAudioInterfaceAsync(
+ VIRTUAL_AUDIO_DEVICE_PROCESS_LOOPBACK,
+ &IID_IAudioClient,
+ &activateParams,
+ (IActivateAudioInterfaceCompletionHandler *)handler,
+ &asyncOp);
+
+ if (SUCCEEDED(hr)) {
+ /* The completion callback can fail to arrive in the field (Chromium
+ * bounds this same wait), so never wait unbounded. */
+ if (WaitForSingleObject(handler->completedEvent, ACTIVATION_TIMEOUT_MS) != WAIT_OBJECT_0) {
+ hr = HRESULT_FROM_WIN32(WAIT_TIMEOUT);
+ *outErrorCode = "activation_timeout";
+ } else {
+ hr = IActivateAudioInterfaceAsyncOperation_GetActivateResult(
+ asyncOp, &activateResult, &audioClientUnknown);
+ if (SUCCEEDED(hr)) {
+ hr = activateResult;
+ }
+ }
+ }
+
+ if (asyncOp) {
+ IActivateAudioInterfaceAsyncOperation_Release(asyncOp);
+ }
+ CH_Release((IActivateAudioInterfaceCompletionHandler *)handler);
+
+ if (FAILED(hr)) {
+ if (audioClientUnknown) {
+ IUnknown_Release(audioClientUnknown);
+ }
+ return hr;
+ }
+
+ hr = IUnknown_QueryInterface(audioClientUnknown, &IID_IAudioClient, (void **)&audioClient);
+ IUnknown_Release(audioClientUnknown);
+ if (FAILED(hr)) {
+ return hr;
+ }
+
+ /* The process-loopback virtual device has no mix format; we pick the
+ * format and AUDCLNT_STREAMFLAGS_AUTOCONVERTPCM makes the engine
+ * resample into it. Stereo is the field-proven choice; we downmix. */
+ ZeroMemory(&format, sizeof(format));
+ format.wFormatTag = WAVE_FORMAT_PCM;
+ format.nChannels = CAPTURE_CHANNELS;
+ format.nSamplesPerSec = sampleRate;
+ format.wBitsPerSample = BYTES_PER_SAMPLE * 8;
+ format.nBlockAlign = CAPTURE_CHANNELS * BYTES_PER_SAMPLE;
+ format.nAvgBytesPerSec = sampleRate * format.nBlockAlign;
+
+ hr = IAudioClient_Initialize(
+ audioClient,
+ AUDCLNT_SHAREMODE_SHARED,
+ AUDCLNT_STREAMFLAGS_LOOPBACK | AUDCLNT_STREAMFLAGS_EVENTCALLBACK |
+ AUDCLNT_STREAMFLAGS_AUTOCONVERTPCM | AUDCLNT_STREAMFLAGS_SRC_DEFAULT_QUALITY,
+ BUFFER_DURATION_HNS,
+ 0,
+ &format,
+ NULL);
+
+ if (FAILED(hr)) {
+ IAudioClient_Release(audioClient);
+ *outErrorCode = "initialize_failed";
+ return hr;
+ }
+
+ *outClient = audioClient;
+ return S_OK;
+}
+
+/* ========================================================================
+ * Capture loop
+ * ======================================================================== */
+
+static BOOL write_pcm(const short *samples, size_t sampleCount)
+{
+ if (sampleCount == 0) {
+ return TRUE;
+ }
+ if (fwrite(samples, sizeof(short), sampleCount, stdout) != sampleCount) {
+ return FALSE;
+ }
+ return TRUE;
+}
+
+static BOOL write_silence(size_t frames)
+{
+ static const short zeros[SILENCE_FILL_CHUNK_FRAMES] = {0};
+
+ while (frames > 0) {
+ size_t batch = frames < SILENCE_FILL_CHUNK_FRAMES ? frames : SILENCE_FILL_CHUNK_FRAMES;
+ if (!write_pcm(zeros, batch)) {
+ return FALSE;
+ }
+ frames -= batch;
+ }
+ return TRUE;
+}
+
+static int run_capture(DWORD excludePid, UINT32 sampleRate)
+{
+ IAudioClient *audioClient = NULL;
+ IAudioCaptureClient *captureClient = NULL;
+ HANDLE samplesReadyEvent = NULL;
+ short *monoBuffer = NULL;
+ size_t monoBufferFrames = 0;
+ LARGE_INTEGER qpcFrequency;
+ LARGE_INTEGER captureStart;
+ UINT64 emittedFrames = 0;
+ const char *errorCode = NULL;
+ HRESULT hr;
+ int exitCode = 0;
+
+ hr = activate_process_loopback(excludePid, sampleRate, &audioClient, &errorCode);
+ if (FAILED(hr)) {
+ emit_event("error", errorCode, "Process loopback activation failed (hr=0x%08lx)",
+ (unsigned long)hr);
+ return 2;
+ }
+
+ samplesReadyEvent = CreateEventW(NULL, FALSE, FALSE, NULL);
+ if (!samplesReadyEvent ||
+ FAILED(hr = IAudioClient_SetEventHandle(audioClient, samplesReadyEvent))) {
+ emit_event("error", "initialize_failed", "Failed to attach capture event (hr=0x%08lx)",
+ (unsigned long)hr);
+ IAudioClient_Release(audioClient);
+ if (samplesReadyEvent) CloseHandle(samplesReadyEvent);
+ return 2;
+ }
+
+ hr = IAudioClient_GetService(audioClient, &IID_IAudioCaptureClient, (void **)&captureClient);
+ if (FAILED(hr)) {
+ emit_event("error", "initialize_failed", "Failed to get capture client (hr=0x%08lx)",
+ (unsigned long)hr);
+ IAudioClient_Release(audioClient);
+ CloseHandle(samplesReadyEvent);
+ return 2;
+ }
+
+ hr = IAudioClient_Start(audioClient);
+ if (FAILED(hr)) {
+ emit_event("error", "start_failed", "Failed to start capture (hr=0x%08lx)",
+ (unsigned long)hr);
+ IAudioCaptureClient_Release(captureClient);
+ IAudioClient_Release(audioClient);
+ CloseHandle(samplesReadyEvent);
+ return 2;
+ }
+
+ QueryPerformanceFrequency(&qpcFrequency);
+ QueryPerformanceCounter(&captureStart);
+ emit_event("start", NULL, NULL);
+
+ while (InterlockedCompareExchange(&g_running, TRUE, TRUE)) {
+ UINT32 packetFrames = 0;
+ LARGE_INTEGER now;
+ UINT64 targetFrames;
+ UINT64 drainedFrames = 0;
+
+ WaitForSingleObject(samplesReadyEvent, CAPTURE_WAIT_TIMEOUT_MS);
+
+ /* The virtual device does no buffering of its own, so drain every
+ * available packet per wakeup. */
+ for (;;) {
+ BYTE *data = NULL;
+ UINT32 frames = 0;
+ DWORD flags = 0;
+
+ hr = IAudioCaptureClient_GetNextPacketSize(captureClient, &packetFrames);
+ if (FAILED(hr) || packetFrames == 0) {
+ break;
+ }
+
+ hr = IAudioCaptureClient_GetBuffer(captureClient, &data, &frames, &flags, NULL, NULL);
+ if (FAILED(hr)) {
+ break;
+ }
+
+ if (frames > 0) {
+ if (frames > monoBufferFrames) {
+ short *grown = (short *)realloc(monoBuffer, frames * sizeof(short));
+ if (!grown) {
+ IAudioCaptureClient_ReleaseBuffer(captureClient, frames);
+ hr = E_OUTOFMEMORY;
+ break;
+ }
+ monoBuffer = grown;
+ monoBufferFrames = frames;
+ }
+
+ if (flags & AUDCLNT_BUFFERFLAGS_SILENT) {
+ memset(monoBuffer, 0, frames * sizeof(short));
+ } else {
+ const short *stereo = (const short *)data;
+ UINT32 i;
+ for (i = 0; i < frames; i++) {
+ monoBuffer[i] = (short)(((int)stereo[i * 2] + (int)stereo[i * 2 + 1]) / 2);
+ }
+ }
+
+ if (!write_pcm(monoBuffer, frames)) {
+ IAudioCaptureClient_ReleaseBuffer(captureClient, frames);
+ emit_event("error", "stdout_write_failed",
+ "Failed to write captured audio to stdout");
+ exitCode = 2;
+ goto done;
+ }
+ emittedFrames += frames;
+ drainedFrames += frames;
+ }
+
+ hr = IAudioCaptureClient_ReleaseBuffer(captureClient, frames);
+ if (FAILED(hr)) {
+ break;
+ }
+ }
+
+ if (FAILED(hr) && hr != AUDCLNT_S_BUFFER_EMPTY) {
+ emit_event("error", "wasapi_capture_failed", "Capture read failed (hr=0x%08lx)",
+ (unsigned long)hr);
+ exitCode = 2;
+ goto done;
+ }
+
+ /* Process loopback delivers nothing while no excluded-mix audio is
+ * rendering; keep the timeline continuous against the wall clock. */
+ QueryPerformanceCounter(&now);
+ targetFrames =
+ (UINT64)((now.QuadPart - captureStart.QuadPart) * (LONGLONG)sampleRate /
+ qpcFrequency.QuadPart);
+ if (targetFrames > emittedFrames) {
+ UINT64 gapFrames = targetFrames - emittedFrames;
+ if (gapFrames >= (UINT64)sampleRate * SILENCE_GAP_MAX_MS / 1000) {
+ /* QPC keeps counting through system sleep; rebase the clock
+ * so resume does not flood the pipe with hours of silence. */
+ captureStart.QuadPart =
+ now.QuadPart -
+ (LONGLONG)(emittedFrames * (UINT64)qpcFrequency.QuadPart / sampleRate);
+ emit_event("warning", "timeline_rebased",
+ "Capture clock jumped; audio timeline rebased");
+ } else if (gapFrames >= (UINT64)sampleRate * SILENCE_GAP_THRESHOLD_MS / 1000) {
+ if (drainedFrames > 0) {
+ /* Audio is flowing, so the deficit is drift between the
+ * audio engine clock and QPC, not real silence. Rebase
+ * instead of splicing silence into continuous audio. */
+ captureStart.QuadPart =
+ now.QuadPart -
+ (LONGLONG)(emittedFrames * (UINT64)qpcFrequency.QuadPart / sampleRate);
+ } else {
+ if (!write_silence((size_t)gapFrames)) {
+ emit_event("error", "stdout_write_failed",
+ "Failed to write silence to stdout");
+ exitCode = 2;
+ goto done;
+ }
+ emittedFrames = targetFrames;
+ }
+ }
+ }
+
+ fflush(stdout);
+ }
+
+done:
+ IAudioClient_Stop(audioClient);
+ IAudioCaptureClient_Release(captureClient);
+ IAudioClient_Release(audioClient);
+ CloseHandle(samplesReadyEvent);
+ free(monoBuffer);
+ return exitCode;
+}
+
+/* ========================================================================
+ * Probe
+ * ======================================================================== */
+
+static int run_probe(void)
+{
+ IAudioClient *audioClient = NULL;
+ const char *errorCode = NULL;
+ HRESULT hr;
+
+ hr = activate_process_loopback(GetCurrentProcessId(), DEFAULT_SAMPLE_RATE, &audioClient,
+ &errorCode);
+ if (FAILED(hr)) {
+ emit_probe_result(FALSE, errorCode, hr);
+ return 0;
+ }
+
+ IAudioClient_Release(audioClient);
+ emit_probe_result(TRUE, NULL, S_OK);
+ return 0;
+}
+
+/* ========================================================================
+ * Lifecycle
+ * ======================================================================== */
+
+static DWORD WINAPI stdin_monitor_thread(LPVOID param)
+{
+ HANDLE stdinHandle = GetStdHandle(STD_INPUT_HANDLE);
+ char buffer[64];
+ DWORD bytesRead;
+
+ (void)param;
+ while (ReadFile(stdinHandle, buffer, sizeof(buffer), &bytesRead, NULL) && bytesRead > 0) {
+ }
+
+ InterlockedExchange(&g_running, FALSE);
+ return 0;
+}
+
+static BOOL WINAPI console_ctrl_handler(DWORD ctrlType)
+{
+ (void)ctrlType;
+ InterlockedExchange(&g_running, FALSE);
+ return TRUE;
+}
+
+int main(int argc, char *argv[])
+{
+ const char *command = argc > 1 ? argv[1] : NULL;
+ DWORD excludePid = GetCurrentProcessId();
+ UINT32 sampleRate = DEFAULT_SAMPLE_RATE;
+ HRESULT hr;
+ int exitCode;
+ int i;
+
+ if (!command || (strcmp(command, "probe") != 0 && strcmp(command, "start") != 0)) {
+ fprintf(stderr, "Usage: windows-system-audio-helper <probe|start> "
+ "[--exclude-pid N] [--sample-rate N]\n");
+ return 1;
+ }
+
+ for (i = 2; i < argc - 1; i++) {
+ if (strcmp(argv[i], "--exclude-pid") == 0) {
+ excludePid = (DWORD)strtoul(argv[++i], NULL, 10);
+ } else if (strcmp(argv[i], "--sample-rate") == 0) {
+ sampleRate = (UINT32)strtoul(argv[++i], NULL, 10);
+ }
+ }
+ if (excludePid == 0 || sampleRate == 0) {
+ fprintf(stderr, "Invalid --exclude-pid or --sample-rate value\n");
+ return 1;
+ }
+
+ hr = CoInitializeEx(NULL, COINIT_MULTITHREADED);
+ if (FAILED(hr)) {
+ if (strcmp(command, "probe") == 0) {
+ emit_probe_result(FALSE, "com_init_failed", hr);
+ return 0;
+ }
+ emit_event("error", "com_init_failed", "COM initialization failed (hr=0x%08lx)",
+ (unsigned long)hr);
+ return 2;
+ }
+
+ if (strcmp(command, "probe") == 0) {
+ exitCode = run_probe();
+ } else {
+ _setmode(_fileno(stdout), _O_BINARY);
+ SetConsoleCtrlHandler(console_ctrl_handler, TRUE);
+ HANDLE stdinThread = CreateThread(NULL, 0, stdin_monitor_thread, NULL, 0, NULL);
+ if (stdinThread) {
+ CloseHandle(stdinThread);
+ } else {
+ emit_event("warning", "stdin_monitor_failed", "Parent-death detection unavailable");
+ }
+ exitCode = run_capture(excludePid, sampleRate);
+ }
+
+ CoUninitialize();
+ return exitCode;
+}
diff --git a/scripts/download-windows-system-audio-helper.js b/scripts/download-windows-system-audio-helper.js
new file mode 100644
index 000000000..63dc4ce67
--- /dev/null
+++ b/scripts/download-windows-system-audio-helper.js
@@ -0,0 +1,142 @@
+#!/usr/bin/env node
+/**
+ * Downloads prebuilt Windows system audio helper binary from GitHub releases.
+ * Used for WASAPI process-loopback system audio capture in meeting notes.
+ *
+ * Usage:
+ * node scripts/download-windows-system-audio-helper.js [--force]
+ *
+ * Options:
+ * --force Re-download even if binary already exists
+ */
+
+const fs = require("fs");
+const path = require("path");
+const {
+ downloadFile,
+ extractZip,
+ fetchLatestRelease,
+ setExecutable,
+} = require("./lib/download-utils");
+
+const REPO = "OpenWhispr/openwhispr";
+const TAG_PREFIX = "windows-system-audio-helper-v";
+const ZIP_NAME = "windows-system-audio-helper-win32-x64.zip";
+const BINARY_NAME = "windows-system-audio-helper.exe";
+
+// Version can be pinned via environment variable for reproducible builds
+const VERSION_OVERRIDE = process.env.WINDOWS_SYSTEM_AUDIO_HELPER_VERSION || null;
+
+const BIN_DIR = path.join(__dirname, "..", "resources", "bin");
+
+async function main() {
+ // Only needed on Windows
+ if (process.platform !== "win32") {
+ console.log("[windows-system-audio-helper] Skipping download (not Windows)");
+ return;
+ }
+
+ const forceDownload = process.argv.includes("--force");
+ const outputPath = path.join(BIN_DIR, BINARY_NAME);
+
+ // Check if already exists
+ if (fs.existsSync(outputPath) && !forceDownload) {
+ console.log("[windows-system-audio-helper] Already exists (use --force to re-download)");
+ console.log(` ${outputPath}`);
+ return;
+ }
+
+ // Fetch release (pinned version or latest)
+ if (VERSION_OVERRIDE) {
+ console.log(`\n[windows-system-audio-helper] Using pinned version: ${VERSION_OVERRIDE}`);
+ } else {
+ console.log("\n[windows-system-audio-helper] Fetching latest release...");
+ }
+ const release = await fetchLatestRelease(
+ REPO,
+ VERSION_OVERRIDE ? { tag: VERSION_OVERRIDE } : { tagPrefix: TAG_PREFIX }
+ );
+
+ if (!release) {
+ console.error(
+ "[windows-system-audio-helper] Could not find a release matching:",
+ VERSION_OVERRIDE || TAG_PREFIX
+ );
+ console.log(
+ "[windows-system-audio-helper] Meeting system audio will use Chromium loopback fallback"
+ );
+ return;
+ }
+
+ // Find the zip asset
+ const zipAsset = release.assets.find((a) => a.name === ZIP_NAME);
+ if (!zipAsset) {
+ console.error(
+ `[windows-system-audio-helper] Release ${release.tag} does not contain ${ZIP_NAME}`
+ );
+ console.log(
+ "[windows-system-audio-helper] Available assets:",
+ release.assets.map((a) => a.name).join(", ")
+ );
+ return;
+ }
+
+ console.log(`\nDownloading Windows system audio helper (${release.tag})...\n`);
+
+ fs.mkdirSync(BIN_DIR, { recursive: true });
+
+ const zipPath = path.join(BIN_DIR, ZIP_NAME);
+ console.log(` Downloading from: ${zipAsset.url}`);
+
+ try {
+ await downloadFile(zipAsset.url, zipPath);
+
+ // Extract zip
+ const extractDir = path.join(BIN_DIR, "temp-windows-system-audio-helper");
+ fs.mkdirSync(extractDir, { recursive: true });
+
+ console.log(" Extracting...");
+ await extractZip(zipPath, extractDir);
+
+ // Find and copy the binary
+ const binaryPath = path.join(extractDir, BINARY_NAME);
+ if (fs.existsSync(binaryPath)) {
+ fs.copyFileSync(binaryPath, outputPath);
+ setExecutable(outputPath);
+ console.log(` Extracted to: ${BINARY_NAME}`);
+ } else {
+ throw new Error(`Binary not found in archive: ${BINARY_NAME}`);
+ }
+
+ // Cleanup
+ fs.rmSync(extractDir, { recursive: true, force: true });
+ if (fs.existsSync(zipPath)) {
+ fs.unlinkSync(zipPath);
+ }
+
+ const stats = fs.statSync(outputPath);
+ console.log(
+ `\n[windows-system-audio-helper] Successfully downloaded ${release.tag} (${Math.round(stats.size / 1024)}KB)`
+ );
+ } catch (error) {
+ console.error(`\n[windows-system-audio-helper] Download failed: ${error.message}`);
+
+ // Cleanup on failure
+ if (fs.existsSync(zipPath)) {
+ fs.unlinkSync(zipPath);
+ }
+
+ // Don't fail the build — meeting capture falls back to Chromium loopback
+ console.log(
+ "[windows-system-audio-helper] Meeting system audio will use Chromium loopback fallback"
+ );
+ console.log(
+ "[windows-system-audio-helper] To compile locally, install Visual Studio Build Tools or MinGW-w64"
+ );
+ }
+}
+
+main().catch((error) => {
+ console.error("[windows-system-audio-helper] Unexpected error:", error);
+ // Don't fail the build
+});
diff --git a/src/components/MeetingRecordingMount.tsx b/src/components/MeetingRecordingMount.tsx
index ceea32d61..22cd3b246 100644
--- a/src/components/MeetingRecordingMount.tsx
+++ b/src/components/MeetingRecordingMount.tsx
@@ -1,4 +1,6 @@
import { useEffect } from "react";
+import { useTranslation } from "react-i18next";
+import { useToast } from "./ui/useToast";
import {
getMicAnalyser,
primeMeetingWorklet,
@@ -9,12 +11,24 @@ const EMA_PREV = 0.5;
const EMA_NEXT = 0.5;
export default function MeetingRecordingMount(): null {
+ const { t } = useTranslation();
+ const { toast } = useToast();
const isRecording = useMeetingRecordingStore((s) => s.isRecording);
+ const error = useMeetingRecordingStore((s) => s.error);
useEffect(() => {
primeMeetingWorklet();
}, []);
+ useEffect(() => {
+ if (!error) return;
+ toast({
+ title: t("notes.meeting.title"),
+ description: error,
+ variant: "destructive",
+ });
+ }, [error, toast, t]);
+
useEffect(() => {
if (!isRecording) return;
diff --git a/src/helpers/ipcHandlers.js b/src/helpers/ipcHandlers.js
index 12baf0ea2..1076096fb 100644
--- a/src/helpers/ipcHandlers.js
+++ b/src/helpers/ipcHandlers.js
@@ -330,6 +330,7 @@ class IPCHandlers {
this.meetingDetectionEngine = managers.meetingDetectionEngine;
this.audioTapManager = managers.audioTapManager;
this.linuxPortalAudioManager = managers.linuxPortalAudioManager;
+ this.windowsLoopbackAudioManager = managers.windowsLoopbackAudioManager;
this.meetingAecManager = managers.meetingAecManager;
this.oauthProtocolRegistered = managers.oauthProtocolRegistered === true;
this.oauthProtocol = managers.oauthProtocol || "openwhispr";
@@ -3474,14 +3475,27 @@ class IPCHandlers {
});
};
+ // System audio is always capturable on Windows: via the native WASAPI
+ // process-loopback helper when available (hears every output device),
+ // otherwise via Chromium's default-device loopback in the renderer.
+ const getWindowsSystemAudioAccess = async () => {
+ const capability = await this.windowsLoopbackAudioManager?.getCapability().catch(() => ({
+ available: false,
+ }));
+ const helperAvailable = !!capability?.available;
+
+ return buildSystemAudioAccess({
+ granted: true,
+ status: "granted",
+ mode: "loopback",
+ supportsNativeCapture: helperAvailable,
+ strategy: helperAvailable ? "wasapi-loopback" : "loopback",
+ });
+ };
+
const getSystemAudioAccess = async () => {
if (process.platform === "win32") {
- return buildSystemAudioAccess({
- granted: true,
- status: "granted",
- mode: "loopback",
- strategy: "loopback",
- });
+ return getWindowsSystemAudioAccess();
}
if (process.platform === "linux") {
@@ -3505,12 +3519,7 @@ class IPCHandlers {
ipcMain.handle("request-system-audio-access", async () => {
if (process.platform === "win32") {
- return buildSystemAudioAccess({
- granted: true,
- status: "granted",
- mode: "loopback",
- strategy: "loopback",
- });
+ return getWindowsSystemAudioAccess();
}
if (process.platform === "linux") {
@@ -4487,9 +4496,14 @@ class IPCHandlers {
};
}
- if (mode === "loopback") {
- return { mode, strategy: "loopback" };
+ if (process.platform === "win32") {
+ const windowsAccess = await getWindowsSystemAudioAccess();
+ return { mode: windowsAccess.mode, strategy: windowsAccess.strategy };
}
+
+ // Unreachable today (loopback implies win32 or linux, both handled
+ // above), but callers destructure the result, so never return undefined.
+ return { mode, strategy: "unsupported" };
};
const hasNativeMeetingSystemAudio = () => getMeetingSystemAudioMode() === "native";
@@ -5291,6 +5305,9 @@ class IPCHandlers {
if (this.linuxPortalAudioManager) {
await this.linuxPortalAudioManager.stop().catch(() => {});
}
+ if (this.windowsLoopbackAudioManager) {
+ await this.windowsLoopbackAudioManager.stop().catch(() => {});
+ }
await stopMeetingAec();
await stopLiveSpeakerIdentification().catch(() => {});
resetMeetingLocalState();
@@ -5612,23 +5629,9 @@ class IPCHandlers {
}
};
- const startNativeMeetingSystemAudio = async (event) => {
+ const startManagedMeetingSystemAudio = (event, manager, warningLabel) => {
const win = BrowserWindow.fromWebContents(event.sender);
- await this.audioTapManager.start({
- onChunk: (chunk) => {
- sendMeetingAudio(chunk, "system");
- },
- onError: (error) => {
- if (win && !win.isDestroyed()) {
- win.webContents.send("meeting-transcription-error", error.message);
- }
- },
- });
- };
-
- const startLinuxMeetingSystemAudio = async (event) => {
- const win = BrowserWindow.fromWebContents(event.sender);
- await this.linuxPortalAudioManager.start({
+ return manager.start({
onChunk: (chunk) => {
sendMeetingAudio(chunk, "system");
},
@@ -5639,7 +5642,7 @@ class IPCHandlers {
},
onWarning: (warning) => {
debugLogger.warn(
- "Linux PipeWire system audio warning",
+ warningLabel,
{ code: warning.code, message: warning.message },
"meeting"
);
@@ -5669,7 +5672,11 @@ class IPCHandlers {
) => {
if (systemAudioMode === "native") {
try {
- await startNativeMeetingSystemAudio(event);
+ await startManagedMeetingSystemAudio(
+ event,
+ this.audioTapManager,
+ "macOS system audio tap warning"
+ );
return { systemAudioMode, systemAudioStrategy };
} catch (error) {
debugLogger.warn(
@@ -5682,12 +5689,36 @@ class IPCHandlers {
}
}
+ if (systemAudioStrategy === "wasapi-loopback") {
+ try {
+ await startManagedMeetingSystemAudio(
+ event,
+ this.windowsLoopbackAudioManager,
+ "Windows system audio warning"
+ );
+ return { systemAudioMode, systemAudioStrategy };
+ } catch (error) {
+ debugLogger.warn(
+ `Windows system audio helper failed ${context}, falling back to renderer loopback`,
+ { error: error.message },
+ "meeting"
+ );
+ // The renderer captures via Chromium's display-media loopback when
+ // it sees the downgraded strategy in the start result.
+ return { systemAudioMode, systemAudioStrategy: "loopback" };
+ }
+ }
+
if (systemAudioStrategy !== "pipewire-loopback") {
return { systemAudioMode, systemAudioStrategy };
}
try {
- await startLinuxMeetingSystemAudio(event);
+ await startManagedMeetingSystemAudio(
+ event,
+ this.linuxPortalAudioManager,
+ "Linux PipeWire system audio warning"
+ );
return { systemAudioMode, systemAudioStrategy };
} catch (error) {
debugLogger.warn(
@@ -5713,6 +5744,9 @@ class IPCHandlers {
if (this.linuxPortalAudioManager) {
await this.linuxPortalAudioManager.stop().catch(() => {});
}
+ if (this.windowsLoopbackAudioManager) {
+ await this.windowsLoopbackAudioManager.stop().catch(() => {});
+ }
flushPendingMeetingMicChunks(true);
await stopMeetingAec();
diff --git a/src/helpers/windowsLoopbackAudioManager.js b/src/helpers/windowsLoopbackAudioManager.js
new file mode 100644
index 000000000..5e16b2709
--- /dev/null
+++ b/src/helpers/windowsLoopbackAudioManager.js
@@ -0,0 +1,387 @@
+const { spawn } = require("child_process");
+const fs = require("fs");
+const path = require("path");
+const debugLogger = require("./debugLogger");
+
+const START_TIMEOUT_MS = 10000;
+const STOP_TIMEOUT_MS = 3000;
+const PROBE_TIMEOUT_MS = 5000;
+const TRANSIENT_CAPABILITY_TTL_MS = 30000;
+const SAMPLE_RATE = 24000;
+const BINARY_NAME = "windows-system-audio-helper.exe";
+
+// Captures system audio on Windows via a native WASAPI process-loopback
+// helper. Unlike Chromium's display-media loopback (which only hears the
+// default render device), process loopback hears every application on every
+// output device and excludes OpenWhispr's own audio.
+class WindowsLoopbackAudioManager {
+ constructor() {
+ this.process = null;
+ this.stderrBuffer = "";
+ this.onChunk = null;
+ this.onError = null;
+ this.onWarning = null;
+ this.isStopping = false;
+ this.cachedCapability = null;
+ this.cachedCapabilityExpiresAt = 0;
+ this.capabilityPromise = null;
+ }
+
+ isSupported() {
+ return process.platform === "win32";
+ }
+
+ isAvailable() {
+ return !!this.resolveBinary();
+ }
+
+ resolveBinary() {
+ const candidates = new Set([path.join(__dirname, "..", "..", "resources", "bin", BINARY_NAME)]);
+
+ if (process.resourcesPath) {
+ candidates.add(path.join(process.resourcesPath, BINARY_NAME));
+ candidates.add(path.join(process.resourcesPath, "bin", BINARY_NAME));
+ candidates.add(path.join(process.resourcesPath, "resources", "bin", BINARY_NAME));
+ candidates.add(
+ path.join(process.resourcesPath, "app.asar.unpacked", "resources", "bin", BINARY_NAME)
+ );
+ }
+
+ for (const candidate of candidates) {
+ if (fs.existsSync(candidate)) {
+ return candidate;
+ }
+ }
+
+ return null;
+ }
+
+ async getCapability({ force = false } = {}) {
+ if (!this.isSupported()) {
+ return { available: false, error: "Not running on Windows." };
+ }
+
+ if (!force && this.cachedCapability && Date.now() < this.cachedCapabilityExpiresAt) {
+ return this.cachedCapability;
+ }
+
+ if (!force && this.capabilityPromise) {
+ return this.capabilityPromise;
+ }
+
+ // Definitive probe results are cached for the session. Transient failures
+ // (the helper's own activation timeout, a spawn failure, a probe that hung)
+ // are cached only briefly so a momentary audio-stack hiccup can't pin the
+ // native path "unavailable" until restart, while still bounding how often
+ // IPC capability checks can respawn the probe.
+ const promise = this._probeCapability()
+ .then((capability) => {
+ this._cacheCapability(capability, this._isTransientProbeFailure(capability));
+ return capability;
+ })
+ .catch((error) => {
+ debugLogger.warn(
+ "[WindowsLoopbackAudioManager] Capability probe failed",
+ { error: error.message },
+ "meeting"
+ );
+ const capability = { available: false, error: error.message };
+ this._cacheCapability(capability, true);
+ return capability;
+ })
+ .finally(() => {
+ this.capabilityPromise = null;
+ });
+
+ this.capabilityPromise = promise;
+ return promise;
+ }
+
+ _cacheCapability(capability, transient) {
+ this.cachedCapability = capability;
+ this.cachedCapabilityExpiresAt = transient
+ ? Date.now() + TRANSIENT_CAPABILITY_TTL_MS
+ : Infinity;
+ }
+
+ _isTransientProbeFailure(capability) {
+ return !capability.available && /activation_timeout/i.test(capability.error || "");
+ }
+
+ async start({ onChunk, onError, onWarning } = {}) {
+ const capability = await this.getCapability();
+ if (!capability.available) {
+ throw new Error(capability.error || "Windows system audio helper is unavailable.");
+ }
+
+ if (this.process) {
+ this.onChunk = onChunk || null;
+ this.onError = onError || null;
+ this.onWarning = onWarning || null;
+ return;
+ }
+
+ const binaryPath = this.resolveBinary();
+ const args = [
+ "start",
+ "--exclude-pid",
+ String(process.pid),
+ "--sample-rate",
+ String(SAMPLE_RATE),
+ ];
+
+ // stdin stays piped so the helper can detect parent death via EOF.
+ const child = spawn(binaryPath, args, {
+ stdio: ["pipe", "pipe", "pipe"],
+ windowsHide: true,
+ });
+
+ this.process = child;
+ this.onChunk = onChunk || null;
+ this.onError = onError || null;
+ this.onWarning = onWarning || null;
+ this.isStopping = false;
+ this.stderrBuffer = "";
+
+ await new Promise((resolve, reject) => {
+ let settled = false;
+ let fatalErrorReported = false;
+ const timeout = setTimeout(() => {
+ finish(reject, new Error("Timed out starting Windows system audio capture."), true);
+ }, START_TIMEOUT_MS);
+
+ const finish = (callback, value, shouldStop = false) => {
+ if (settled) return;
+ settled = true;
+ clearTimeout(timeout);
+ if (shouldStop) {
+ void this.stop();
+ }
+ callback(value);
+ };
+
+ child.stdout.on("data", (chunk) => {
+ if (this.process !== child) return;
+ this.onChunk?.(chunk);
+ });
+
+ child.stderr.on("data", (chunk) => {
+ this._consumeStderr(chunk, (message) => {
+ if (message.type === "start") {
+ finish(resolve);
+ return;
+ }
+
+ if (message.type === "warning") {
+ this.onWarning?.(message);
+ return;
+ }
+
+ if (message.type === "error") {
+ const error = this._buildProcessError(message);
+ if (!settled) {
+ finish(reject, error, true);
+ } else {
+ fatalErrorReported = true;
+ this.onError?.(error);
+ }
+ }
+ });
+ });
+
+ child.on("error", (error) => {
+ if (this.process === child) {
+ this.process = null;
+ }
+ finish(reject, error);
+ });
+
+ child.on("exit", (code, signal) => {
+ const wasStopping = this.isStopping;
+ if (this.process === child) {
+ this.process = null;
+ }
+
+ if (!settled) {
+ finish(
+ reject,
+ new Error(
+ `Windows system audio helper exited before start (code ${code ?? "null"}, signal ${signal ?? "null"}).`
+ )
+ );
+ return;
+ }
+
+ // Skip the synthetic exit error when the helper already delivered a
+ // specific JSON error event, so the informative message isn't
+ // clobbered by the generic one.
+ if (!wasStopping && !fatalErrorReported) {
+ this.onError?.(
+ new Error(
+ `Windows system audio helper exited unexpectedly (code ${code ?? "null"}, signal ${signal ?? "null"}).`
+ )
+ );
+ }
+ });
+ });
+ }
+
+ async stop() {
+ if (!this.process) {
+ return;
+ }
+
+ const child = this.process;
+ this.isStopping = true;
+
+ // Resolve only once the child has actually exited (kill on timeout, then
+ // keep waiting) so cleanup below can't reset isStopping while the child is
+ // still alive — a late exit would otherwise surface a spurious
+ // "exited unexpectedly" error into a subsequent capture session.
+ await new Promise((resolve) => {
+ const timeout = setTimeout(() => {
+ try {
+ child.kill();
+ } catch {
+ resolve();
+ }
+ }, STOP_TIMEOUT_MS);
+
+ child.once("exit", () => {
+ clearTimeout(timeout);
+ resolve();
+ });
+
+ // Closing stdin signals the helper to exit gracefully.
+ try {
+ child.stdin.end();
+ } catch {
+ try {
+ child.kill();
+ } catch {
+ clearTimeout(timeout);
+ resolve();
+ }
+ }
+ });
+
+ if (this.process === child) {
+ this.process = null;
+ }
+ this.stderrBuffer = "";
+ this.onChunk = null;
+ this.onError = null;
+ this.onWarning = null;
+ this.isStopping = false;
+ }
+
+ async _probeCapability() {
+ if (!this.resolveBinary()) {
+ return { available: false, error: "Windows system audio helper binary not found." };
+ }
+
+ const result = await this._runJsonCommand(["probe"], PROBE_TIMEOUT_MS);
+ return {
+ available: !!result?.ok,
+ error: typeof result?.error === "string" ? result.error : null,
+ };
+ }
+
+ _runJsonCommand(args, timeoutMs) {
+ const child = spawn(this.resolveBinary(), args, {
+ stdio: ["ignore", "pipe", "pipe"],
+ windowsHide: true,
+ });
+
+ let stdout = "";
+ let stderr = "";
+
+ return new Promise((resolve, reject) => {
+ let settled = false;
+ const timeout = setTimeout(() => {
+ finish(
+ reject,
+ new Error(`Windows system audio helper timed out running ${args[0]}.`),
+ true
+ );
+ }, timeoutMs);
+
+ const finish = (callback, value, shouldKill = false) => {
+ if (settled) return;
+ settled = true;
+ clearTimeout(timeout);
+ if (shouldKill) {
+ try {
+ child.kill();
+ } catch {}
+ }
+ callback(value);
+ };
+
+ child.stdout.on("data", (chunk) => {
+ stdout += chunk.toString();
+ });
+
+ child.stderr.on("data", (chunk) => {
+ stderr += chunk.toString();
+ });
+
+ child.on("error", (error) => {
+ finish(reject, error);
+ });
+
+ child.on("exit", (code) => {
+ if (settled) return;
+
+ if (code !== 0) {
+ const message = stderr.trim() || stdout.trim() || `exit code ${code}`;
+ finish(reject, new Error(message));
+ return;
+ }
+
+ try {
+ finish(resolve, JSON.parse(stdout.trim() || "{}"));
+ } catch {
+ finish(
+ reject,
+ new Error(
+ `Windows system audio helper returned invalid JSON for ${args[0]}: ${stdout.trim().slice(0, 200)}`
+ )
+ );
+ }
+ });
+ });
+ }
+
+ _consumeStderr(chunk, onMessage) {
+ this.stderrBuffer += chunk.toString();
+ let newlineIndex = this.stderrBuffer.indexOf("\n");
+
+ while (newlineIndex !== -1) {
+ const line = this.stderrBuffer.slice(0, newlineIndex).trim();
+ this.stderrBuffer = this.stderrBuffer.slice(newlineIndex + 1);
+
+ if (line) {
+ try {
+ onMessage(JSON.parse(line));
+ } catch {
+ debugLogger.warn(
+ "[WindowsLoopbackAudioManager] Non-JSON stderr output",
+ { line },
+ "meeting"
+ );
+ }
+ }
+
+ newlineIndex = this.stderrBuffer.indexOf("\n");
+ }
+ }
+
+ _buildProcessError(message) {
+ const error = new Error(message.message || "Windows system audio capture failed");
+ error.code = message.code;
+ return error;
+ }
+}
+
+module.exports = WindowsLoopbackAudioManager;
diff --git a/src/stores/meetingRecordingStore.ts b/src/stores/meetingRecordingStore.ts
index 38df199ec..86238ee3f 100644
--- a/src/stores/meetingRecordingStore.ts
+++ b/src/stores/meetingRecordingStore.ts
@@ -840,6 +840,10 @@ export async function startRecording(args: StartRecordingArgs): Promise<void> {
});
const systemAudioHandledInMain =
systemAudioMode !== "unsupported" && !isRendererSystemAudioStrategy(systemAudioStrategy);
+ if (systemAudioHandledInMain && systemCaptureResult.stream) {
+ stopMediaStream(systemCaptureResult.stream);
+ systemCaptureResult = { stream: null, error: null };
+ }
const systemCaptureError = systemAudioHandledInMain ? null : systemCaptureResult.error;
if (!micResult && (systemAudioHandledInMain || systemCaptureResult.stream)) {
@@ -1116,6 +1120,11 @@ export async function startRecording(args: StartRecordingArgs): Promise<void> {
{ error: systemCaptureError.message },
"meeting"
);
+ if (micResult) {
+ useMeetingRecordingStore.setState({
+ error: "System audio capture failed. Continuing with microphone only.",
+ });
+ }
}
}
diff --git a/src/types/electron.ts b/src/types/electron.ts
index a409e7dfd..ca1fabc90 100644
--- a/src/types/electron.ts
+++ b/src/types/electron.ts
@@ -296,7 +296,12 @@ export interface AudioDiagnosticsResult {
}
export type SystemAudioMode = "native" | "loopback" | "portal" | "unsupported";
-export type SystemAudioStrategy = "native" | "loopback" | "pipewire-loopback" | "unsupported";
+export type SystemAudioStrategy =
+ | "native"
+ | "loopback"
+ | "pipewire-loopback"
+ | "wasapi-loopback"
+ | "unsupported";
export interface SystemAudioAccessResult {
granted: boolean;