omi icon indicating copy to clipboard operation
omi copied to clipboard

feat(desktop): record system audio only during meetings (new System Audio mode)

Open ThomsenDrake opened this issue 5 months ago • 3 comments

Summary

Adds a System Audio setting to the macOS desktop app (Settings → General) that controls when audio from other apps is captured, as an alternative to always capturing it.

Three modes:

  • Always — capture system audio for the whole recording (previous behavior; default).
  • Only during meetings — record nothing until you're in a call, then capture mic + system audio, and pause both when the call ends (the mic indicator stays dark outside meetings; UI shows "Waiting for a meeting…").
  • Never — never capture other apps' audio (microphone only).

The setting absorbs the previously hidden disableSystemAudioCapture debug flag (which still forces .never).

"In a call" detection (permission-free)

Uses the macOS 14.4 CoreAudio process API (kAudioHardwarePropertyProcessObjectList + kAudioProcessPropertyIsRunningInput/Output):

  • Native apps (Zoom, Teams, FaceTime, Webex, GoTo) — detected when actually using the mic, so an idle/backgrounded app no longer counts as a meeting.
  • Browser calls (Google Meet, Teams web) — detected when a browser uses the mic (matched by bundle-id prefix incl. helper processes), with a window-title fallback when Screen Recording permission is granted.
  • Sticky keep-alive — once in a browser call, recording continues while the browser keeps playing the call's audio, so muting mid-call doesn't stop recording (a browser drops mic input when muted).

Detection runs off the main thread with on/off hysteresis (debounced) to avoid flapping. ProactiveAssistantsPlugin's existing call-detection constants were centralized into a shared ConferencingApps enum.

Testing

  • 13 unit tests (MeetingGatedSystemAudioTests): call-window/bundle-id matching, hysteresis on/off, sticky keep-alive through mute, settings persistence + disableSystemAudioCapture override.
  • Live verified on macOS 26.5 (Apple Silicon, on-device Parakeet): idle Zoom → mic off (zero processes using the mic); a real Google Meet call → detected in ~150ms → mic + system recording; setting persists and applies live mid-recording.
  • Clean swift build -c release not run here, but clean debug build passes.

Notes

  • 100% Swift-side; no backend (Python/Rust) changes; no new permissions or wire-format changes.
  • Design spec: docs/superpowers/specs/2026-06-03-desktop-meeting-gated-system-audio-design.md.
  • Includes fixes from an adversarial code review (mic-start failure handling, off-main-thread probe, idempotent AudioMixer.start).
  • Known limitations (documented): a browser call joined while already muted needs Screen Recording permission (window-title path); the conversation spans the armed session with silence gaps between meetings (backend segmentation handles splitting) — per-meeting boundaries are possible future work.

ThomsenDrake avatar Jun 03 '26 15:06 ThomsenDrake

@mdmohsin7 @krushnarout could I get a review on this? Having all of my system audio get transcribed to my Omi storage is really polluting my conversation data

ThomsenDrake avatar Jun 08 '26 12:06 ThomsenDrake

@greptile-apps review

mdmohsin7 avatar Jun 09 '26 16:06 mdmohsin7

Greptile Summary

This PR adds a System Audio setting to the macOS desktop app with three modes — Always (prior behavior), Only during meetings (mic + system audio gated on call detection), and Never (mic only) — plus a MeetingDetector that uses the macOS 14.4 CoreAudio process API to detect active calls without requiring Screen Recording permission.

  • ConferencingApps centralizes the conferencing-app catalog previously duplicated in ProactiveAssistantsPlugin, and adds CoreAudio-based mic-in-use detection for native apps and browser prefix matching for browser-based calls.
  • AppState.reconcileCapture() replaces the old unconditional capture start with an idempotent gate that coalesces concurrent calls via a captureGateInFlight flag and drives the MeetingDetector lifecycle.
  • AudioMixer.start() is made idempotent to avoid resetting in-flight buffers on silent-mic re-arm; 13 unit tests cover hysteresis, sticky keep-alive, bundle-ID matching, and settings persistence.

Confidence Score: 3/5

The core capture-gating logic works correctly for common cases, but the sticky browser keep-alive has a false-positive that can leave recording running indefinitely after a call ends.

The stickyBrowserCall flag is not cleared when the grace period is first armed, so any concurrent browser audio output (YouTube, music, notifications in another tab) resets pendingOffDeadline and keeps the meeting active forever. This is a real-world scenario and the failure mode — continuous recording with no visible indication — is not obvious to the user. The async capture helpers also lack @MainActor annotations, leaving @Published state unprotected against future off-actor callers.

MeetingDetector.swift (sticky flag lifecycle) and AppState.swift (actor isolation on the new async helpers) need the most attention before shipping.

Important Files Changed

Filename Overview
desktop/Desktop/Sources/MeetingDetector.swift New file: implements hysteresis-based meeting detection with off-grace and sticky browser keep-alive; stickyBrowserCall not cleared on grace-period arm, allowing any concurrent browser audio output to cancel a meeting end.
desktop/Desktop/Sources/AppState.swift Substantial additions: reconcileCapture() gating logic with in-flight coalescing; new startMicCaptureIfNeeded/startSystemAudioCaptureIfNeeded helpers; all three lack @MainActor annotations despite accessing @Published state.
desktop/Desktop/Sources/ConferencingApps.swift New file: centralized conferencing-app catalog with CoreAudio 14.4+ process-API mic-use detection; isMeetingActiveNow() has a documentation gap (doesn't reflect sticky browser state).
desktop/Desktop/Sources/ProactiveAssistants/ProactiveAssistantsPlugin.swift Refactor: removes duplicated videoCallApps/browserApps/browserCallKeywords sets and delegates isVideoCallApp to ConferencingApps.isCallWindow; behavior-preserving.
desktop/Desktop/Sources/AudioMixer.swift Minor fix: start() is now idempotent — reuses the running mixer instead of resetting buffers, preventing silent-mic fallback from discarding in-flight audio.
desktop/Desktop/Tests/MeetingGatedSystemAudioTests.swift 13 unit tests covering hysteresis, sticky keep-alive, bundle-ID matching, and settings persistence; the sticky-then-YouTube false-positive scenario is not covered by any test.

Sequence Diagram

sequenceDiagram
    participant UI as SettingsPage
    participant AS as AssistantSettings
    participant AppState
    participant MD as MeetingDetector
    participant CA as ConferencingApps
    participant Mic as AudioCaptureService
    participant Sys as SystemAudioCaptureService

    UI->>AS: "systemAudioCaptureMode = .onlyDuringMeetings"
    AS-->>AppState: .systemAudioCaptureModeDidChange notification
    AppState->>AppState: reconcileCapture()
    AppState->>MD: "create & start()"
    MD->>CA: meetingSignal() [off main actor]
    CA-->>MD: MeetingSignal(inCall: false, ...)
    MD->>AppState: "onChange(false) → isMeetingActive=false"
    AppState-->>UI: "isAwaitingMeeting = true"

    Note over MD: Poll / workspace notification fires
    MD->>CA: meetingSignal() [off main actor]
    CA-->>MD: MeetingSignal(inCall: true, browserInvolved: true, ...)
    MD->>MD: applySignal → setActive(true)
    MD->>AppState: onChange(true)
    AppState->>AppState: reconcileCapture()
    AppState->>Mic: startCapture()
    AppState->>Sys: startCapture()
    AppState-->>UI: "isAwaitingMeeting = false"

    Note over MD: Call ends — grace period (8s)
    MD->>CA: meetingSignal() [off main actor]
    CA-->>MD: MeetingSignal(inCall: false, ...)
    MD->>MD: applyDetected(false) → pendingOffDeadline set
    Note over MD: Grace elapses
    MD->>MD: setActive(false)
    MD->>AppState: onChange(false)
    AppState->>AppState: reconcileCapture()
    AppState->>Mic: stopCapture()
    AppState->>Sys: stopCapture()
    AppState-->>UI: "isAwaitingMeeting = true"

Reviews (1): Last reviewed commit: "Merge remote-tracking branch 'origin/mai..." | Re-trigger Greptile

greptile-apps avatar Jun 09 '26 16:06 greptile-apps