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

fix diarization thing

Louis Beaumont13fe219c2856
diff --git a/.github/workflows/release-app.yml b/.github/workflows/release-app.yml
index e59158141..81250a1f7 100644
--- a/.github/workflows/release-app.yml
+++ b/.github/workflows/release-app.yml
@@ -177,7 +177,7 @@ jobs:
key: ${{ matrix.platform }}-${{ matrix.target }}-pre-build
- name: Install Linux dependencies
- if: matrix.platform == 'ubuntu-22.04' || matrix.platform == 'big-linux'
+ if: matrix.platform == 'ubuntu-22.04'
run: |
sudo apt update
sudo apt install -y \
@@ -194,7 +194,12 @@ jobs:
libbsd-dev \
libmd-dev \
libssl-dev \
- libglib2.0-dev
+ libglib2.0-dev \
+ # Add these new dependencies:
+ libgdk-pixbuf2.0-dev \
+ shared-mime-info \
+ desktop-file-utils \
+ libgtk-3-0
- name: Install dependencies
if: matrix.platform == 'macos-latest'
diff --git a/screenpipe-app-tauri/src-tauri/Cargo.toml b/screenpipe-app-tauri/src-tauri/Cargo.toml
index c8a8492c3..83ad159e1 100644
--- a/screenpipe-app-tauri/src-tauri/Cargo.toml
+++ b/screenpipe-app-tauri/src-tauri/Cargo.toml
@@ -1,6 +1,6 @@
[package]
name = "screenpipe-app"
-version = "0.11.5"
+version = "0.11.6"
description = ""
authors = ["you"]
license = ""
diff --git a/screenpipe-audio/src/pyannote/mod.rs b/screenpipe-audio/src/pyannote/mod.rs
index 46bf6f526..0092fb7ca 100644
--- a/screenpipe-audio/src/pyannote/mod.rs
+++ b/screenpipe-audio/src/pyannote/mod.rs
@@ -1,4 +1,5 @@
pub mod embedding;
pub mod identify;
+pub mod models;
pub mod segment;
pub mod session;
diff --git a/screenpipe-audio/src/pyannote/models.rs b/screenpipe-audio/src/pyannote/models.rs
new file mode 100644
index 000000000..42539845f
--- /dev/null
+++ b/screenpipe-audio/src/pyannote/models.rs
@@ -0,0 +1,127 @@
+use anyhow::Result;
+use dirs;
+use lazy_static::lazy_static;
+use log::{debug, info};
+use std::path::PathBuf;
+use std::sync::Once;
+use tokio::sync::Mutex;
+
+lazy_static! {
+ static ref SEGMENTATION_MODEL_PATH: Mutex<Option<PathBuf>> = Mutex::new(None);
+ static ref EMBEDDING_MODEL_PATH: Mutex<Option<PathBuf>> = Mutex::new(None);
+}
+
+static DOWNLOAD_SEGMENTATION_ONCE: Once = Once::new();
+static DOWNLOAD_EMBEDDING_ONCE: Once = Once::new();
+
+pub async fn get_or_download_model(model_type: PyannoteModel) -> Result<PathBuf> {
+ match model_type {
+ PyannoteModel::Segmentation => {
+ let mut model_path = SEGMENTATION_MODEL_PATH.lock().await;
+ if let Some(path) = model_path.as_ref() {
+ debug!("using cached segmentation model: {:?}", path);
+ return Ok(path.clone());
+ }
+
+ let cache_dir = get_cache_dir()?;
+ let path = cache_dir.join("segmentation-3.0.onnx");
+
+ if path.exists() {
+ debug!("found existing segmentation model at: {:?}", path);
+ *model_path = Some(path.clone());
+ return Ok(path);
+ }
+
+ info!("initiating segmentation model download...");
+ DOWNLOAD_SEGMENTATION_ONCE.call_once(|| {
+ tokio::spawn(async move {
+ if let Err(e) = download_model(PyannoteModel::Segmentation).await {
+ debug!("error downloading segmentation model: {}", e);
+ }
+ });
+ });
+
+ while !path.exists() {
+ tokio::time::sleep(tokio::time::Duration::from_millis(100)).await;
+ }
+
+ *model_path = Some(path.clone());
+ Ok(path)
+ }
+ PyannoteModel::Embedding => {
+ let mut model_path = EMBEDDING_MODEL_PATH.lock().await;
+ if let Some(path) = model_path.as_ref() {
+ debug!("using cached embedding model: {:?}", path);
+ return Ok(path.clone());
+ }
+
+ let cache_dir = get_cache_dir()?;
+ let path = cache_dir.join("wespeaker_en_voxceleb_CAM++.onnx");
+
+ if path.exists() {
+ debug!("found existing embedding model at: {:?}", path);
+ *model_path = Some(path.clone());
+ return Ok(path);
+ }
+
+ info!("initiating embedding model download...");
+ DOWNLOAD_EMBEDDING_ONCE.call_once(|| {
+ tokio::spawn(async move {
+ if let Err(e) = download_model(PyannoteModel::Embedding).await {
+ debug!("error downloading embedding model: {}", e);
+ }
+ });
+ });
+
+ while !path.exists() {
+ tokio::time::sleep(tokio::time::Duration::from_millis(100)).await;
+ }
+
+ *model_path = Some(path.clone());
+ Ok(path)
+ }
+ }
+}
+
+pub enum PyannoteModel {
+ Segmentation,
+ Embedding,
+}
+
+async fn download_model(model_type: PyannoteModel) -> Result<()> {
+ let (url, filename) = match model_type {
+ PyannoteModel::Segmentation => (
+ "https://github.com/mediar-ai/screenpipe/raw/refs/heads/main/screenpipe-audio/models/pyannote/segmentation-3.0.onnx",
+ "segmentation-3.0.onnx",
+ ),
+ PyannoteModel::Embedding => (
+ "https://github.com/mediar-ai/screenpipe/raw/refs/heads/main/screenpipe-audio/models/pyannote/wespeaker_en_voxceleb_CAM++.onnx",
+ "wespeaker_en_voxceleb_CAM++.onnx",
+ ),
+ };
+
+ info!("downloading {} model from {}", filename, url);
+ let response = reqwest::get(url).await?;
+ let model_data = response.bytes().await?;
+
+ let cache_dir = get_cache_dir()?;
+ tokio::fs::create_dir_all(&cache_dir).await?;
+ let path = cache_dir.join(filename);
+
+ info!(
+ "saving {} model ({} bytes) to {:?}",
+ filename,
+ model_data.len(),
+ path
+ );
+ let mut file = tokio::fs::File::create(&path).await?;
+ tokio::io::AsyncWriteExt::write_all(&mut file, &model_data).await?;
+ info!("{} model successfully downloaded and saved", filename);
+
+ Ok(())
+}
+
+fn get_cache_dir() -> Result<PathBuf> {
+ let proj_dirs = dirs::cache_dir().ok_or_else(|| anyhow::anyhow!("failed to get cache dir"))?;
+ Ok(proj_dirs.join("screenpipe").join("models"))
+}
diff --git a/screenpipe-audio/src/stt.rs b/screenpipe-audio/src/stt.rs
index 0661c8813..fc63e9094 100644
--- a/screenpipe-audio/src/stt.rs
+++ b/screenpipe-audio/src/stt.rs
@@ -36,6 +36,8 @@ use screenpipe_core::Language;
use serde_json::Value;
use std::io::Cursor;
+use crate::pyannote::models::{get_or_download_model, PyannoteModel};
+
async fn transcribe_with_deepgram(
api_key: &str,
audio_data: &[f32],
@@ -533,17 +535,8 @@ pub async fn create_whisper_channel(
let shutdown_flag_clone = shutdown_flag.clone();
let output_path = output_path.clone();
- let project_dir = PathBuf::from(env!("CARGO_MANIFEST_DIR"));
-
- let embedding_model_path = project_dir
- .join("models")
- .join("pyannote")
- .join("wespeaker_en_voxceleb_CAM++.onnx");
-
- let segmentation_model_path = project_dir
- .join("models")
- .join("pyannote")
- .join("segmentation-3.0.onnx");
+ let embedding_model_path = get_or_download_model(PyannoteModel::Embedding).await?;
+ let segmentation_model_path = get_or_download_model(PyannoteModel::Segmentation).await?;
let embedding_extractor = Arc::new(StdMutex::new(EmbeddingExtractor::new(
embedding_model_path