YC (S26) | Open Computer History | Continuously record your company computer work, map your workflows, help you find work worth automating, and power your agents' context
Rust agentsagiaiai-memoryaudio-recordingcomputer-visionhermeshermes-agentllmlocal-ailocal-firstmachine-learningmcpmultimodalopenclawprivacyrewindscreen-recordingspeech-to-textycombinator
feat(audio): add "Follow System Default" mode for audio devices
Louis Beaumont3d8563c7fca1
diff --git a/screenpipe-app-tauri/components/settings/recording-settings.tsx b/screenpipe-app-tauri/components/settings/recording-settings.tsxindex 50e054b1e..e8661f7d8 100644--- a/screenpipe-app-tauri/components/settings/recording-settings.tsx+++ b/screenpipe-app-tauri/components/settings/recording-settings.tsx@@ -1084,7 +1084,43 @@ export function RecordingSettings() {<Separator />+ {/* Follow System Default Audio */}+ <div className="flex flex-col space-y-2">+ <div className="flex items-center justify-between">+ <Label htmlFor="useSystemDefaultAudio" className="flex items-center space-x-2">+ <span>Follow system default</span>+ <TooltipProvider>+ <Tooltip>+ <TooltipTrigger>+ <HelpCircle className="h-4 w-4 cursor-default" />+ </TooltipTrigger>+ <TooltipContent side="right">+ <p>+ Automatically use system default audio devices. When you plug in a new microphone+ or change the default in System Settings, screenpipe will automatically switch to it.+ This handles device disconnects, sleep/wake, and app conflicts gracefully.+ </p>+ </TooltipContent>+ </Tooltip>+ </TooltipProvider>+ </Label>+ <Switch+ id="useSystemDefaultAudio"+ checked={settings.useSystemDefaultAudio ?? true}+ onCheckedChange={(checked) =>+ handleSettingsChange({ useSystemDefaultAudio: checked }, true)+ }+ />+ </div>+ {settings.useSystemDefaultAudio && (+ <p className="text-sm text-muted-foreground">+ Using system default input and output devices. Changes are detected automatically.+ </p>+ )}+ </div>+{/* Audio Devices */}+ {!settings.useSystemDefaultAudio && (<div className="flex flex-col space-y-2"><Label htmlFor="audioDevices" className="flex items-center space-x-2"><span>Audio devices</span>@@ -1149,6 +1185,7 @@ export function RecordingSettings() {</PopoverContent></Popover></div>+ )}{/* Languages */}<div className="flex flex-col space-y-2">diff --git a/screenpipe-app-tauri/lib/hooks/use-settings.tsx b/screenpipe-app-tauri/lib/hooks/use-settings.tsxindex f575f5f52..64c004668 100644--- a/screenpipe-app-tauri/lib/hooks/use-settings.tsx+++ b/screenpipe-app-tauri/lib/hooks/use-settings.tsx@@ -83,6 +83,8 @@ export type Settings = SettingsStore & {chatHistory?: ChatHistoryStore;ignoredUrls?: string[];searchShortcut?: string;+ /** When true, audio devices follow system default and auto-switch on changes */+ useSystemDefaultAudio?: boolean;}export const DEFAULT_PROMPT = `Rules:@@ -163,6 +165,7 @@ let DEFAULT_SETTINGS: Settings = {ocrEngine: "default",monitorIds: ["default"],audioDevices: ["default"],+ useSystemDefaultAudio: true,usePiiRemoval: false,restartInterval: 0,port: 3030,diff --git a/screenpipe-app-tauri/src-tauri/src/sidecar.rs b/screenpipe-app-tauri/src-tauri/src/sidecar.rsindex abcc86d43..89aa0b749 100644--- a/screenpipe-app-tauri/src-tauri/src/sidecar.rs+++ b/screenpipe-app-tauri/src-tauri/src/sidecar.rs@@ -287,6 +287,8 @@ async fn spawn_sidecar(app: &tauri::AppHandle, override_args: Option<Vec<String>let audio_devices = store.audio_devices.clone();+ let use_system_default_audio = store.use_system_default_audio;+let use_pii_removal = store.use_pii_removal;let port = store.port;@@ -419,6 +421,11 @@ async fn spawn_sidecar(app: &tauri::AppHandle, override_args: Option<Vec<String>}}+ // Pass use-system-default-audio flag (defaults to true in CLI, only pass when false)+ if !use_system_default_audio {+ args.push("--use-system-default-audio=false");+ }+if use_pii_removal {args.push("--use-pii-removal");}diff --git a/screenpipe-app-tauri/src-tauri/src/store.rs b/screenpipe-app-tauri/src-tauri/src/store.rsindex 2dba740fb..702587bf2 100644--- a/screenpipe-app-tauri/src-tauri/src/store.rs+++ b/screenpipe-app-tauri/src-tauri/src/store.rs@@ -123,6 +123,9 @@ pub struct SettingsStore {pub monitor_ids: Vec<String>,#[serde(rename = "audioDevices")]pub audio_devices: Vec<String>,+ /// When true, automatically follow system default audio devices+ #[serde(rename = "useSystemDefaultAudio", default = "default_true")]+ pub use_system_default_audio: bool,#[serde(rename = "usePiiRemoval")]pub use_pii_removal: bool,#[serde(rename = "restartInterval")]@@ -411,6 +414,7 @@ impl Default for SettingsStore {ocr_engine: "tesseract".to_string(),monitor_ids: vec!["default".to_string()],audio_devices: vec!["default".to_string()],+ use_system_default_audio: true,use_pii_removal: true,restart_interval: 0,port: 3030,diff --git a/screenpipe-audio/src/audio_manager/builder.rs b/screenpipe-audio/src/audio_manager/builder.rsindex e6a0b861d..bde658698 100644--- a/screenpipe-audio/src/audio_manager/builder.rs+++ b/screenpipe-audio/src/audio_manager/builder.rs@@ -34,6 +34,9 @@ pub struct AudioManagerOptions {pub output_path: Option<PathBuf>,/// Enable PII removal from audio transcriptionspub use_pii_removal: bool,+ /// When true, automatically follow system default audio devices+ /// and switch when the system default changes (e.g., device plug/unplug)+ pub use_system_default_audio: bool,}impl Default for AudioManagerOptions {@@ -59,6 +62,7 @@ impl Default for AudioManagerOptions {deepgram_url,deepgram_websocket_url,use_pii_removal: false,+ use_system_default_audio: true,}}}@@ -145,6 +149,11 @@ impl AudioManagerBuilder {self}+ pub fn use_system_default_audio(mut self, use_system_default_audio: bool) -> Self {+ self.options.use_system_default_audio = use_system_default_audio;+ self+ }+pub async fn build(&mut self, db: Arc<DatabaseManager>) -> Result<AudioManager> {self.validate_options()?;let options = &mut self.options;diff --git a/screenpipe-audio/src/audio_manager/device_monitor.rs b/screenpipe-audio/src/audio_manager/device_monitor.rsindex f0a138dc4..7b9a80021 100644--- a/screenpipe-audio/src/audio_manager/device_monitor.rs+++ b/screenpipe-audio/src/audio_manager/device_monitor.rs@@ -4,7 +4,10 @@ use anyhow::Result;use tokio::{sync::Mutex, task::JoinHandle, time::sleep};use tracing::{error, info, warn};-use crate::{core::device::parse_audio_device, device::device_manager::DeviceManager};+use crate::{+ core::device::{default_input_device, default_output_device, parse_audio_device, DeviceType},+ device::device_manager::DeviceManager,+};use super::{AudioManager, AudioManagerStatus};@@ -12,6 +15,45 @@ lazy_static::lazy_static! {pub static ref DEVICE_MONITOR: Mutex<Option<JoinHandle<()>>> = Mutex::new(None);}+/// Track the last known system default devices to detect changes+struct SystemDefaultTracker {+ last_input: Option<String>,+ last_output: Option<String>,+}++impl SystemDefaultTracker {+ fn new() -> Self {+ Self {+ last_input: None,+ last_output: None,+ }+ }++ /// Check if system default input device has changed+ fn check_input_changed(&mut self) -> Option<String> {+ let current = default_input_device().ok().map(|d| d.to_string());+ if current != self.last_input {+ let changed = current.clone();+ self.last_input = current;+ changed+ } else {+ None+ }+ }++ /// Check if system default output device has changed+ async fn check_output_changed(&mut self) -> Option<String> {+ let current = default_output_device().await.ok().map(|d| d.to_string());+ if current != self.last_output {+ let changed = current.clone();+ self.last_output = current;+ changed+ } else {+ None+ }+ }+}+pub async fn start_device_monitor(audio_manager: Arc<AudioManager>,device_manager: Arc<DeviceManager>,@@ -20,11 +62,64 @@ pub async fn start_device_monitor(*DEVICE_MONITOR.lock().await = Some(tokio::spawn(async move {let mut disconnected_devices: HashSet<String> = HashSet::new();+ let mut default_tracker = SystemDefaultTracker::new();++ // Initialize tracker with current defaults+ let _ = default_tracker.check_input_changed();+ let _ = default_tracker.check_output_changed().await;+loop {if audio_manager.status().await == AudioManagerStatus::Running {let currently_available_devices = device_manager.devices().await;let enabled_devices = audio_manager.enabled_devices().await;+ // Handle "Follow System Default" mode+ if audio_manager.use_system_default_audio().await {+ // Check if system default input changed+ if let Some(new_default_input) = default_tracker.check_input_changed() {+ info!("system default input changed to: {}", new_default_input);++ // Stop all current input devices+ for device_name in enabled_devices.iter() {+ if let Ok(device) = parse_audio_device(device_name) {+ if device.device_type == DeviceType::Input {+ let _ = audio_manager.stop_device(device_name).await;+ }+ }+ }++ // Start the new default input device+ if let Ok(new_device) = parse_audio_device(&new_default_input) {+ match audio_manager.start_device(&new_device).await {+ Ok(()) => info!("switched to new system default input: {}", new_default_input),+ Err(e) => error!("failed to start new default input {}: {}", new_default_input, e),+ }+ }+ }++ // Check if system default output changed+ if let Some(new_default_output) = default_tracker.check_output_changed().await {+ info!("system default output changed to: {}", new_default_output);++ // Stop all current output devices+ for device_name in audio_manager.enabled_devices().await.iter() {+ if let Ok(device) = parse_audio_device(device_name) {+ if device.device_type == DeviceType::Output {+ let _ = audio_manager.stop_device(device_name).await;+ }+ }+ }++ // Start the new default output device+ if let Ok(new_device) = parse_audio_device(&new_default_output) {+ match audio_manager.start_device(&new_device).await {+ Ok(()) => info!("switched to new system default output: {}", new_default_output),+ Err(e) => error!("failed to start new default output {}: {}", new_default_output, e),+ }+ }+ }+ }+// Check for stale recording handles (tasks that have finished/crashed)// This handles cases where audio stream was hijacked by another applet stale_devices = audio_manager.check_stale_recording_handles().await;@@ -46,6 +141,22 @@ pub async fn start_device_monitor(}};+ // In system default mode, try to restart with current default instead+ if audio_manager.use_system_default_audio().await {+ let current_default = match device.device_type {+ DeviceType::Input => default_input_device().ok(),+ DeviceType::Output => default_output_device().await.ok(),+ };++ if let Some(default_device) = current_default {+ if audio_manager.start_device(&default_device).await.is_ok() {+ info!("restarted with system default device: {}", default_device);+ disconnected_devices.remove(&device_name);+ continue;+ }+ }+ }+if audio_manager.start_device(&device).await.is_ok() {info!("successfully restarted device {}", device_name);disconnected_devices.remove(&device_name);diff --git a/screenpipe-audio/src/audio_manager/manager.rs b/screenpipe-audio/src/audio_manager/manager.rsindex 4ad88639f..f6a2c5e6b 100644--- a/screenpipe-audio/src/audio_manager/manager.rs+++ b/screenpipe-audio/src/audio_manager/manager.rs@@ -234,6 +234,11 @@ impl AudioManager {self.options.read().await.use_all_devices}+ /// Returns whether to follow system default audio devices+ pub async fn use_system_default_audio(&self) -> bool {+ self.options.read().await.use_system_default_audio+ }+async fn record_device(&self, device: &AudioDevice) -> Result<JoinHandle<Result<()>>> {let options = self.options.read().await;let stream = self.device_manager.stream(device).unwrap();diff --git a/screenpipe-server/src/bin/screenpipe-server.rs b/screenpipe-server/src/bin/screenpipe-server.rsindex 485759ef5..8c9dcac38 100644--- a/screenpipe-server/src/bin/screenpipe-server.rs+++ b/screenpipe-server/src/bin/screenpipe-server.rs@@ -759,7 +759,8 @@ async fn main() -> anyhow::Result<()> {.enabled_devices(audio_devices).deepgram_api_key(cli.deepgram_api_key.clone()).output_path(PathBuf::from(output_path_clone.clone().to_string()))- .use_pii_removal(cli.use_pii_removal);+ .use_pii_removal(cli.use_pii_removal)+ .use_system_default_audio(cli.use_system_default_audio);let audio_manager = match audio_manager_builder.build(db.clone()).await {Ok(manager) => Arc::new(manager),diff --git a/screenpipe-server/src/cli.rs b/screenpipe-server/src/cli.rsindex 803798dc2..5ff365bc6 100644--- a/screenpipe-server/src/cli.rs+++ b/screenpipe-server/src/cli.rs@@ -176,6 +176,12 @@ pub struct Cli {#[arg(short = 'i', long)]pub audio_device: Vec<String>,+ /// Follow system default audio devices. When enabled, screenpipe automatically+ /// switches to the current system default when devices are plugged/unplugged+ /// or the default changes in system settings.+ #[arg(long, default_value_t = true)]+ pub use_system_default_audio: bool,+// Audio devices to use for realtime audio transcription#[arg(short = 'r', long)]pub realtime_audio_device: Vec<String>,