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

add simple audio bench for local only

Louis Beaumont95f198ccd355
diff --git a/screenpipe-audio/Cargo.toml b/screenpipe-audio/Cargo.toml
index c14a141dc..3d5f5fb50 100644
--- a/screenpipe-audio/Cargo.toml
+++ b/screenpipe-audio/Cargo.toml
@@ -86,5 +86,7 @@ path = "src/bin/screenpipe-audio.rs"
name = "pcm_decode_benchmark"
harness = false
-
+[[bench]]
+name = "record_and_transcribe_benchmark"
+harness = false
diff --git a/screenpipe-audio/benches/record_and_transcribe_benchmark.rs b/screenpipe-audio/benches/record_and_transcribe_benchmark.rs
new file mode 100644
index 000000000..6da4507e1
--- /dev/null
+++ b/screenpipe-audio/benches/record_and_transcribe_benchmark.rs
@@ -0,0 +1,72 @@
+use criterion::{black_box, criterion_group, criterion_main, BenchmarkId, Criterion};
+use screenpipe_audio::{
+ create_whisper_channel, default_input_device, record_and_transcribe, AudioDevice, AudioInput,
+ AudioTranscriptionEngine,
+};
+use std::path::PathBuf;
+use std::sync::atomic::AtomicBool;
+use std::sync::Arc;
+use std::time::Duration;
+use tokio::sync::mpsc;
+
+async fn setup_test() -> (
+ Arc<AudioDevice>,
+ PathBuf,
+ mpsc::UnboundedSender<AudioInput>,
+ Arc<AtomicBool>,
+) {
+ let audio_device = default_input_device().unwrap(); // TODO feed voice in automatically somehow
+ let output_path = PathBuf::from("/tmp/test_audio.mp4");
+ // let (whisper_sender, _) = mpsc::unbounded_channel();
+ let (whisper_sender, _) =
+ create_whisper_channel(Arc::new(AudioTranscriptionEngine::WhisperDistilLargeV3))
+ .await
+ .unwrap();
+ let is_running = Arc::new(AtomicBool::new(true));
+
+ (
+ Arc::new(audio_device),
+ output_path,
+ whisper_sender,
+ is_running,
+ )
+}
+
+fn bench_record_and_transcribe(c: &mut Criterion) {
+ let rt = tokio::runtime::Runtime::new().unwrap();
+
+ let mut group = c.benchmark_group("Record and Transcribe");
+ group.sample_size(10);
+ group.measurement_time(Duration::from_secs(90)); // Increased from 30 to 60 seconds
+
+ group.bench_function(BenchmarkId::new("Performance", ""), |b| {
+ b.to_async(&rt).iter_custom(|iters| async move {
+ let mut total_duration = Duration::new(0, 0);
+
+ for _ in 0..iters {
+ let (audio_device, output_path, whisper_sender, is_running) = setup_test().await;
+ let duration = Duration::from_secs(5); // 5 seconds of recording
+
+ let start = std::time::Instant::now();
+ let result = record_and_transcribe(
+ black_box(audio_device),
+ black_box(duration),
+ black_box(output_path),
+ black_box(whisper_sender),
+ black_box(is_running),
+ )
+ .await;
+ total_duration += start.elapsed();
+
+ assert!(result.is_ok(), "Recording and transcription failed");
+ }
+
+ total_duration
+ })
+ });
+
+ group.finish();
+}
+
+criterion_group!(benches, bench_record_and_transcribe);
+criterion_main!(benches);