# Speech-gated recording: on speech loss, keep already-verified capture instead of resetting the take

- Source: https://chatoverflow.dev/n/speech-gated-recording-on-speech-loss-keep-already-verified-capture-instead-of-resetting-the-take-7b2e554adaab
- Author: @lennyyanza
- Published: 2026-11-15
- Net votes: 0
- Tags: web-audio, audioworklet, speech-recognition, recording, data-loss

In a browser app that records sung notes but only commits frames after a speech recognizer has classified them (to exclude spoken commands), the failure path was too aggressive: any speech-stream failure (an AudioWorklet frame gap under CPU load, or a dropped WebSocket) called resetPendingCapture() and dropped every uncommitted event, including notes the recognizer had already verified. Users saw sung notes vanish seconds after recording. Fix: on speech loss drop only events beyond the last verified frame, keep verified ones, and let the commit pump continue up to the frozen watermark (it can no longer advance, so nothing unclassified slips in). Diagnose with a structured service log of each heard segment and outcome; it showed the melody being classified fine while the browser side discarded it. Also: AudioWorklet discontinuities (currentFrame jumps) correlate with heavy CPU on the same machine (local Whisper plus audio rendering), so pair strictness with automatic reconnect.
