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

Revert "Merge pull request #273 from m13v/onnx_implementation-wip"

Louis Beaumontc0bd548e9afe
diff --git a/README.md b/README.md
index fae56bf1d..f31ec5321 100644
--- a/README.md
+++ b/README.md
@@ -120,13 +120,9 @@ if you want to run screenpipe in debug mode to show more logs in terminal:
```bash
screenpipe --debug
```
-by default screenpipe is using Silero-VAD to identify speech and non-speech tokens to improve audio transcription, bu you can use WebRTC if needed by passing the following command:
+by default screenpipe is using whisper-tiny that runs LOCALLY to get better quality or lower compute you can use cloud model (we use Deepgram) via cloud api:
```bash
-screenpipe --vad-engine webrtc
-```
-by default screenpipe is using whisper-large that runs LOCALLY to get better quality or lower compute you can use cloud model (we use Deepgram) via cloud api:
-```bash
-screenpipe --audio-transcription-engine deepgram
+screenpipe -audio-transcription-engine deepgram
```
by default screenpipe is using a local model for screen capture OCR processing to use the cloud (through unstructured.io) for better performance use this flag:
```bash
diff --git a/screenpipe-audio/Cargo.toml b/screenpipe-audio/Cargo.toml
index 0d2f92f0f..cfb974c53 100644
--- a/screenpipe-audio/Cargo.toml
+++ b/screenpipe-audio/Cargo.toml
@@ -34,8 +34,6 @@ chrono = { version = "0.4.31", features = ["serde"] }
candle = { workspace = true }
candle-nn = { workspace = true }
candle-transformers = { workspace = true }
-ndarray = "0.15.6"
-vad-rs = "0.1.3"
tokenizers = { workspace = true }
anyhow = "1.0.86"
byteorder = "1.5.0"
diff --git a/screenpipe-audio/src/bin/screenpipe-audio.rs b/screenpipe-audio/src/bin/screenpipe-audio.rs
index bf219d7db..c034bcd9c 100644
--- a/screenpipe-audio/src/bin/screenpipe-audio.rs
+++ b/screenpipe-audio/src/bin/screenpipe-audio.rs
@@ -9,7 +9,6 @@ use screenpipe_audio::parse_audio_device;
use screenpipe_audio::record_and_transcribe;
use screenpipe_audio::AudioDevice;
use screenpipe_audio::AudioTranscriptionEngine;
-use screenpipe_audio::VadEngineEnum;
use std::path::PathBuf;
use std::sync::atomic::AtomicBool;
use std::sync::Arc;
@@ -80,10 +79,7 @@ async fn main() -> Result<()> {
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::WhisperDistilLargeV3),
- VadEngineEnum::Silero, // Or VadEngineEnum::WebRtc, hardcoded for now
- ).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/lib.rs b/screenpipe-audio/src/lib.rs
index fbcf8efd9..e2f090871 100644
--- a/screenpipe-audio/src/lib.rs
+++ b/screenpipe-audio/src/lib.rs
@@ -2,11 +2,9 @@ mod core;
mod multilingual;
pub mod pcm_decode;
pub mod stt;
-pub mod vad_engine;
pub use core::{
default_input_device, default_output_device, list_audio_devices, parse_audio_device,
record_and_transcribe, AudioDevice, AudioTranscriptionEngine, DeviceControl, DeviceType
};
pub use pcm_decode::pcm_decode;
pub use stt::{create_whisper_channel, stt, AudioInput, TranscriptionResult, WhisperModel};
-pub use vad_engine::VadEngineEnum;
diff --git a/screenpipe-audio/src/stt.rs b/screenpipe-audio/src/stt.rs
index 4fb074f67..00eedf3b8 100644
--- a/screenpipe-audio/src/stt.rs
+++ b/screenpipe-audio/src/stt.rs
@@ -19,12 +19,9 @@ use rubato::{
Resampler, SincFixedIn, SincInterpolationParameters, SincInterpolationType, WindowFunction,
};
-use crate::{
- multilingual,
- pcm_decode::pcm_decode,
- vad_engine::{SileroVad, VadEngine, VadEngineEnum, WebRtcVad},
- AudioTranscriptionEngine,
-};
+use crate::{multilingual, pcm_decode::pcm_decode, AudioTranscriptionEngine};
+
+use webrtc_vad::{Vad, VadMode};
use hound::{WavSpec, WavWriter};
use std::io::Cursor;
@@ -512,7 +509,6 @@ pub fn stt(
file_path: &str,
whisper_model: &WhisperModel,
audio_transcription_engine: Arc<AudioTranscriptionEngine>,
- vad_engine: &mut dyn VadEngine,
) -> Result<String> {
debug!("Starting speech to text for file: {}", file_path);
let model = &whisper_model.model;
@@ -539,15 +535,25 @@ pub fn stt(
pcm_data = resample(pcm_data, sample_rate, m::SAMPLE_RATE as u32)?;
}
- // Filter out non-speech segments using Silero VAD
- debug!("Filtering out non-speech segments with VAD");
+ // Initialize VAD
+ debug!("VAD: Initializing VAD");
+ let mut vad = Vad::new();
+ vad.set_mode(VadMode::VeryAggressive); // Set mode to very aggressive
+
+ // Filter out non-speech segments
+ debug!("VAD: Filtering out non-speech segments");
let frame_size = 160; // 10ms frame size for 16kHz audio
let mut speech_frames = Vec::new();
for (frame_index, chunk) in pcm_data.chunks(frame_size).enumerate() {
- match vad_engine.is_voice_segment(chunk) {
+ // Convert f32 to i16
+ let i16_chunk: Vec<i16> = chunk.iter().map(|&x| (x * 32767.0) as i16).collect();
+ match vad.is_voice_segment(&i16_chunk) {
Ok(is_voice) => {
if is_voice {
+ // debug!("VAD: Speech detected in frame {}", frame_index);
speech_frames.extend_from_slice(chunk);
+ } else {
+ // debug!("VAD: Non-speech frame {} filtered out", frame_index);
}
}
Err(e) => {
@@ -717,7 +723,6 @@ use std::sync::atomic::{AtomicBool, Ordering};
pub async fn create_whisper_channel(
audio_transcription_engine: Arc<AudioTranscriptionEngine>,
- vad_engine: VadEngineEnum,
) -> Result<(
UnboundedSender<AudioInput>,
UnboundedReceiver<TranscriptionResult>,
@@ -732,10 +737,6 @@ pub async fn create_whisper_channel(
UnboundedSender<TranscriptionResult>,
UnboundedReceiver<TranscriptionResult>,
) = unbounded_channel();
- let mut vad_engine: Box<dyn VadEngine + Send> = match vad_engine {
- VadEngineEnum::WebRtc => Box::new(WebRtcVad::new()),
- VadEngineEnum::Silero => Box::new(SileroVad::new()?),
- };
let shutdown_flag = Arc::new(AtomicBool::new(false));
let shutdown_flag_clone = shutdown_flag.clone();
@@ -758,7 +759,7 @@ pub async fn create_whisper_channel(
#[cfg(target_os = "macos")]
{
autoreleasepool(|| {
- match stt(&input.path, &whisper_model, audio_transcription_engine.clone(), &mut *vad_engine) {
+ match stt(&input.path, &whisper_model, audio_transcription_engine.clone()) {
Ok(transcription) => TranscriptionResult {
input: input.clone(),
transcription: Some(transcription),
@@ -779,10 +780,11 @@ pub async fn create_whisper_channel(
}
#[cfg(not(target_os = "macos"))]
{
+ // This will be used for non-macOS platforms when compiling for macOS
unreachable!("This code should not be reached on non-macOS platforms")
}
} else {
- match stt(&input.path, &whisper_model, audio_transcription_engine.clone(), &mut *vad_engine) {
+ match stt(&input.path, &whisper_model, audio_transcription_engine.clone()) {
Ok(transcription) => TranscriptionResult {
input: input.clone(),
transcription: Some(transcription),
diff --git a/screenpipe-audio/src/vad_engine.rs b/screenpipe-audio/src/vad_engine.rs
deleted file mode 100644
index 4f5dd4816..000000000
--- a/screenpipe-audio/src/vad_engine.rs
+++ /dev/null
@@ -1,108 +0,0 @@
-use std::path::PathBuf;
-use vad_rs::{Vad};
-use anyhow;
-use std::io::Write;
-use log::debug;
-
-pub enum VadEngineEnum {
- WebRtc,
- Silero,
-}
-
-pub trait VadEngine {
- fn is_voice_segment(&mut self, audio_chunk: &[f32]) -> anyhow::Result<bool>;
-}
-
-pub struct WebRtcVad(webrtc_vad::Vad);
-
-impl WebRtcVad {
- pub fn new() -> Self {
- let mut vad = webrtc_vad::Vad::new();
- vad.set_mode(webrtc_vad::VadMode::VeryAggressive);
- Self(vad)
- }
-}
-
-impl VadEngine for WebRtcVad {
- fn is_voice_segment(&mut self, audio_chunk: &[f32]) -> anyhow::Result<bool> {
- // Convert f32 to i16
- let i16_chunk: Vec<i16> = audio_chunk
- .iter()
- .map(|&x| (x * 32767.0) as i16)
- .collect();
-
- let result = self.0.is_voice_segment(&i16_chunk)
- .map_err(|e| anyhow::anyhow!("WebRTC VAD error: {:?}", e))?;
-
- // debug!("WebRTC VAD result: is_voice_segment = {}", result);
-
- Ok(result)
- }
-}
-
-pub struct SileroVad {
- vad: Vad,
-}
-
-impl SileroVad {
- pub fn new() -> anyhow::Result<Self> {
- debug!("Initializing SileroVad...");
- let model_path = Self::download_model()?;
- debug!("SileroVad Model downloaded to: {:?}", model_path);
- let vad = Vad::new(model_path, 16000).map_err(|e| {
- debug!("SileroVad Error creating Vad: {}", e);
- anyhow::anyhow!("Vad creation error: {}", e)
- })?;
- debug!("SileroVad initialized successfully");
- Ok(Self { vad })
- }
-
- fn download_model() -> anyhow::Result<PathBuf> {
- debug!("Downloading SileroVAD model...");
- let url = "https://github.com/k2-fsa/sherpa-onnx/releases/download/asr-models/silero_vad.onnx";
- let response = reqwest::blocking::get(url)?;
- let model_data = response.bytes()?;
-
- let path = std::env::temp_dir().join("silero_vad.onnx");
- let mut file = std::fs::File::create(&path)?;
- file.write_all(&model_data)?;
- debug!("SileroVad Model downloaded and saved to: {:?}", path);
-
- Ok(path)
- }
-}
-
-impl VadEngine for SileroVad {
- fn is_voice_segment(&mut self, audio_chunk: &[f32]) -> anyhow::Result<bool> {
- const CHUNK_SIZE: usize = 1600; // 100 milliseconds
-
- for chunk in audio_chunk.chunks(CHUNK_SIZE) {
- let mut chunk_data: Vec<f32> = chunk.to_vec();
- chunk_data.resize(CHUNK_SIZE, 0.0);
-
- let result = self.vad.compute(&chunk_data).map_err(|e| {
- debug!("SileroVad Error computing VAD: {}", e);
- anyhow::anyhow!("Vad compute error: {}", e)
- })?;
-
- if result.prob < 0.5 {
- return Ok(true);
- }
- }
-
- Ok(false)
- }
-}
-
-pub fn create_vad_engine(engine: VadEngineEnum) -> anyhow::Result<Box<dyn VadEngine>> {
- match engine {
- VadEngineEnum::WebRtc => Ok(Box::new(WebRtcVad::new())),
- VadEngineEnum::Silero => {
- let silero_vad = SileroVad::new()?;
- Ok(Box::new(silero_vad))
- },
- }
-}
-
-unsafe impl Send for WebRtcVad {}
-unsafe impl Send for SileroVad {}
diff --git a/screenpipe-audio/tests/core_tests.rs b/screenpipe-audio/tests/core_tests.rs
index 41b00135d..f4372b09d 100644
--- a/screenpipe-audio/tests/core_tests.rs
+++ b/screenpipe-audio/tests/core_tests.rs
@@ -13,7 +13,6 @@ mod tests {
use std::sync::Arc;
use std::time::{Duration, Instant};
use tokio::sync::mpsc::unbounded_channel;
- use screenpipe_audio::vad_engine::{VadEngineEnum, WebRtcVad};
fn setup() {
// Initialize the logger with an info level filter
@@ -51,12 +50,10 @@ mod tests {
let whisper_model =
WhisperModel::new(Arc::new(AudioTranscriptionEngine::WhisperTiny)).unwrap();
- let mut vad_engine = WebRtcVad::new();
let text = stt(
"./test_data/selah.mp4",
&whisper_model,
Arc::new(AudioTranscriptionEngine::WhisperTiny),
- &mut vad_engine
)
.unwrap();
let duration = start.elapsed();
@@ -234,12 +231,9 @@ mod tests {
PathBuf::from(format!("test_output_{}.mp4", Utc::now().timestamp_millis()));
let output_path_2 = output_path.clone();
let (whisper_sender, mut whisper_receiver, _) =
- create_whisper_channel(
- Arc::new(AudioTranscriptionEngine::WhisperTiny),
- VadEngineEnum::WebRtc
- )
- .await
- .unwrap();
+ create_whisper_channel(Arc::new(AudioTranscriptionEngine::WhisperTiny))
+ .await
+ .unwrap();
let is_running = Arc::new(AtomicBool::new(true));
// Start recording in a separate thread
let recording_thread = tokio::spawn(async move {
diff --git a/screenpipe-server/src/bin/screenpipe-server.rs b/screenpipe-server/src/bin/screenpipe-server.rs
index 723b80c18..16b0120c1 100644
--- a/screenpipe-server/src/bin/screenpipe-server.rs
+++ b/screenpipe-server/src/bin/screenpipe-server.rs
@@ -262,7 +262,6 @@ async fn main() -> anyhow::Result<()> {
});
let ocr_engine_clone = cli.ocr_engine.clone();
let restart_interval = cli.restart_interval;
- let vad_engine = cli.vad_engine.clone();
// Function to start or restart the recording task
let _start_recording = tokio::spawn(async move {
@@ -284,7 +283,6 @@ async fn main() -> anyhow::Result<()> {
let vision_control = vision_control.clone();
let audio_devices_control = audio_devices_control.clone();
let friend_wearable_uid_clone = friend_wearable_uid.clone(); // Clone for each iteration
- let vad_engine_clone = vad_engine.clone(); // Clone it here for each iteration
tokio::select! {
_ = &mut recording_task => {
@@ -321,10 +319,9 @@ async fn main() -> anyhow::Result<()> {
cli.save_text_files,
audio_transcription_engine,
ocr_engine,
- friend_wearable_uid_clone,
+ friend_wearable_uid_clone, // Use the cloned version
monitor_id,
cli.use_pii_removal,
- vad_engine_clone,
)
.await;
diff --git a/screenpipe-server/src/cli.rs b/screenpipe-server/src/cli.rs
index 42e5d1961..f3601fb42 100644
--- a/screenpipe-server/src/cli.rs
+++ b/screenpipe-server/src/cli.rs
@@ -2,7 +2,6 @@ use clap::Parser;
use screenpipe_audio::AudioTranscriptionEngine as CoreAudioTranscriptionEngine;
use screenpipe_vision::utils::OcrEngine as CoreOcrEngine;
use clap::ValueEnum;
-use screenpipe_audio::vad_engine::VadEngineEnum;
#[derive(Clone, Debug, ValueEnum, PartialEq)]
pub enum CliAudioTranscriptionEngine {
@@ -51,23 +50,6 @@ impl From<CliOcrEngine> for CoreOcrEngine {
}
}
-#[derive(Clone, Debug, ValueEnum, PartialEq)]
-pub enum CliVadEngine {
- #[clap(name = "webrtc")]
- WebRtc,
- #[clap(name = "silero")]
- Silero,
-}
-
-impl From<CliVadEngine> for VadEngineEnum {
- fn from(cli_engine: CliVadEngine) -> Self {
- match cli_engine {
- CliVadEngine::WebRtc => VadEngineEnum::WebRtc,
- CliVadEngine::Silero => VadEngineEnum::Silero,
- }
- }
-}
-
#[derive(Parser)]
#[command(
author,
@@ -169,8 +151,4 @@ pub struct Cli {
/// Restart recording process every X minutes (0 means no periodic restart) - NOT RECOMMENDED
#[arg(long, default_value_t = 0)]
pub restart_interval: u64,
-
- /// VAD engine to use for speech detection
- #[arg(long, value_enum, default_value_t = CliVadEngine::Silero)] // Silero or WebRtc
- pub vad_engine: CliVadEngine,
}
\ No newline at end of file
diff --git a/screenpipe-server/src/core.rs b/screenpipe-server/src/core.rs
index 8a78caed2..0271b59bf 100644
--- a/screenpipe-server/src/core.rs
+++ b/screenpipe-server/src/core.rs
@@ -1,4 +1,3 @@
-use crate::cli::CliVadEngine;
use crate::{DatabaseManager, VideoCapture};
use anyhow::Result;
use chrono::Utc;
@@ -7,7 +6,6 @@ use log::{debug, error, info, warn};
use screenpipe_audio::{
create_whisper_channel, record_and_transcribe, AudioDevice, AudioInput,
AudioTranscriptionEngine, DeviceControl, TranscriptionResult,
- vad_engine::VadEngineEnum,
};
use screenpipe_core::pii_removal::remove_pii;
use screenpipe_integrations::friend_wearable::initialize_friend_wearable_loop;
@@ -34,7 +32,6 @@ pub async fn start_continuous_recording(
friend_wearable_uid: Option<String>,
monitor_id: u32,
use_pii_removal: bool,
- vad_engine: CliVadEngine,
) -> Result<()> {
let (whisper_sender, whisper_receiver, whisper_shutdown_flag) = if audio_disabled {
// Create a dummy channel if no audio devices are available, e.g. audio disabled
@@ -50,7 +47,7 @@ pub async fn start_continuous_recording(
Arc::new(AtomicBool::new(false)),
)
} else {
- create_whisper_channel(audio_transcription_engine.clone(), VadEngineEnum::from(vad_engine)).await?
+ create_whisper_channel(audio_transcription_engine.clone()).await?
};
let whisper_sender_clone = whisper_sender.clone();
let db_manager_video = Arc::clone(&db);