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: timeline shows batch-transcribed audio in real-time
Louis Beaumont18fe4b38380e
diff --git a/apps/screenpipe-app-tauri/lib/hooks/use-timeline-store.tsx b/apps/screenpipe-app-tauri/lib/hooks/use-timeline-store.tsxindex 2b232109b..19867a435 100644--- a/apps/screenpipe-app-tauri/lib/hooks/use-timeline-store.tsx+++ b/apps/screenpipe-app-tauri/lib/hooks/use-timeline-store.tsx@@ -428,6 +428,35 @@ export const useTimelineStore = create<TimelineState>((set, get) => ({return;}+ // Handle audio updates from batch/reconciliation — merge+ // transcription into existing frames near the audio timestamp.+ if (data.type === "audio_update" && data.audio) {+ set((state) => {+ const audioTs = new Date(data.timestamp).getTime();+ const pad = 60_000; // ±60s window matching server+ let updated = false;+ const updatedFrames = state.frames.map((frame) => {+ const frameTs = new Date(frame.timestamp).getTime();+ if (Math.abs(frameTs - audioTs) > pad) return frame;+ // Check if this audio is already attached+ const isDuplicate = frame.devices?.some((d: any) =>+ d.audio?.some((a: any) => a.audio_chunk_id === data.audio.audio_chunk_id)+ );+ if (isDuplicate) return frame;+ updated = true;+ return {+ ...frame,+ devices: frame.devices?.map((d: any) => ({+ ...d,+ audio: [...(d.audio || []), data.audio],+ })),+ };+ });+ return updated ? { frames: updatedFrames } : {};+ });+ return;+ }+// Handle batched frames - OPTIMIZED: buffer and flush periodicallyif (Array.isArray(data)) {// Add to buffer instead of immediate state updatediff --git a/crates/screenpipe-audio/src/audio_manager/manager.rs b/crates/screenpipe-audio/src/audio_manager/manager.rsindex 1c201938c..a58c2edf6 100644--- a/crates/screenpipe-audio/src/audio_manager/manager.rs+++ b/crates/screenpipe-audio/src/audio_manager/manager.rs@@ -433,6 +433,11 @@ impl AudioManager {info!("transcription session created (will be reused across segments)");Ok(tokio::spawn(async move {+ // Track whether we've deferred segments so we can trigger reconciliation+ // when the session ends — even if the transition happens between chunks+ // (i.e. the 45s output-speech window expires between deliveries).+ let mut had_deferred_segments = false;+while let Ok(audio) = whisper_receiver.recv() {debug!("received audio from device: {:?}", audio.device.name);@@ -495,8 +500,15 @@ impl AudioManager {meeting.check_grace_period().await;let now_in_session = meeting.is_in_audio_session();- if was_in_session && !now_in_session {- // Audio session just ended — trigger immediate reconciliation+ // Detect session-end: either the transition happened during+ // check_grace_period (was=true, now=false), OR it happened+ // between chunks (was=false, now=false, but we had deferred).+ let session_just_ended = (was_in_session && !now_in_session)+ || (!now_in_session && had_deferred_segments);++ if session_just_ended {+ // Audio session ended — trigger immediate reconciliation+ had_deferred_segments = false;info!("batch mode: audio session ended, transcribing accumulated audio");@@ -518,6 +530,7 @@ impl AudioManager {}info!("batch mode: transcribed {} chunks after session end", count);} else if now_in_session {+ had_deferred_segments = true;metrics.record_segment_deferred();debug!("batch mode: in audio session, deferring transcription");} else {diff --git a/crates/screenpipe-server/src/routes/streaming.rs b/crates/screenpipe-server/src/routes/streaming.rsindex d70fd4ec9..b76de2ae1 100644--- a/crates/screenpipe-server/src/routes/streaming.rs+++ b/crates/screenpipe-server/src/routes/streaming.rs@@ -416,6 +416,8 @@ async fn handle_stream_frames_socket(// Subscribe to live frame updates from the hot cachelet mut frame_rx_cache = cache.subscribe_frames();+ // Subscribe to live audio updates (reconciliation / batch mode push)+ let mut audio_rx_cache = cache.subscribe_audio();let mut frame_rx_channel = Some(frame_rx);loop {@@ -526,6 +528,48 @@ async fn handle_stream_frames_socket(}}+ // Live audio from hot cache (reconciliation / batch mode)+ // Sends audio updates so the timeline can attach transcriptions+ // to frames that were originally sent without audio.+ result = audio_rx_cache.recv() => {+ match result {+ Ok(hot_audio) => {+ let is_live = live_subscribe.lock().await.unwrap_or(false);+ if !is_live {+ continue;+ }+ // Send a lightweight audio-update message so the+ // frontend can merge transcription into existing frames.+ let update = serde_json::json!({+ "type": "audio_update",+ "timestamp": hot_audio.timestamp,+ "audio": {+ "device_name": hot_audio.device_name,+ "is_input": hot_audio.is_input,+ "transcription": hot_audio.transcription,+ "audio_file_path": hot_audio.audio_file_path,+ "duration_secs": hot_audio.duration_secs,+ "start_offset": hot_audio.start_time.unwrap_or(0.0),+ "audio_chunk_id": hot_audio.audio_chunk_id,+ "speaker_id": hot_audio.speaker_id,+ "speaker_name": hot_audio.speaker_name,+ }+ });+ if let Err(e) = sender.send(Message::Text(update.to_string())).await {+ warn!("failed to send audio update: {}", e);+ break;+ }+ }+ Err(broadcast::error::RecvError::Lagged(n)) => {+ debug!("audio cache broadcast lagged by {} messages", n);+ }+ Err(broadcast::error::RecvError::Closed) => {+ debug!("audio cache broadcast closed");+ break;+ }+ }+ }+// Flush partial batches_ = buffer_timer.tick() => {if !frame_buffer.is_empty() {