Skip to content

Commit fa1762c

Browse files
committed
🩹 (v2): ignore recordings shorter than 0.2s
1 parent 35cde64 commit fa1762c

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

assistant_v2/src/main.rs

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ use open;
1616
use speakstream::ss::SpeakStream;
1717
use std::error::Error;
1818
use std::path::PathBuf;
19+
use std::time::Instant;
1920
use std::sync::atomic::{AtomicBool, Ordering};
2021
use std::sync::{Arc, Mutex};
2122
use tracing_subscriber::{fmt, layer::SubscriberExt, util::SubscriberInitExt, EnvFilter};
@@ -273,6 +274,7 @@ fn start_ptt_thread(
273274
let mut key_pressed = false;
274275
let ptt_key = Key::F9;
275276
let mut current_path: Option<PathBuf> = None;
277+
let mut recording_start = Instant::now();
276278

277279
let callback = move |event: Event| match event.event_type {
278280
EventType::KeyPress(key) if key == ptt_key && !key_pressed => {
@@ -288,13 +290,22 @@ fn start_ptt_thread(
288290
let path = tmp_dir.path().join(format!("{}.wav", Uuid::new_v4()));
289291
if recorder.start_recording(&path, None).is_ok() {
290292
current_path = Some(path);
293+
recording_start = Instant::now();
291294
}
292295
}
293296
EventType::KeyRelease(key) if key == ptt_key && key_pressed => {
294297
key_pressed = false;
295298
if recorder.stop_recording().is_ok() {
296-
if let Some(p) = current_path.take() {
297-
audio_tx.send(p).unwrap();
299+
let elapsed = recording_start.elapsed();
300+
if elapsed.as_secs_f32() >= 0.2 {
301+
if let Some(p) = current_path.take() {
302+
audio_tx.send(p).unwrap();
303+
}
304+
} else {
305+
println!(
306+
"{}",
307+
"User recording too short. Aborting transcription and LLM response.".truecolor(255, 0, 0)
308+
);
298309
}
299310
}
300311
if duck_ptt {

0 commit comments

Comments
 (0)