fix: drain loop uses fixed 100ms deadline instead of idle timeout

This commit is contained in:
2026-08-17 06:41:32 +00:00
parent 20e5c6c542
commit b3e0fe3b30
+7 -6
View File
@@ -288,11 +288,9 @@ fn transcriber_loop(
r.log_event(&format!("session {} started", shared.session_id));
}
let drain_timeout = Duration::from_millis(100);
// Main loop: process audio until stop_signal
while !stop_signal.load(Ordering::SeqCst) {
match rx.recv_timeout(drain_timeout) {
match rx.recv_timeout(Duration::from_millis(100)) {
Ok(chunk) => {
if let Some(ref mut r) = recorder {
r.add_audio(&chunk);
@@ -323,9 +321,12 @@ fn transcriber_loop(
}
}
// Drain trailing audio from ALSA buffer (cpal stream still alive)
loop {
match rx.recv_timeout(drain_timeout) {
// Drain trailing audio from ALSA buffer (cpal stream still alive).
// Fixed 100ms window — cpal delivers every ~50ms (800 samples @ 16kHz),
// so this captures 1-2 more callbacks worth of trailing audio.
let drain_deadline = std::time::Instant::now() + Duration::from_millis(100);
while std::time::Instant::now() < drain_deadline {
match rx.recv_timeout(drain_deadline - std::time::Instant::now()) {
Ok(chunk) => {
if let Some(ref mut r) = recorder {
r.add_audio(&chunk);