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
fix windows live meeting transcription
louis0301956e7b610fda1a
diff --git a/crates/screenpipe-audio/src/audio_manager/manager.rs b/crates/screenpipe-audio/src/audio_manager/manager.rsindex e201d4c3e..76de62750 100644--- a/crates/screenpipe-audio/src/audio_manager/manager.rs+++ b/crates/screenpipe-audio/src/audio_manager/manager.rs@@ -793,11 +793,10 @@ impl AudioManager {};// Meeting live transcription has its own provider/session path.- // While that path is actively accepting low-latency frames, do- // not also run the same audio through the background STT path.- // The durable audio chunk was already written above; if live- // streaming is unavailable, the controller drops this flag and- // background transcription resumes normally.+ // While a live session is active, do not also run the same+ // audio through the background STT path. The durable audio+ // chunk was already written above; background transcription+ // resumes when the live session ends.if meeting_audio_tap.background_suppressed() {had_deferred_segments = true;metrics.record_segment_deferred();diff --git a/crates/screenpipe-audio/src/core/run_record_and_transcribe.rs b/crates/screenpipe-audio/src/core/run_record_and_transcribe.rsindex 5f365e44b..87cb8042a 100644--- a/crates/screenpipe-audio/src/core/run_record_and_transcribe.rs+++ b/crates/screenpipe-audio/src/core/run_record_and_transcribe.rs@@ -78,12 +78,27 @@ const INPUT_SILENT_BUFFER_TIMEOUT_SECS: u64 = 30;/// CoreAudio zero-fill produces exact 0.0; any real input source — even/// a muted-by-hand AirPods mic — sits well above this floor.const SILENT_BUFFER_PEAK_THRESHOLD: f32 = 1e-6;+const RECORDER_OUTPUT_CHANNELS: u16 = 1;#[inline]fn is_silent_buffer(chunk: &[f32]) -> bool {!chunk.is_empty() && chunk.iter().all(|s| s.abs() < SILENT_BUFFER_PEAK_THRESHOLD)}+fn meeting_frame_from_recorder_output(+ samples: Vec<f32>,+ audio_stream: &AudioStream,+ captured_at_unix_ms: u64,+) -> MeetingAudioFrame {+ MeetingAudioFrame::new(+ Arc::new(samples),+ &audio_stream.device,+ audio_stream.device_config.sample_rate().0,+ RECORDER_OUTPUT_CHANNELS,+ captured_at_unix_ms,+ )+}+/// Recording always uses 30s segments. Both batch and realtime modes record identically./// The batch vs realtime distinction is in the processing layer (manager.rs):/// - Realtime: transcribe immediately after each segment@@ -205,11 +220,9 @@ pub async fn run_record_and_transcribe(let drained = source_buffer.drain_all();if let Some(tap) = live_audio_tap.as_ref() {if tap.is_active() && !drained.is_empty() {- let frame = MeetingAudioFrame::new(- Arc::new(drained.clone()),- &audio_stream.device,- audio_stream.device_config.sample_rate().0,- audio_stream.device_config.channels(),+ let frame = meeting_frame_from_recorder_output(+ drained.clone(),+ &audio_stream,now_epoch_millis(),);tap.send(frame);@@ -442,7 +455,7 @@ async fn flush_audio(data: Arc::new(send_data),device: audio_stream.device.clone(),sample_rate: audio_stream.device_config.sample_rate().0,- channels: audio_stream.device_config.channels(),+ channels: RECORDER_OUTPUT_CHANNELS,capture_timestamp,},Duration::from_secs(30),@@ -467,3 +480,26 @@ async fn flush_audio(Ok(())}++#[cfg(test)]+mod tests {+ use super::*;+ use crate::core::device::AudioDevice;++ #[test]+ fn live_tap_marks_recorder_mono_output_as_mono() {+ let device = Arc::new(AudioDevice::new(+ "Windows Mic Array".to_string(),+ DeviceType::Input,+ ));+ let (audio_stream, _tx) = AudioStream::from_sender_for_test(device, 48_000, 4);+ let samples = vec![0.1, -0.2, 0.3, -0.4];++ let frame = meeting_frame_from_recorder_output(samples.clone(), &audio_stream, 1234);++ assert_eq!(frame.channels, RECORDER_OUTPUT_CHANNELS);+ assert_eq!(frame.channels, 1);+ assert_eq!(frame.sample_rate, 48_000);+ assert_eq!(frame.samples.as_ref(), &samples);+ }+}diff --git a/crates/screenpipe-audio/src/meeting_streaming/config.rs b/crates/screenpipe-audio/src/meeting_streaming/config.rsindex e2f645cbf..65b2e1107 100644--- a/crates/screenpipe-audio/src/meeting_streaming/config.rs+++ b/crates/screenpipe-audio/src/meeting_streaming/config.rs@@ -148,6 +148,55 @@ impl FromStr for MeetingStreamingProvider {}impl MeetingStreamingConfig {+ pub fn with_provider(mut self, provider: MeetingStreamingProvider) -> Self {+ self.provider = provider;+ match self.provider {+ MeetingStreamingProvider::SelectedEngine => {+ self.api_key = None;+ self.endpoint = String::new();+ self.model = Some("selected transcription engine".to_string());+ }+ MeetingStreamingProvider::ScreenpipeCloud => {+ self.api_key = None;+ self.endpoint = endpoint_from_env(+ &["SCREENPIPE_MEETING_REALTIME_URL"],+ SCREENPIPE_CLOUD_REALTIME_URL,+ SCREENPIPE_CLOUD_REALTIME_PATH,+ );+ self.model = Some(+ env_non_empty("SCREENPIPE_MEETING_TRANSCRIPTION_MODEL")+ .unwrap_or_else(|| "nova-3".to_string()),+ );+ }+ MeetingStreamingProvider::DeepgramLive => {+ self.api_key = provider_api_key(&self.provider);+ self.endpoint = endpoint_from_env(+ &["SCREENPIPE_MEETING_DEEPGRAM_LIVE_URL"],+ DEEPGRAM_LIVE_URL,+ DEEPGRAM_LIVE_PATH,+ );+ self.model = Some(+ env_non_empty("SCREENPIPE_MEETING_TRANSCRIPTION_MODEL")+ .unwrap_or_else(|| "nova-3".to_string()),+ );+ }+ MeetingStreamingProvider::OpenAiRealtime => {+ self.api_key = provider_api_key(&self.provider);+ self.endpoint = endpoint_from_env(+ &["SCREENPIPE_MEETING_OPENAI_REALTIME_URL"],+ OPENAI_REALTIME_URL,+ SCREENPIPE_CLOUD_REALTIME_PATH,+ );+ self.model = Some(+ env_non_empty("SCREENPIPE_MEETING_TRANSCRIPTION_MODEL")+ .unwrap_or_else(|| "gpt-4o-transcribe".to_string()),+ );+ }+ MeetingStreamingProvider::Disabled => {}+ }+ self+ }+pub fn from_settings(enabled: bool,provider: &str,diff --git a/crates/screenpipe-audio/src/meeting_streaming/controller.rs b/crates/screenpipe-audio/src/meeting_streaming/controller.rsindex 5ddd7c29c..bd403c1d0 100644--- a/crates/screenpipe-audio/src/meeting_streaming/controller.rs+++ b/crates/screenpipe-audio/src/meeting_streaming/controller.rs@@ -37,6 +37,7 @@ const LIVE_MAX_SESSION_DURATION: Duration = Duration::from_secs(2 * 60 * 60);struct ActiveMeetingStream {meeting_id: i64,provider: String,+ config: MeetingStreamingConfig,live_transcription_enabled: bool,started_at: Instant,audio_frames_seen: u64,@@ -182,7 +183,6 @@ pub fn start_meeting_streaming_loop(}if session.live_transcription_enabled {route_frame_to_provider(- &config,&audio_tap,&transcription_engine,session,@@ -252,15 +252,17 @@ async fn start_streaming_session(emit_session_ended(previous);}- let readiness_error = readiness_error(config, transcription_engine).await;+ let session_config = effective_streaming_config(config, transcription_engine).await;+ let readiness_error = readiness_error(&session_config, transcription_engine).await;let live_transcription_enabled =- config.provider.supports_live_transcription() && readiness_error.is_none();- let provider = config.provider.as_str().to_string();+ session_config.provider.supports_live_transcription() && readiness_error.is_none();+ let provider = session_config.provider.as_str().to_string();audio_tap.set_active(live_transcription_enabled);- audio_tap.set_background_suppressed(false);+ audio_tap.set_background_suppressed(live_transcription_enabled);*active = Some(ActiveMeetingStream {meeting_id,provider: provider.clone(),+ config: session_config.clone(),live_transcription_enabled,started_at: Instant::now(),audio_frames_seen: 0,@@ -275,7 +277,7 @@ async fn start_streaming_session(app,title,provider: provider.clone(),- model: config.model.clone(),+ model: session_config.model.clone(),live_transcription_enabled,started_at: Utc::now(),};@@ -288,7 +290,7 @@ async fn start_streaming_session(emit_error(meeting_id,&provider,- config.model.clone(),+ session_config.model.clone(),None,error.clone(),);@@ -402,12 +404,12 @@ fn emit_status(}fn route_frame_to_provider(- config: &MeetingStreamingConfig,audio_tap: &MeetingAudioTap,transcription_engine: &Arc<RwLock<Option<TranscriptionEngine>>>,session: &mut ActiveMeetingStream,frame: MeetingAudioFrame,) {+ let config = &session.config;let key = device_stream_key(&frame);if let Some(retry_after) = session.device_retry_after.get(&key).copied() {if retry_after > Instant::now() {@@ -474,7 +476,7 @@ fn route_frame_to_provider(Err(mpsc::error::TrySendError::Closed(_)) => {session.device_senders.remove(&key);if session.device_senders.is_empty() {- audio_tap.set_background_suppressed(false);+ audio_tap.set_background_suppressed(session.live_transcription_enabled);}session.device_retry_after.insert(key.clone(),@@ -558,6 +560,46 @@ fn auto_end_reason(session: &ActiveMeetingStream, now: Instant) -> Option<AutoEnNone}+async fn effective_streaming_config(+ config: &MeetingStreamingConfig,+ transcription_engine: &Arc<RwLock<Option<TranscriptionEngine>>>,+) -> MeetingStreamingConfig {+ if config.provider != MeetingStreamingProvider::SelectedEngine {+ return config.clone();+ }++ let selected_engine = transcription_engine+ .read()+ .await+ .as_ref()+ .map(TranscriptionEngine::config);+ if selected_engine != Some(AudioTranscriptionEngine::Deepgram) {+ return config.clone();+ }++ let cloud_config = config+ .clone()+ .with_provider(MeetingStreamingProvider::ScreenpipeCloud);+ if cloud_config.live_transcription_ready() {+ info!(+ "meeting streaming: selected-engine resolved to screenpipe-cloud live because the selected transcription engine is screenpipe cloud"+ );+ return cloud_config;+ }++ let direct_deepgram_config = config+ .clone()+ .with_provider(MeetingStreamingProvider::DeepgramLive);+ if direct_deepgram_config.live_transcription_ready() {+ info!(+ "meeting streaming: selected-engine resolved to direct Deepgram live because the selected transcription engine is Deepgram"+ );+ return direct_deepgram_config;+ }++ config.clone()+}+async fn readiness_error(config: &MeetingStreamingConfig,transcription_engine: &Arc<RwLock<Option<TranscriptionEngine>>>,@@ -616,6 +658,8 @@ mod tests {ActiveMeetingStream {meeting_id: 42,provider: "selected-engine".to_string(),+ config: MeetingStreamingConfig::default()+ .with_provider(MeetingStreamingProvider::SelectedEngine),live_transcription_enabled: live,started_at: now,audio_frames_seen: 0,@@ -657,4 +701,56 @@ mod tests {assert!(!should_request_auto_end_for_inactivity(&session, now));}++ #[tokio::test]+ async fn selected_deepgram_uses_cloud_live_when_token_available() {+ let engine = TranscriptionEngine::new(+ Arc::new(AudioTranscriptionEngine::Deepgram),+ Some("unused-personal-key".to_string()),+ None,+ Vec::new(),+ Vec::new(),+ )+ .await+ .expect("deepgram engine");+ let engine_ref = Arc::new(RwLock::new(Some(engine)));+ let config = MeetingStreamingConfig::from_settings(+ true,+ "selected-engine",+ Some("cloud-token".to_string()),+ None,+ None,+ None,+ );++ let effective = effective_streaming_config(&config, &engine_ref).await;++ assert_eq!(+ effective.provider,+ MeetingStreamingProvider::ScreenpipeCloud+ );+ assert!(effective.live_transcription_ready());+ assert_eq!(effective.model.as_deref(), Some("nova-3"));+ assert!(effective.endpoint.starts_with("wss://"));+ }++ #[tokio::test]+ async fn selected_deepgram_without_live_credentials_stays_selected_engine() {+ let engine = TranscriptionEngine::new(+ Arc::new(AudioTranscriptionEngine::Deepgram),+ Some("unused-personal-key".to_string()),+ None,+ Vec::new(),+ Vec::new(),+ )+ .await+ .expect("deepgram engine");+ let engine_ref = Arc::new(RwLock::new(Some(engine)));+ let config =+ MeetingStreamingConfig::from_settings(true, "selected-engine", None, None, None, None);++ let effective = effective_streaming_config(&config, &engine_ref).await;++ assert_eq!(effective.provider, MeetingStreamingProvider::SelectedEngine);+ }}