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
chore: add benchmark for measuring transcription accuracy
Louis Beaumontf22a85fd9ff0
diff --git a/screenpipe-audio/Cargo.toml b/screenpipe-audio/Cargo.tomlindex 80f9ad1bd..97cbc6435 100644--- a/screenpipe-audio/Cargo.toml+++ b/screenpipe-audio/Cargo.toml@@ -71,6 +71,7 @@ dirs = "5.0.1"lazy_static = { version = "1.4.0" }+pyannote-rs = "0.2.7"[target.'cfg(target_os = "windows")'.dependencies]ort = { version = "2.0.0-rc.5", features = ["download-binaries", "copy-dylibs", "directml", "cuda"] }@@ -87,6 +88,8 @@ tempfile = "3.3.0"infer = "0.15"criterion = { workspace = true }memory-stats = "1.0"+strsim = "0.10.0"+futures = "0.3.31"[features]metal = ["candle/metal", "candle-nn/metal", "candle-transformers/metal"]diff --git a/screenpipe-audio/test_data/accuracy1.wav b/screenpipe-audio/test_data/accuracy1.wavnew file mode 100644index 000000000..a34717cf2Binary files /dev/null and b/screenpipe-audio/test_data/accuracy1.wav differdiff --git a/screenpipe-audio/test_data/accuracy2.wav b/screenpipe-audio/test_data/accuracy2.wavnew file mode 100644index 000000000..38e63e28fBinary files /dev/null and b/screenpipe-audio/test_data/accuracy2.wav differdiff --git a/screenpipe-audio/test_data/accuracy3.wav b/screenpipe-audio/test_data/accuracy3.wavnew file mode 100644index 000000000..8c9a8cdabBinary files /dev/null and b/screenpipe-audio/test_data/accuracy3.wav differdiff --git a/screenpipe-audio/test_data/accuracy4.mp4 b/screenpipe-audio/test_data/accuracy4.mp4new file mode 100644index 000000000..e7f45b2c8Binary files /dev/null and b/screenpipe-audio/test_data/accuracy4.mp4 differdiff --git a/screenpipe-audio/test_data/accuracy4.wav b/screenpipe-audio/test_data/accuracy4.wavnew file mode 100644index 000000000..7b3aaa77eBinary files /dev/null and b/screenpipe-audio/test_data/accuracy4.wav differdiff --git a/screenpipe-audio/tests/accuracy_test.rs b/screenpipe-audio/tests/accuracy_test.rsnew file mode 100644index 000000000..6502034da--- /dev/null+++ b/screenpipe-audio/tests/accuracy_test.rs@@ -0,0 +1,120 @@+use futures::future::join_all;+use screenpipe_audio::stt::stt;+use screenpipe_audio::vad_engine::{SileroVad, VadEngine};+use screenpipe_audio::whisper::WhisperModel;+use screenpipe_audio::{AudioInput, AudioTranscriptionEngine};+use std::path::PathBuf;+use std::sync::Arc;+use strsim::levenshtein;+use tokio::sync::Mutex;++#[tokio::test]+async fn test_transcription_accuracy() {+ // Setup+ let test_cases = vec![+ (+ "test_data/accuracy1.wav",+ r#"yo louis, here's the tldr of that mind-blowing meeting:+ - bob's cat walked across his keyboard 3 times. productivity increased by 200%.+ - sarah's virtual background glitched, revealing she was actually on a beach. no one noticed.+ - you successfully pretended to be engaged while scrolling twitter. achievement unlocked!+ - 7 people said "you're on mute" in perfect synchronization. new world record.+ - meeting could've been an email. shocking.+ key takeaway: we're all living in a simulation, and the devs are laughing.+ peace out, llama3.2:3b-instruct-q4_K_M"#,+ ),+ (+ "test_data/accuracy2.wav",+ r#"bro - got some good stuff from screenpipe here's the lowdown on your day, you productivity ninja:+ - absolutely demolished that 2-hour coding sesh on the new feature. the keyboard is still smoking, bro!+ - crushed 3 client calls like a boss. they're probably writing love letters to you as we speak, make sure to close john tomorrow 8.00 am according to our notes, let the cash flow in!+ - spent 45 mins on slack. 90% memes, 10% actual work. perfectly balanced, as all things should be+ - watched a rust tutorial. way to flex those brain muscles, you nerd!+ overall, you're killing it! 80% of your time on high-value tasks. the other 20%? probably spent admiring your own reflection, you handsome devil.+ PS: seriously, quit tiktok. your FBI agent is getting bored watching you scroll endlessly.+ what's the plan for tomorrow? more coding? more memes? world domination?+ generated by your screenpipe ai assistant (who's definitely not planning to take over the world... yet)"#,+ ),+ (+ "test_data/accuracy3.wav",+ r#"again, screenpipe allows you to get meeting summaries, locally, without leaking data to OpenAI, with any apps, like WhatsApp, Meet, Zoom, etc. and it's open source at github.com/mediar-ai/screenpipe"#,+ ),+ (+ "test_data/accuracy4.wav",+ r#"Eventually but, I mean, I feel like but, I mean, first, I mean, you think your your vision smart will be interesting because, yeah, you install once. You pay us, you install once. That that yours. So, basically, all the time Microsoft explained, you know, MS Office, long time ago, you just buy the the the software that you can using there forever unless you wanna you wanna update upgrade is the better version. Right?++So it's a little bit, you know"#,+ ),+ // Add more test cases as needed+ ];++ let whisper_model =+ Arc::new(WhisperModel::new(&AudioTranscriptionEngine::WhisperLargeV3Turbo).unwrap());+ let vad_engine: Arc<Mutex<Box<dyn VadEngine + Send>>> =+ Arc::new(Mutex::new(Box::new(SileroVad::new().await.unwrap())));+ let output_path = Arc::new(PathBuf::from("test_output"));++ let mut tasks = Vec::new();++ for (audio_file, expected_transcription) in test_cases {+ let whisper_model = Arc::clone(&whisper_model);+ let vad_engine = Arc::clone(&vad_engine);+ let output_path = Arc::clone(&output_path);++ let task = tokio::spawn(async move {+ let audio_path = PathBuf::from(env!("CARGO_MANIFEST_DIR")).join(audio_file);+ let audio_data =+ screenpipe_audio::pcm_decode(&audio_path).expect("Failed to decode audio file");++ let audio_input = AudioInput {+ data: Arc::new(audio_data.0),+ sample_rate: 44100,+ channels: 1,+ device: Arc::new(screenpipe_audio::default_output_device().await.unwrap()),+ };++ let mut vad_engine_guard = vad_engine.lock().await;+ let (transcription, _) = stt(+ &audio_input,+ &whisper_model,+ Arc::new(AudioTranscriptionEngine::WhisperTiny),+ &mut **vad_engine_guard,+ None,+ &output_path,+ )+ .await+ .unwrap();+ drop(vad_engine_guard);++ let distance = levenshtein(expected_transcription, &transcription);+ let accuracy = 1.0 - (distance as f64 / expected_transcription.len() as f64);++ (audio_file, expected_transcription, transcription, accuracy)+ });++ tasks.push(task);+ }++ let results = join_all(tasks).await;++ let mut total_accuracy = 0.0;+ let mut total_tests = 0;++ for result in results {+ let (audio_file, expected_transcription, transcription, accuracy) = result.unwrap();++ println!("file: {}", audio_file);+ println!("expected: {}", expected_transcription);+ println!("actual: {}", transcription);+ println!("accuracy: {:.2}%", accuracy * 100.0);+ println!();++ total_accuracy += accuracy;+ total_tests += 1;+ }++ let average_accuracy = total_accuracy / total_tests as f64;+ println!("average accuracy: {:.2}%", average_accuracy * 100.0);++ assert!(average_accuracy > 0.55, "average accuracy is below 55%");+}