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: parakeet 12GB memory spike — cap batch at 45s + 30s chunking with 1s overlap

louis030195402ddbd3cd0d
diff --git a/crates/screenpipe-audio/src/audio_manager/reconciliation.rs b/crates/screenpipe-audio/src/audio_manager/reconciliation.rs
index 8cd07fdc7..642db748b 100644
--- a/crates/screenpipe-audio/src/audio_manager/reconciliation.rs
+++ b/crates/screenpipe-audio/src/audio_manager/reconciliation.rs
@@ -51,14 +51,17 @@ struct PendingTranscription {
///
/// - Deepgram via Cloudflare: 100 MB upload limit ÷ 64 kbps ≈ 3.5 h → cap at 5000 s (~83 min)
/// - OpenAI-compatible: user-configurable (unknown engine limits), default 3000 s (~50 min)
-/// - Parakeet: no sliding window, handles long-form well → cap at 3600 s (60 min)
+/// - Parakeet: ONNX encoder has fixed-size relative position encoding (~5000 mel frames ≈ 50s).
+/// Longer audio causes ORT BroadcastIterator errors and ~10GB memory spikes.
+/// Cap at 45s — the engine layer chunks at 30s with 1s overlap + LCS dedup
+/// (matching NVIDIA's approach), so batches up to 45s are handled safely.
/// - Local Whisper: processes in 30s windows with context carryover → cap at 600 s (10 min)
/// - Qwen3-ASR: similar to Whisper architecture → cap at 600 s (10 min)
pub fn default_max_batch_duration_secs(engine: &AudioTranscriptionEngine) -> u64 {
match engine {
AudioTranscriptionEngine::Deepgram => 5000,
AudioTranscriptionEngine::OpenAICompatible => 3000,
- AudioTranscriptionEngine::Parakeet => 3600,
+ AudioTranscriptionEngine::Parakeet => 45,
_ => 600,
}
}
diff --git a/crates/screenpipe-audio/src/transcription/engine.rs b/crates/screenpipe-audio/src/transcription/engine.rs
index e8ca7bb1f..e1f8ca6fd 100644
--- a/crates/screenpipe-audio/src/transcription/engine.rs
+++ b/crates/screenpipe-audio/src/transcription/engine.rs
@@ -427,11 +427,55 @@ impl TranscriptionSession {
#[cfg(feature = "parakeet")]
Self::Parakeet { model, .. } => {
let mut engine = model.lock().map_err(|e| anyhow!("stt model lock: {}", e))?;
- let opts = audiopipe::TranscribeOptions::default();
- let result = engine
- .transcribe_with_sample_rate(audio, sample_rate, opts)
- .map_err(|e| anyhow!("{}", e))?;
- Ok(result.text)
+ // parakeet's ONNX encoder has fixed-size relative position encoding
+ // (~5000 mel frames ≈ 50s). chunk audio at 30s with 1s overlap,
+ // matching NVIDIA's recommended approach (arxiv 2509.14128).
+ // overlap regions are deduplicated via longest common word substring.
+ let chunk_samples = (sample_rate as usize) * 30;
+ if audio.len() <= chunk_samples {
+ let opts = audiopipe::TranscribeOptions::default();
+ let result = engine
+ .transcribe_with_sample_rate(audio, sample_rate, opts)
+ .map_err(|e| anyhow!("{}", e))?;
+ Ok(result.text)
+ } else {
+ let overlap_samples = sample_rate as usize; // 1s overlap
+ let step = chunk_samples - overlap_samples;
+ let mut texts: Vec<String> = Vec::new();
+ let mut offset = 0;
+ while offset < audio.len() {
+ let end = (offset + chunk_samples).min(audio.len());
+ let chunk = &audio[offset..end];
+ let opts = audiopipe::TranscribeOptions::default();
+ let result = engine
+ .transcribe_with_sample_rate(chunk, sample_rate, opts)
+ .map_err(|e| anyhow!("{}", e))?;
+ let text = result.text.trim().to_string();
+ if !text.is_empty() {
+ if let Some(prev) = texts.last_mut() {
+ // deduplicate overlap via LCS on words
+ if let Some((prev_idx, _cur_idx, match_len)) =
+ super::text_utils::longest_common_word_substring(prev, &text)
+ {
+ let prev_words: Vec<&str> = prev.split_whitespace().collect();
+ *prev = prev_words[..prev_idx].join(" ");
+ let cur_words: Vec<&str> = text.split_whitespace().collect();
+ let skip = _cur_idx + match_len;
+ if skip < cur_words.len() {
+ texts.push(cur_words[skip..].join(" "));
+ }
+ } else {
+ texts.push(text);
+ }
+ } else {
+ texts.push(text);
+ }
+ }
+ if end >= audio.len() { break; }
+ offset += step;
+ }
+ Ok(texts.join(" "))
+ }
}
#[cfg(feature = "parakeet-mlx")]