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: virtual devices not shown on mac + VAD too aggressive

Louis Beaumont1c335a21ebee
diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml
index ad39a59f2..d6efdd20f 100644
--- a/.github/workflows/benchmark.yml
+++ b/.github/workflows/benchmark.yml
@@ -60,7 +60,9 @@ jobs:
- name: Run Windows OCR benchmarks
run: |
- cargo bench --bench ocr_benchmark -- --output-format criterion | Tee-Object -Append -FilePath ocr_output.txt
+ cargo bench --bench ocr_benchmark -- --output-format criterion
+ # TODO broken
+ # | Tee-Object -Append -FilePath ocr_output.txt
- name: Upload OCR benchmark artifact
uses: actions/upload-artifact@v3
@@ -68,8 +70,36 @@ jobs:
name: ocr-benchmark-data
path: ocr_output.txt
+ stt_benchmark:
+ name: Run STT benchmark
+ runs-on: ubuntu-latest
+ steps:
+ - uses: actions/checkout@v3
+ - uses: dtolnay/rust-toolchain@stable
+
+ - name: Install dependencies
+ run: |
+ sudo apt-get update
+ sudo apt-get install -y ffmpeg
+
+ - name: Run STT benchmarks
+ run: |
+ cargo bench --bench stt_benchmark -- --output-format bencher | tee -a stt_output.txt
+
+ - name: Upload STT benchmark artifact
+ uses: actions/upload-artifact@v3
+ with:
+ name: stt-benchmark-data
+ path: stt_output.txt
+
analyze_benchmarks:
- needs: [apple_ocr_benchmark, tesseract_ocr_benchmark, windows_ocr_benchmark]
+ needs:
+ [
+ apple_ocr_benchmark,
+ tesseract_ocr_benchmark,
+ windows_ocr_benchmark,
+ stt_benchmark,
+ ]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
@@ -78,17 +108,36 @@ jobs:
uses: actions/download-artifact@v3
with:
name: ocr-benchmark-data
- path: ./cache
+ path: ./cache/ocr
+
+ - name: Download STT benchmark data
+ uses: actions/download-artifact@v3
+ with:
+ name: stt-benchmark-data
+ path: ./cache/stt
- name: List contents of cache directory
run: ls -R ./cache
- - name: Analyze all OCR benchmarks
+ - name: Analyze OCR benchmarks
uses: benchmark-action/github-action-benchmark@v1
with:
name: OCR Benchmarks
tool: "cargo"
- output-file-path: ./cache/ocr_output.txt
+ output-file-path: ./cache/ocr/ocr_output.txt
+ github-token: ${{ secrets.GH_PAGES_TOKEN }}
+ auto-push: true
+ alert-threshold: "200%"
+ comment-on-alert: true
+ fail-on-alert: true
+ alert-comment-cc-users: "@louis030195"
+
+ - name: Analyze STT benchmarks
+ uses: benchmark-action/github-action-benchmark@v1
+ with:
+ name: STT Benchmarks
+ tool: "criterion"
+ output-file-path: ./cache/stt/stt_output.txt
github-token: ${{ secrets.GH_PAGES_TOKEN }}
auto-push: true
alert-threshold: "200%"
diff --git a/screenpipe-audio/Cargo.toml b/screenpipe-audio/Cargo.toml
index e7d79de0d..6e8fc29ee 100644
--- a/screenpipe-audio/Cargo.toml
+++ b/screenpipe-audio/Cargo.toml
@@ -68,6 +68,7 @@ once_cell = "1.17.1"
tempfile = "3.3.0"
infer = "0.15"
criterion = { workspace = true }
+memory-stats = "1.0"
[features]
metal = ["candle/metal", "candle-nn/metal", "candle-transformers/metal"]
@@ -86,3 +87,6 @@ harness = false
name = "record_and_transcribe_benchmark"
harness = false
+[[bench]]
+name = "stt_benchmark"
+harness = false
diff --git a/screenpipe-audio/benches/stt_benchmark.rs b/screenpipe-audio/benches/stt_benchmark.rs
new file mode 100644
index 000000000..a5cc18c74
--- /dev/null
+++ b/screenpipe-audio/benches/stt_benchmark.rs
@@ -0,0 +1,59 @@
+use criterion::{black_box, criterion_group, criterion_main, Criterion};
+use memory_stats::memory_stats;
+use screenpipe_audio::{create_whisper_channel, stt, AudioTranscriptionEngine, WhisperModel};
+use std::path::PathBuf;
+use std::sync::Arc;
+use std::time::Duration;
+
+fn criterion_benchmark(c: &mut Criterion) {
+ let audio_transcription_engine = Arc::new(AudioTranscriptionEngine::WhisperTiny);
+ let whisper_model = WhisperModel::new(audio_transcription_engine.clone()).unwrap();
+ let test_file_path = PathBuf::from(env!("CARGO_MANIFEST_DIR"))
+ .join("test_data")
+ .join("selah.mp4");
+
+ let mut group = c.benchmark_group("whisper_benchmarks");
+ group.sample_size(10);
+ group.measurement_time(Duration::from_secs(60));
+
+ group.bench_function("create_whisper_channel", |b| {
+ b.iter(|| {
+ let _ = create_whisper_channel(black_box(audio_transcription_engine.clone()));
+ })
+ });
+
+ group.bench_function("stt", |b| {
+ b.iter(|| {
+ let _ = stt(
+ black_box(test_file_path.to_string_lossy().as_ref()),
+ black_box(&whisper_model),
+ black_box(audio_transcription_engine.clone()),
+ );
+ })
+ });
+
+ group.bench_function("memory_usage_stt", |b| {
+ b.iter_custom(|iters| {
+ let mut total_duration = Duration::new(0, 0);
+ for _ in 0..iters {
+ let start = std::time::Instant::now();
+ let before = memory_stats().unwrap().physical_mem;
+ let _ = stt(
+ test_file_path.to_string_lossy().as_ref(),
+ &whisper_model,
+ audio_transcription_engine.clone(),
+ );
+ let after = memory_stats().unwrap().physical_mem;
+ let duration = start.elapsed();
+ total_duration += duration;
+ println!("Memory used: {} bytes", after - before);
+ }
+ total_duration
+ })
+ });
+
+ group.finish();
+}
+
+criterion_group!(benches, criterion_benchmark);
+criterion_main!(benches);
diff --git a/screenpipe-audio/src/bin/screenpipe-audio.rs b/screenpipe-audio/src/bin/screenpipe-audio.rs
index 09e087ca7..0785a34a3 100644
--- a/screenpipe-audio/src/bin/screenpipe-audio.rs
+++ b/screenpipe-audio/src/bin/screenpipe-audio.rs
@@ -38,7 +38,7 @@ fn print_devices(devices: &[AudioDevice]) {
println!("On macOS, it's not intuitive but output devices are your displays");
}
-// TODO - kinda bad cli here
+// ! usage - cargo run --bin screenpipe-audio -- --audio-device "Display 1 (output)"
#[tokio::main]
async fn main() -> Result<()> {
@@ -46,7 +46,7 @@ async fn main() -> Result<()> {
use log::LevelFilter;
Builder::new()
- .filter(None, LevelFilter::Info)
+ .filter(None, LevelFilter::Debug)
.filter_module("tokenizers", LevelFilter::Error)
.init();
@@ -76,10 +76,10 @@ async fn main() -> Result<()> {
std::fs::remove_file("output_0.mp4").unwrap_or_default();
std::fs::remove_file("output_1.mp4").unwrap_or_default();
- let chunk_duration = Duration::from_secs(5);
+ let chunk_duration = Duration::from_secs(10);
let output_path = PathBuf::from("output.mp4");
let (whisper_sender, mut whisper_receiver) =
- create_whisper_channel(Arc::new(AudioTranscriptionEngine::WhisperTiny)).await?;
+ create_whisper_channel(Arc::new(AudioTranscriptionEngine::WhisperDistilLargeV3)).await?;
// Spawn threads for each device
let recording_threads: Vec<_> = devices
.into_iter()
diff --git a/screenpipe-audio/src/core.rs b/screenpipe-audio/src/core.rs
index fcae16c36..1d5472414 100644
--- a/screenpipe-audio/src/core.rs
+++ b/screenpipe-audio/src/core.rs
@@ -121,17 +121,14 @@ pub fn parse_audio_device(name: &str) -> Result<AudioDevice> {
async fn get_device_and_config(
audio_device: &AudioDevice,
) -> Result<(cpal::Device, cpal::SupportedStreamConfig)> {
- let host = match audio_device.device_type {
- #[cfg(target_os = "macos")]
- DeviceType::Output => cpal::host_from_id(cpal::HostId::ScreenCaptureKit)?,
- _ => cpal::default_host(),
- };
+ let host = cpal::default_host();
info!("device: {:?}", audio_device.to_string());
let is_output_device = audio_device.device_type == DeviceType::Output;
+ let is_display = audio_device.to_string().contains("Display");
- let audio_device = if audio_device.to_string() == "default" {
+ let cpal_audio_device = if audio_device.to_string() == "default" {
match audio_device.device_type {
DeviceType::Input => host.default_input_device(),
DeviceType::Output => host.default_output_device(),
@@ -144,7 +141,9 @@ async fn get_device_and_config(
#[cfg(target_os = "macos")]
{
- if audio_device.device_type == DeviceType::Output {
+ // if the user intentionally selected the display capture device, use the screen capture kit host
+ // otherwise we will use the core audio output device (likely a virtual device that connect system audio)
+ if audio_device.device_type == DeviceType::Output && is_display {
let version = *MACOS_VERSION;
if version < 15.0 {
if let Ok(screen_capture_host) =
@@ -171,12 +170,12 @@ async fn get_device_and_config(
.ok_or_else(|| anyhow!("Audio device not found"))?;
// if output device and windows, using output config
- let config = if is_output_device && cfg!(target_os = "windows") {
- audio_device.default_output_config()?
+ let config = if is_output_device && !is_display {
+ cpal_audio_device.default_output_config()?
} else {
- audio_device.default_input_config()?
+ cpal_audio_device.default_input_config()?
};
- Ok((audio_device, config))
+ Ok((cpal_audio_device, config))
}
async fn run_ffmpeg(
@@ -404,6 +403,7 @@ pub async fn list_audio_devices() -> Result<Vec<AudioDevice>> {
}
}
+ // macos hack using screen capture kit for output devices - does not work well
#[cfg(target_os = "macos")]
{
// !HACK macos is suppoed to use special macos feature "display capture"
@@ -420,12 +420,10 @@ pub async fn list_audio_devices() -> Result<Vec<AudioDevice>> {
}
}
- #[cfg(not(target_os = "macos"))]
- {
- for device in host.output_devices()? {
- if let Ok(name) = device.name() {
- devices.push(AudioDevice::new(name, DeviceType::Output));
- }
+ // add default output device - on macos think of custom virtual devices
+ for device in host.output_devices()? {
+ if let Ok(name) = device.name() {
+ devices.push(AudioDevice::new(name, DeviceType::Output));
}
}
diff --git a/screenpipe-audio/src/lib.rs b/screenpipe-audio/src/lib.rs
index caf147d08..e2f090871 100644
--- a/screenpipe-audio/src/lib.rs
+++ b/screenpipe-audio/src/lib.rs
@@ -4,7 +4,7 @@ pub mod pcm_decode;
pub mod stt;
pub use core::{
default_input_device, default_output_device, list_audio_devices, parse_audio_device,
- record_and_transcribe, AudioDevice, AudioTranscriptionEngine, DeviceControl,
+ record_and_transcribe, AudioDevice, AudioTranscriptionEngine, DeviceControl, DeviceType
};
pub use pcm_decode::pcm_decode;
pub use stt::{create_whisper_channel, stt, AudioInput, TranscriptionResult, WhisperModel};
diff --git a/screenpipe-audio/src/stt.rs b/screenpipe-audio/src/stt.rs
index 6bc928f6b..547055061 100644
--- a/screenpipe-audio/src/stt.rs
+++ b/screenpipe-audio/src/stt.rs
@@ -536,7 +536,7 @@ pub fn stt(
// Initialize VAD
debug!("VAD: Initializing VAD");
let mut vad = Vad::new();
- vad.set_mode(VadMode::VeryAggressive); // Set mode to very aggressive
+ vad.set_mode(VadMode::Quality); // Set mode to very aggressive
// Filter out non-speech segments
debug!("VAD: Filtering out non-speech segments");