Skip to content

armgit / Handy

Public Imported from GitHub
0

A free, open source, and extensible speech-to-text application that works completely offline.

fix(audio): skip level meter and resampler while idle in always-on mode (#1873)

Mike Evdokimovdb003f38b1ae
diff --git a/src-tauri/src/audio_toolkit/audio/recorder.rs b/src-tauri/src/audio_toolkit/audio/recorder.rs
index 9bc77d05..08a44304 100644
--- a/src-tauri/src/audio_toolkit/audio/recorder.rs
+++ b/src-tauri/src/audio_toolkit/audio/recorder.rs
@@ -797,24 +797,33 @@ fn run_consumer(
);
}
- // ---------- spectrum processing ---------------------------------- //
- if let Some(buckets) = visualizer.feed(&raw) {
- if let Some(cb) = &level_cb {
- cb(buckets);
+ // ---------- recording-time processing ---------------------------- //
+ // In always-on mode the capture stream stays open continuously for
+ // zero-latency start, so while idle (not recording) there is nothing to
+ // do with a chunk: handle_frame returns early when not recording, which
+ // means the resampled output would be discarded, and the level meter has
+ // no idle consumer. Skip both the level-meter FFT and the resampler while
+ // idle to avoid doing unnecessary work whose output is thrown away. Both
+ // are reset on Cmd::Start (visualizer.reset() / frame_resampler.reset()),
+ // so they resume cleanly the moment recording begins.
+ if recording {
+ if let Some(buckets) = visualizer.feed(&raw) {
+ if let Some(cb) = &level_cb {
+ cb(buckets);
+ }
}
- }
- // ---------- existing pipeline ------------------------------------ //
- frame_resampler.push(&raw, &mut |frame: &[f32]| {
- handle_frame(
- frame,
- recording,
- vad_policy,
- &vad,
- &audio_cb,
- &mut processed_samples,
- )
- });
+ frame_resampler.push(&raw, &mut |frame: &[f32]| {
+ handle_frame(
+ frame,
+ recording,
+ vad_policy,
+ &vad,
+ &audio_cb,
+ &mut processed_samples,
+ )
+ });
+ }
if recording {
if let Some(started) = awaiting_first_captured_chunk.take() {