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: deduplicate audio transcriptions in meeting and conversation views
Louis Beaumont680bf5f001a0
diff --git a/apps/screenpipe-app-tauri/components/rewind/timeline/audio-transcript.tsx b/apps/screenpipe-app-tauri/components/rewind/timeline/audio-transcript.tsxindex ebc431918..cd2ea23e6 100644--- a/apps/screenpipe-app-tauri/components/rewind/timeline/audio-transcript.tsx+++ b/apps/screenpipe-app-tauri/components/rewind/timeline/audio-transcript.tsx@@ -14,7 +14,7 @@ import {ParticipantsSummary,} from "@/components/conversation-bubble";import { cn } from "@/lib/utils";-import { Meeting } from "@/lib/hooks/use-meetings";+import { Meeting, deduplicateAudioItems } from "@/lib/hooks/use-meetings";interface AudioGroup {deviceName: string;@@ -228,12 +228,15 @@ export function AudioTranscript({// Sort by timestampallAudio.sort((a, b) => a.timestamp.getTime() - b.timestamp.getTime());+ // Deduplicate overlapping input/output entries (same speech captured by mic + display)+ const dedupedAudio = deduplicateAudioItems(allAudio);+// Build conversation items with grouping and gap detectionconst items: ConversationItem[] = [];let lastSpeakerId: number | undefined = undefined;let lastTimestamp: Date | null = null;- allAudio.forEach((audio) => {+ dedupedAudio.forEach((audio) => {const { speakerId } = getSpeakerInfo(audio);const isFirstInGroup = speakerId !== lastSpeakerId;@@ -263,7 +266,7 @@ export function AudioTranscript({// Compute participantsconst participantMap = new Map<number, { name: string; duration: number }>();- allAudio.forEach((audio) => {+ dedupedAudio.forEach((audio) => {const { speakerId, speakerName } = getSpeakerInfo(audio);const id = speakerId ?? -1;const existing = participantMap.get(id);@@ -285,10 +288,10 @@ export function AudioTranscript({// Time rangeconst timeRange =- allAudio.length > 0+ dedupedAudio.length > 0? {- start: allAudio[0].timestamp,- end: allAudio[allAudio.length - 1].timestamp,+ start: dedupedAudio[0].timestamp,+ end: dedupedAudio[dedupedAudio.length - 1].timestamp,}: null;@@ -307,12 +310,15 @@ export function AudioTranscript({}));+ // Deduplicate overlapping input/output entries+ const dedupedAudio = deduplicateAudioItems(allAudio);+// Build conversation itemsconst items: ConversationItem[] = [];let lastSpeakerId: number | undefined = undefined;let lastTimestamp: Date | null = null;- allAudio.forEach((audio) => {+ dedupedAudio.forEach((audio) => {const { speakerId } = getSpeakerInfo(audio);const isFirstInGroup = speakerId !== lastSpeakerId;diff --git a/apps/screenpipe-app-tauri/lib/hooks/use-meetings.tsx b/apps/screenpipe-app-tauri/lib/hooks/use-meetings.tsxindex 98f1fedf8..b9b8fef30 100644--- a/apps/screenpipe-app-tauri/lib/hooks/use-meetings.tsx+++ b/apps/screenpipe-app-tauri/lib/hooks/use-meetings.tsx@@ -23,11 +23,124 @@ export interface Meeting {frameIndexRange: { first: number; last: number };}-// Default: 3 minute gap between audio entries starts a new meeting-const GAP_THRESHOLD_MS = 3 * 60 * 1000;+// Base gap threshold — extended adaptively for longer meetings+const BASE_GAP_THRESHOLD_MS = 3 * 60 * 1000;+const EXTENDED_GAP_THRESHOLD_MS = 6 * 60 * 1000;+// Meetings with this many entries or more get the extended threshold+const EXTENDED_GAP_MIN_ENTRIES = 5;+const EXTENDED_GAP_MIN_DURATION_SECS = 120;// Minimum entries and duration to qualify as a meetingconst MIN_ENTRIES = 2;const MIN_DURATION_SECS = 10;+// Deduplication: max time diff (ms) and min text similarity to consider entries duplicates+const DEDUP_TIME_THRESHOLD_MS = 10_000;+const DEDUP_SIMILARITY_THRESHOLD = 0.7;++function textSimilarity(a: string, b: string): number {+ const la = a.toLowerCase().trim();+ const lb = b.toLowerCase().trim();+ if (la === lb) return 1;+ if (!la || !lb) return 0;+ const longer = la.length > lb.length ? la : lb;+ const shorter = la.length > lb.length ? lb : la;+ if (longer.length === 0) return 1;+ // Check if shorter is a substring of longer+ if (longer.includes(shorter)) return shorter.length / longer.length;+ // Simple word overlap+ const wordsA = new Set(la.split(/\s+/));+ const wordsB = new Set(lb.split(/\s+/));+ let overlap = 0;+ for (const w of wordsA) if (wordsB.has(w)) overlap++;+ return (2 * overlap) / (wordsA.size + wordsB.size);+}++function deduplicateAudio<T extends { audio_chunk_id: number; is_input: boolean; transcription: string; frameTimestamp: Date }>(+ entries: T[]+): T[] {+ if (entries.length <= 1) return entries;++ // Phase 1: Remove exact duplicates (same chunk_id + same transcription text)+ // This handles the case where the same audio segment appears in multiple frames+ const seen = new Set<string>();+ const uniqueEntries: T[] = [];+ for (const entry of entries) {+ const key = `${entry.audio_chunk_id}:${entry.transcription}`;+ if (!seen.has(key)) {+ seen.add(key);+ uniqueEntries.push(entry);+ }+ }++ // Phase 2: Remove cross-device duplicates (input mic + output display capture same speech)+ const kept: T[] = [];+ const removed = new Set<number>();++ for (let i = 0; i < uniqueEntries.length; i++) {+ if (removed.has(i)) continue;+ for (let j = i + 1; j < uniqueEntries.length; j++) {+ if (removed.has(j)) continue;+ if (uniqueEntries[i].is_input === uniqueEntries[j].is_input) continue;+ const timeDiff = Math.abs(+ uniqueEntries[i].frameTimestamp.getTime() - uniqueEntries[j].frameTimestamp.getTime()+ );+ if (timeDiff > DEDUP_TIME_THRESHOLD_MS) continue;+ const sim = textSimilarity(uniqueEntries[i].transcription, uniqueEntries[j].transcription);+ if (sim >= DEDUP_SIMILARITY_THRESHOLD) {+ if (uniqueEntries[j].is_input) {+ removed.add(i);+ } else {+ removed.add(j);+ }+ }+ }+ if (!removed.has(i)) kept.push(uniqueEntries[i]);+ }+ return kept;+}++// Exported for use in audio-transcript.tsx conversation view+export function deduplicateAudioItems<T extends { audio_chunk_id: number; is_input: boolean; transcription: string; timestamp: Date }>(+ entries: T[]+): T[] {+ if (entries.length <= 1) return entries;++ // Phase 1: Remove exact duplicates (same chunk_id + same transcription text)+ const seen = new Set<string>();+ const uniqueEntries: T[] = [];+ for (const entry of entries) {+ const key = `${entry.audio_chunk_id}:${entry.transcription}`;+ if (!seen.has(key)) {+ seen.add(key);+ uniqueEntries.push(entry);+ }+ }++ // Phase 2: Remove cross-device duplicates (input mic + output display capture same speech)+ const kept: T[] = [];+ const removed = new Set<number>();++ for (let i = 0; i < uniqueEntries.length; i++) {+ if (removed.has(i)) continue;+ for (let j = i + 1; j < uniqueEntries.length; j++) {+ if (removed.has(j)) continue;+ if (uniqueEntries[i].is_input === uniqueEntries[j].is_input) continue;+ const timeDiff = Math.abs(+ uniqueEntries[i].timestamp.getTime() - uniqueEntries[j].timestamp.getTime()+ );+ if (timeDiff > DEDUP_TIME_THRESHOLD_MS) continue;+ const sim = textSimilarity(uniqueEntries[i].transcription, uniqueEntries[j].transcription);+ if (sim >= DEDUP_SIMILARITY_THRESHOLD) {+ if (uniqueEntries[j].is_input) {+ removed.add(i);+ } else {+ removed.add(j);+ }+ }+ }+ if (!removed.has(i)) kept.push(uniqueEntries[i]);+ }+ return kept;+}function detectMeetings(frames: StreamTimeSeriesResponse[]): Meeting[] {if (!frames.length) return [];@@ -56,20 +169,32 @@ function detectMeetings(frames: StreamTimeSeriesResponse[]): Meeting[] {(a, b) => a.frameTimestamp.getTime() - b.frameTimestamp.getTime());- // 3. Group into meetings by gap threshold+ // 2b. Deduplicate overlapping input/output entries+ const dedupedAudio = deduplicateAudio(allAudio);+ if (dedupedAudio.length === 0) return [];++ // 3. Group into meetings by adaptive gap thresholdconst meetingGroups: AudioEntryWithTimestamp[][] = [];- let currentGroup: AudioEntryWithTimestamp[] = [allAudio[0]];+ let currentGroup: AudioEntryWithTimestamp[] = [dedupedAudio[0]];- for (let i = 1; i < allAudio.length; i++) {+ for (let i = 1; i < dedupedAudio.length; i++) {const gap =- allAudio[i].frameTimestamp.getTime() -- allAudio[i - 1].frameTimestamp.getTime();+ dedupedAudio[i].frameTimestamp.getTime() -+ dedupedAudio[i - 1].frameTimestamp.getTime();++ // Use extended threshold for established meetings+ const groupDuration = currentGroup.reduce((s, e) => s + e.duration_secs, 0);+ const threshold =+ currentGroup.length >= EXTENDED_GAP_MIN_ENTRIES &&+ groupDuration >= EXTENDED_GAP_MIN_DURATION_SECS+ ? EXTENDED_GAP_THRESHOLD_MS+ : BASE_GAP_THRESHOLD_MS;- if (gap > GAP_THRESHOLD_MS) {+ if (gap > threshold) {meetingGroups.push(currentGroup);- currentGroup = [allAudio[i]];+ currentGroup = [dedupedAudio[i]];} else {- currentGroup.push(allAudio[i]);+ currentGroup.push(dedupedAudio[i]);}}meetingGroups.push(currentGroup);