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

chore: include other agents' changes (speaker segment, db, calendar speaker id)

Louis Beaumont5f7bc254ba64
diff --git a/apps/screenpipe-app-tauri/src-tauri/Cargo.lock b/apps/screenpipe-app-tauri/src-tauri/Cargo.lock
index 699b2f114..1981649ff 100644
--- a/apps/screenpipe-app-tauri/src-tauri/Cargo.lock
+++ b/apps/screenpipe-app-tauri/src-tauri/Cargo.lock
@@ -9074,7 +9074,7 @@ dependencies = [
[[package]]
name = "screenpipe-app"
-version = "2.2.57"
+version = "2.2.58"
dependencies = [
"anyhow",
"arboard",
diff --git a/crates/screenpipe-audio/src/speaker/segment.rs b/crates/screenpipe-audio/src/speaker/segment.rs
index 5efb4f83a..e8fb60290 100644
--- a/crates/screenpipe-audio/src/speaker/segment.rs
+++ b/crates/screenpipe-audio/src/speaker/segment.rs
@@ -72,8 +72,8 @@ fn create_speech_segment(
let embedding = match get_speaker_embedding(embedding_extractor, segment_samples) {
Ok(embedding) => embedding,
Err(e) => {
- error!("Failed to compute speaker embedding: {}", e);
- vec![0.0; 512]
+ error!("Failed to compute speaker embedding, skipping segment: {}", e);
+ return Err(anyhow::anyhow!("speaker embedding extraction failed: {}", e));
}
};
let speaker = {
@@ -203,8 +203,11 @@ impl SegmentIterator {
&self.embedding_manager,
) {
Ok(segment) => segment,
- Err(e) => {
- return Err(e);
+ Err(_) => {
+ // Skip this segment (e.g. embedding extraction failed)
+ self.is_speeching = false;
+ self.offset += self.frame_size;
+ continue;
}
};
diff --git a/crates/screenpipe-db/src/db.rs b/crates/screenpipe-db/src/db.rs
index 0440f5abe..89b06f202 100644
--- a/crates/screenpipe-db/src/db.rs
+++ b/crates/screenpipe-db/src/db.rs
@@ -937,7 +937,7 @@ impl DatabaseManager {
&self,
embedding: &[f32],
) -> Result<Option<Speaker>, SqlxError> {
- let speaker_threshold = 0.8;
+ let speaker_threshold = 0.55;
let bytes: &[u8] = embedding.as_bytes();
// First try matching against stored embeddings (up to 10 per speaker)
@@ -1090,6 +1090,35 @@ impl DatabaseManager {
Ok(rows)
}
+ /// Get the dominant unnamed speaker on input devices.
+ /// Returns the speaker_id with the most transcriptions on input that has no name set.
+ /// Requires at least `min_count` transcriptions to be considered reliable.
+ pub async fn get_dominant_unnamed_input_speaker(
+ &self,
+ min_count: i32,
+ ) -> Result<Option<i64>, SqlxError> {
+ let result = sqlx::query_scalar::<_, i64>(
+ r#"
+ SELECT at.speaker_id
+ FROM audio_transcriptions at
+ INNER JOIN speakers s ON at.speaker_id = s.id
+ WHERE at.is_input_device = 1
+ AND at.speaker_id IS NOT NULL
+ AND (s.name IS NULL OR s.name = '')
+ AND (s.hallucination IS NULL OR s.hallucination = 0)
+ GROUP BY at.speaker_id
+ HAVING COUNT(*) >= ?1
+ ORDER BY COUNT(*) DESC
+ LIMIT 1
+ "#,
+ )
+ .bind(min_count)
+ .fetch_optional(&self.pool)
+ .await?;
+
+ Ok(result)
+ }
+
pub async fn update_speaker_name(&self, speaker_id: i64, name: &str) -> Result<i64, SqlxError> {
let mut tx = self.begin_immediate_with_retry().await?;
sqlx::query("UPDATE speakers SET name = ?1 WHERE id = ?2")
@@ -4885,7 +4914,7 @@ LIMIT ? OFFSET ?
// their embeddings are similar to target. This prevents one similar
// embedding from stealing all transcriptions from an unrelated speaker.
if propagate_similar {
- let threshold = 0.8;
+ let threshold = 0.55;
let min_absorption_ratio = 0.5; // >50% of embeddings must match
// Read-only: for each other speaker, count matching vs total embeddings
diff --git a/crates/screenpipe-server/src/calendar_speaker_id.rs b/crates/screenpipe-server/src/calendar_speaker_id.rs
index 2e0a6cb66..925a4c3a3 100644
--- a/crates/screenpipe-server/src/calendar_speaker_id.rs
+++ b/crates/screenpipe-server/src/calendar_speaker_id.rs
@@ -304,11 +304,64 @@ pub fn start_speaker_identification(
db: Arc<screenpipe_db::DatabaseManager>,
user_name: Option<String>,
) -> tokio::task::JoinHandle<()> {
+ // Auto-name the dominant input speaker as the user (runs independently of meetings)
+ if let Some(name) = user_name.clone() {
+ if !name.trim().is_empty() {
+ let db2 = db.clone();
+ tokio::spawn(async move {
+ auto_name_input_speaker(db2, &name).await;
+ });
+ }
+ }
+
tokio::spawn(async move {
run_speaker_identification_loop(db, user_name).await;
})
}
+/// Periodically checks for the dominant unnamed speaker on the input device
+/// and auto-labels them as the user. This works outside of meetings — any time
+/// the user is talking into their mic, the system learns who they are.
+async fn auto_name_input_speaker(db: Arc<screenpipe_db::DatabaseManager>, user_name: &str) {
+ // Wait a bit for initial audio to accumulate
+ tokio::time::sleep(tokio::time::Duration::from_secs(60)).await;
+
+ let mut interval = tokio::time::interval(tokio::time::Duration::from_secs(120));
+ let min_transcriptions = 10; // need enough data to be confident
+
+ loop {
+ interval.tick().await;
+
+ match db.get_dominant_unnamed_input_speaker(min_transcriptions).await {
+ Ok(Some(speaker_id)) => {
+ match db.update_speaker_name(speaker_id, user_name).await {
+ Ok(_) => {
+ info!(
+ "auto speaker identification: named dominant input speaker {} as '{}'",
+ speaker_id, user_name
+ );
+ // Done — the dominant input speaker is now named.
+ // Keep running in case new unnamed speakers accumulate
+ // (e.g. after centroid drift creates a new cluster for the same person).
+ }
+ Err(e) => {
+ warn!(
+ "auto speaker identification: failed to name speaker {}: {}",
+ speaker_id, e
+ );
+ }
+ }
+ }
+ Ok(None) => {
+ debug!("auto speaker identification: no dominant unnamed input speaker yet");
+ }
+ Err(e) => {
+ debug!("auto speaker identification: DB query failed: {}", e);
+ }
+ }
+ }
+}
+
async fn run_speaker_identification_loop(
db: Arc<screenpipe_db::DatabaseManager>,
user_name: Option<String>,