Skip to content

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

feat(meeting-streaming): deepgram diarization + collapse render fragments

Louis Beaumont4d7de5e815ad
diff --git a/apps/screenpipe-app-tauri/lib/utils/meeting-context.ts b/apps/screenpipe-app-tauri/lib/utils/meeting-context.ts
index 7baaddc16..df5abc4f0 100644
--- a/apps/screenpipe-app-tauri/lib/utils/meeting-context.ts
+++ b/apps/screenpipe-app-tauri/lib/utils/meeting-context.ts
@@ -78,6 +78,53 @@ function sortAudioChunks(chunks: MeetingAudioChunk[]): MeetingAudioChunk[] {
});
}
+interface SpeakerTurn {
+ speakerName: string;
+ /** Timestamp of the first chunk in this turn — used for display. */
+ timestamp: string;
+ /** Timestamp of the most recent chunk merged in — used to gate further
+ * merging. Comparing against the first chunk would let arbitrarily long
+ * turns swallow new turns as long as adjacent chunks stay close. */
+ lastTimestamp: string;
+ text: string;
+}
+
+/**
+ * Collapse a sorted chunk stream into speaker turns. The live engine writes
+ * one row per ~2-3 s VAD chunk; without grouping, a 30-minute meeting becomes
+ * 500+ single-word lines that drown the summarize prompt. Two consecutive
+ * chunks fold into the same turn when they share a speaker label and the gap
+ * between them is under 10 s. The 10 s window is long enough to bridge a
+ * thinking pause, short enough to start a new turn after a real exchange.
+ */
+function groupConsecutiveSpeakerTurns(
+ chunks: MeetingAudioChunk[],
+): SpeakerTurn[] {
+ const MAX_GAP_MS = 10_000;
+ const turns: SpeakerTurn[] = [];
+ for (const c of chunks) {
+ const speakerName = c.speakerName ?? "";
+ const text = c.transcription.replace(/\s+/g, " ").trim();
+ if (!text) continue;
+ const last = turns[turns.length - 1];
+ const gap = last
+ ? timestampMs(c.timestamp) - timestampMs(last.lastTimestamp)
+ : Infinity;
+ if (last && last.speakerName === speakerName && gap < MAX_GAP_MS) {
+ last.text = `${last.text} ${text}`;
+ last.lastTimestamp = c.timestamp;
+ } else {
+ turns.push({
+ speakerName,
+ timestamp: c.timestamp,
+ lastTimestamp: c.timestamp,
+ text,
+ });
+ }
+ }
+ return turns;
+}
+
export interface SpeakerSummary {
name: string;
segment_count: number;
@@ -545,15 +592,14 @@ function renderTranscript(
activity: ActivitySummary | null,
): string {
if (full && full.length > 0) {
- return sortAudioChunks(full)
- .map((c) => {
- const ts = formatTimeShort(c.timestamp);
+ return groupConsecutiveSpeakerTurns(sortAudioChunks(full))
+ .map((g) => {
+ const ts = formatTimeShort(g.timestamp);
const sp =
- c.speakerName && c.speakerName !== "unknown"
- ? `[${c.speakerName}] `
+ g.speakerName && g.speakerName !== "unknown"
+ ? `[${g.speakerName}] `
: "";
- const txt = c.transcription.replace(/\s+/g, " ").trim();
- return `- ${ts} ${sp}${txt}`;
+ return `- ${ts} ${sp}${g.text}`;
})
.join("\n");
}
diff --git a/crates/screenpipe-audio/src/meeting_streaming/deepgram_live.rs b/crates/screenpipe-audio/src/meeting_streaming/deepgram_live.rs
index f10b6a68d..8dd0055f0 100644
--- a/crates/screenpipe-audio/src/meeting_streaming/deepgram_live.rs
+++ b/crates/screenpipe-audio/src/meeting_streaming/deepgram_live.rs
@@ -214,6 +214,7 @@ fn configure_live_query(url: &mut Url, config: &MeetingStreamingConfig) {
query.append_pair("endpointing", "800");
query.append_pair("utterance_end_ms", "1500");
query.append_pair("vad_events", "true");
+ query.append_pair("diarize", "true");
if let Some(language) = config.language.as_deref().filter(|s| !s.trim().is_empty()) {
query.append_pair("language", language);
}
@@ -327,6 +328,7 @@ fn handle_results_event(
let captured_at = latest_audio_time(latest_audio_ms);
if is_final {
+ let speaker_name = resolve_speaker_name(value, device_type, config);
let event = MeetingTranscriptFinal {
meeting_id,
provider: config.provider.as_str().to_string(),
@@ -334,7 +336,7 @@ fn handle_results_event(
item_id,
device_name: device_name.to_string(),
device_type: device_type.to_string(),
- speaker_name: None,
+ speaker_name,
transcript: transcript.to_string(),
captured_at,
};
@@ -355,6 +357,36 @@ fn handle_results_event(
}
}
+/// Pick a speaker label from a Deepgram `Results` payload with `diarize=true`.
+/// Counts speaker indices across the words array and returns the dominant one.
+/// `device_type == "input"` + `speaker 0` is treated as the local user when
+/// `local_speaker_name` is set, since deepgram numbers speakers in order of
+/// first utterance and the local user typically speaks first into their own
+/// mic. All other indices fall back to a generic `speaker N` (1-indexed).
+fn resolve_speaker_name(
+ value: &Value,
+ device_type: &str,
+ config: &MeetingStreamingConfig,
+) -> Option<String> {
+ let words = value
+ .pointer("/channel/alternatives/0/words")
+ .and_then(Value::as_array)?;
+ let mut counts: std::collections::HashMap<i64, usize> = std::collections::HashMap::new();
+ for word in words {
+ if let Some(speaker) = word.get("speaker").and_then(Value::as_i64) {
+ *counts.entry(speaker).or_insert(0) += 1;
+ }
+ }
+ let (dominant, _) = counts.into_iter().max_by_key(|&(_, n)| n)?;
+
+ if dominant == 0 && device_type == "input" {
+ if let Some(name) = config.local_speaker_name.clone() {
+ return Some(name);
+ }
+ }
+ Some(format!("speaker {}", dominant + 1))
+}
+
fn latest_audio_time(latest_audio_ms: &AtomicU64) -> DateTime<Utc> {
let ms = latest_audio_ms.load(Ordering::Relaxed);
if ms == 0 {