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

chore: change audio stt arg name

Louis Beaumontba6e17df2fc7
diff --git a/screenpipe-audio/src/bin/screenpipe-audio.rs b/screenpipe-audio/src/bin/screenpipe-audio.rs
index 7c1fcb47e..fb822509f 100644
--- a/screenpipe-audio/src/bin/screenpipe-audio.rs
+++ b/screenpipe-audio/src/bin/screenpipe-audio.rs
@@ -8,6 +8,7 @@ use screenpipe_audio::list_audio_devices;
use screenpipe_audio::parse_audio_device;
use screenpipe_audio::record_and_transcribe;
use screenpipe_audio::AudioDevice;
+use screenpipe_audio::AudioTranscriptionEngine;
use std::path::PathBuf;
use std::sync::atomic::AtomicBool;
use std::sync::Arc;
@@ -25,9 +26,6 @@ struct Args {
#[clap(long, help = "List available audio devices")]
list_audio_devices: bool,
-
- #[clap(long, help = "Disable cloud audio processing")]
- cloud_audio_off: bool,
}
fn print_devices(devices: &[AudioDevice]) {
@@ -77,8 +75,8 @@ async fn main() -> Result<()> {
let chunk_duration = Duration::from_secs(5);
let output_path = PathBuf::from("output.mp4");
- let cloud_audio = !args.cloud_audio_off;
- let (whisper_sender, mut whisper_receiver) = create_whisper_channel(cloud_audio).await?;
+ let (whisper_sender, mut whisper_receiver) =
+ create_whisper_channel(Arc::new(AudioTranscriptionEngine::WhisperTiny)).await?;
// Spawn threads for each device
let recording_threads: Vec<_> = devices
.into_iter()
@@ -132,4 +130,4 @@ async fn main() -> Result<()> {
}
Ok(())
-}
\ No newline at end of file
+}
diff --git a/screenpipe-audio/src/core.rs b/screenpipe-audio/src/core.rs
index aad411a41..59cde8c50 100644
--- a/screenpipe-audio/src/core.rs
+++ b/screenpipe-audio/src/core.rs
@@ -16,6 +16,19 @@ use tokio::sync::mpsc::{self, UnboundedSender};
use crate::AudioInput;
+#[derive(Clone, Debug, PartialEq)]
+pub enum AudioTranscriptionEngine {
+ #[allow(dead_code)]
+ Deepgram,
+ WhisperTiny,
+}
+
+impl Default for AudioTranscriptionEngine {
+ fn default() -> Self {
+ AudioTranscriptionEngine::WhisperTiny
+ }
+}
+
#[derive(Clone)]
pub struct DeviceControl {
pub is_running: bool,
diff --git a/screenpipe-audio/src/lib.rs b/screenpipe-audio/src/lib.rs
index f1040f070..caf147d08 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, DeviceControl,
+ record_and_transcribe, AudioDevice, AudioTranscriptionEngine, DeviceControl,
};
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 be971e4b2..62c6c4473 100644
--- a/screenpipe-audio/src/stt.rs
+++ b/screenpipe-audio/src/stt.rs
@@ -1,4 +1,7 @@
-use std::time::{SystemTime, UNIX_EPOCH};
+use std::{
+ sync::Arc,
+ time::{SystemTime, UNIX_EPOCH},
+};
use anyhow::{Error as E, Result};
use candle::{Device, IndexOp, Tensor};
@@ -14,7 +17,7 @@ use rubato::{
Resampler, SincFixedIn, SincInterpolationParameters, SincInterpolationType, WindowFunction,
};
-use crate::{multilingual, pcm_decode::pcm_decode};
+use crate::{multilingual, pcm_decode::pcm_decode, AudioTranscriptionEngine};
use webrtc_vad::{Vad, VadMode};
@@ -486,7 +489,11 @@ fn transcribe_with_deepgram(api_key: &str, audio_data: &[f32]) -> Result<String>
}
}
-pub fn stt(file_path: &str, whisper_model: &WhisperModel, cloud_audio: bool) -> Result<String> {
+pub fn stt(
+ file_path: &str,
+ whisper_model: &WhisperModel,
+ audio_transcription_engine: Arc<AudioTranscriptionEngine>,
+) -> Result<String> {
debug!("Starting speech to text for file: {}", file_path);
let model = &whisper_model.model;
let tokenizer = &whisper_model.tokenizer;
@@ -559,7 +566,7 @@ pub fn stt(file_path: &str, whisper_model: &WhisperModel, cloud_audio: bool) ->
pcm_data.len() / frame_size
);
- if cloud_audio {
+ if audio_transcription_engine == AudioTranscriptionEngine::Deepgram.into() {
// Deepgram implementation
let api_key = get_deepgram_api_key();
match transcribe_with_deepgram(&api_key, &speech_frames) {
@@ -697,7 +704,7 @@ pub struct TranscriptionResult {
pub error: Option<String>,
}
pub async fn create_whisper_channel(
- cloud_audio: bool,
+ audio_transcription_engine: Arc<AudioTranscriptionEngine>,
) -> Result<(
UnboundedSender<AudioInput>,
UnboundedReceiver<TranscriptionResult>,
@@ -721,7 +728,7 @@ pub async fn create_whisper_channel(
.expect("Time went backwards")
.as_secs();
- let transcription_result = match stt(&input.path, &whisper_model, cloud_audio) {
+ let transcription_result = match stt(&input.path, &whisper_model, audio_transcription_engine.clone()) {
Ok(transcription) => TranscriptionResult {
input: input.clone(),
transcription: Some(transcription),
diff --git a/screenpipe-server/src/bin/screenpipe-server.rs b/screenpipe-server/src/bin/screenpipe-server.rs
index 2777f8748..ade6555ed 100644
--- a/screenpipe-server/src/bin/screenpipe-server.rs
+++ b/screenpipe-server/src/bin/screenpipe-server.rs
@@ -24,9 +24,25 @@ use screenpipe_core::find_ffmpeg_path;
use screenpipe_server::logs::MultiWriter;
use screenpipe_server::{start_continuous_recording, DatabaseManager, ResourceMonitor, Server};
use tokio::sync::mpsc::channel;
+use screenpipe_vision::utils::OcrEngine as CoreOcrEngine;
+use screenpipe_audio::AudioTranscriptionEngine as CoreAudioTranscriptionEngine;
use clap::ValueEnum;
-use screenpipe_vision::utils::OcrEngine as CoreOcrEngine;
+
+#[derive(Clone, Debug, ValueEnum, PartialEq)]
+enum CliAudioTranscriptionEngine {
+ Deepgram,
+ WhisperTiny,
+}
+
+impl From<CliAudioTranscriptionEngine> for CoreAudioTranscriptionEngine {
+ fn from(cli_engine: CliAudioTranscriptionEngine) -> Self {
+ match cli_engine {
+ CliAudioTranscriptionEngine::Deepgram => CoreAudioTranscriptionEngine::Deepgram,
+ CliAudioTranscriptionEngine::WhisperTiny => CoreAudioTranscriptionEngine::WhisperTiny,
+ }
+ }
+}
#[derive(Clone, Debug, ValueEnum, PartialEq)]
enum CliOcrEngine {
@@ -121,14 +137,16 @@ struct Cli {
#[arg(long, default_value_t = false)]
save_text_files: bool,
- /// Enable cloud audio processing
- #[arg(long, default_value_t = false)]
- cloud_audio_on: bool,
+ /// Audio transcription engine to use.
+ /// Deepgram is a very high quality cloud-based transcription service (free of charge on us for now).
+ /// WhisperTiny is a local, lightweight transcription model.
+ #[arg(long, value_enum, default_value_t = CliAudioTranscriptionEngine::WhisperTiny)]
+ audio_transcription_engine: CliAudioTranscriptionEngine,
/// OCR engine to use.
/// AppleNative is the default local OCR engine for macOS.
/// WindowsNative is a local OCR engine for Windows.
- /// Unstructured is a cloud OCR engine (free of charge on us)
+ /// Unstructured is a cloud OCR engine (free of charge on us for now)
/// Tesseract is a local OCR engine (not supported on macOS)
#[cfg_attr(
target_os = "macos",
@@ -345,6 +363,7 @@ async fn main() -> anyhow::Result<()> {
let friend_wearable_uid = cli.friend_wearable_uid.clone();
let warning_ocr_engine_clone = cli.ocr_engine.clone();
+ let warning_audio_transcription_engine_clone = cli.audio_transcription_engine.clone();
let monitor_id = cli.monitor_id.unwrap_or(all_monitors.first().unwrap().id());
// try to use the monitor selected, if not available throw an error
@@ -379,6 +398,9 @@ async fn main() -> anyhow::Result<()> {
}
let core_ocr_engine: CoreOcrEngine = cli.ocr_engine.clone().into();
let ocr_engine = Arc::new(OcrEngine::from(core_ocr_engine));
+ let core_audio_transcription_engine: CoreAudioTranscriptionEngine = cli.audio_transcription_engine.clone().into();
+ let audio_transcription_engine = Arc::new(core_audio_transcription_engine);
+
recording_task = tokio::spawn(async move {
let result = start_continuous_recording(
db_clone,
@@ -388,7 +410,7 @@ async fn main() -> anyhow::Result<()> {
vision_control,
audio_devices_control,
cli.save_text_files,
- cli.cloud_audio_on,
+ audio_transcription_engine,
ocr_engine,
friend_wearable_uid_clone, // Use the cloned version
monitor_id
@@ -449,7 +471,7 @@ async fn main() -> anyhow::Result<()> {
println!("│ Audio Disabled │ {:<34} │", cli.disable_audio);
println!("│ Self Healing │ {:<34} │", cli.self_healing);
println!("│ Save Text Files │ {:<34} │", cli.save_text_files);
- println!("│ Cloud Audio │ {:<34} │", cli.cloud_audio_on);
+ println!("│ Audio Engine │ {:<34} │", format!("{:?}", warning_audio_transcription_engine_clone));
println!("│ OCR Engine │ {:<34} │", format!("{:?}", ocr_engine_clone));
println!("│ Monitor ID │ {:<34} │", monitor_id);
println!("│ Data Directory │ {:<34} │", local_data_dir_clone.display());
@@ -489,7 +511,7 @@ async fn main() -> anyhow::Result<()> {
// Add warning for cloud arguments
- if cli.cloud_audio_on || warning_ocr_engine_clone == CliOcrEngine::Unstructured {
+ if warning_audio_transcription_engine_clone == CliAudioTranscriptionEngine::Deepgram || warning_ocr_engine_clone == CliOcrEngine::Unstructured {
println!(
"{}",
"WARNING: You are using cloud now. Make sure to understand the data privacy risks."
diff --git a/screenpipe-server/src/core.rs b/screenpipe-server/src/core.rs
index be5c7f6f8..b6c96b2b2 100644
--- a/screenpipe-server/src/core.rs
+++ b/screenpipe-server/src/core.rs
@@ -4,8 +4,8 @@ use chrono::Utc;
use crossbeam::queue::SegQueue;
use log::{debug, error, info, warn};
use screenpipe_audio::{
- create_whisper_channel, record_and_transcribe, AudioDevice, AudioInput, DeviceControl,
- TranscriptionResult,
+ create_whisper_channel, record_and_transcribe, AudioDevice, AudioInput,
+ AudioTranscriptionEngine, DeviceControl, TranscriptionResult,
};
use screenpipe_integrations::friend_wearable::initialize_friend_wearable_loop;
use screenpipe_vision::OcrEngine;
@@ -52,13 +52,13 @@ pub async fn start_continuous_recording(
vision_control: Arc<AtomicBool>,
audio_devices_control: Arc<SegQueue<(AudioDevice, DeviceControl)>>,
save_text_files: bool,
- cloud_audio: bool,
+ audio_transcription_engine: Arc<AudioTranscriptionEngine>,
ocr_engine: Arc<OcrEngine>,
friend_wearable_uid: Option<String>,
monitor_id: u32,
) -> Result<()> {
-
- let (whisper_sender, whisper_receiver) = create_whisper_channel(cloud_audio).await?;
+ let (whisper_sender, whisper_receiver) =
+ create_whisper_channel(audio_transcription_engine.clone()).await?;
let db_manager_video = Arc::clone(&db);
let db_manager_audio = Arc::clone(&db);
@@ -101,7 +101,7 @@ pub async fn start_continuous_recording(
whisper_receiver,
audio_devices_control,
friend_wearable_uid,
- cloud_audio,
+ audio_transcription_engine,
)
.await
});
@@ -158,7 +158,8 @@ async fn record_video(
for window_result in &frame.window_ocr_results {
match db.insert_frame().await {
Ok(frame_id) => {
- let text_json = serde_json::to_string(&window_result.text_json).unwrap_or_default();
+ let text_json =
+ serde_json::to_string(&window_result.text_json).unwrap_or_default();
if let Err(e) = db
.insert_ocr_text(
@@ -201,7 +202,7 @@ async fn record_audio(
mut whisper_receiver: UnboundedReceiver<TranscriptionResult>,
audio_devices_control: Arc<SegQueue<(AudioDevice, DeviceControl)>>,
friend_wearable_uid: Option<String>,
- cloud_audio: bool,
+ audio_transcription_engine: Arc<AudioTranscriptionEngine>,
) -> Result<()> {
let mut handles: HashMap<String, JoinHandle<()>> = HashMap::new();
@@ -314,7 +315,7 @@ async fn record_audio(
&db,
transcription,
friend_wearable_uid.as_deref(),
- cloud_audio,
+ audio_transcription_engine.clone(),
)
.await
{
@@ -331,7 +332,7 @@ async fn process_audio_result(
db: &DatabaseManager,
result: TranscriptionResult,
_friend_wearable_uid: Option<&str>,
- cloud_audio: bool,
+ audio_transcription_engine: Arc<AudioTranscriptionEngine>,
) -> Result<(), anyhow::Error> {
if result.error.is_some() || result.transcription.is_none() {
error!(
@@ -341,7 +342,12 @@ async fn process_audio_result(
return Ok(());
}
let transcription = result.transcription.unwrap();
- let transcription_engine = if cloud_audio { "Deepgram" } else { "Whisper" };
+ let transcription_engine =
+ if audio_transcription_engine == AudioTranscriptionEngine::Deepgram.into() {
+ "Deepgram"
+ } else {
+ "Whisper"
+ };
info!("Inserting audio chunk: {:?}", result.input.path);
match db.insert_audio_chunk(&result.input.path).await {
@@ -372,4 +378,4 @@ async fn process_audio_result(
),
}
Ok(())
-}
\ No newline at end of file
+}