feat(A.2 #19): progressive WAV write during live capture
The Vec<f32> in-memory accumulator on run_live_session had three failure modes: (a) a crash during transcription took the recording with it, (b) RAM grew linearly with session length, (c) OOM killed the capture thread silently. New kon_audio::WavWriter wraps hound::WavWriter<BufWriter<File>> with an append-friendly API and a 500 ms-granularity header flush. On any abort after a flush the on-disk file is a valid, playable WAV. Unit test (brief item #19 acceptance) simulates the abort with std::mem::forget and asserts the pre-flush samples are recoverable. Live capture now: - resolves the destination path at start_live_transcription_session time via a new resolve_recording_path helper extracted from persist_audio_samples, - opens a WavWriter before any samples arrive, sample rate taken from LocalEngine::capabilities() (#13 wiring) with 16 kHz fallback, - feeds the resampler output through WavWriter::append inside append_resampled_audio — drops the writer with a user-visible warning if a write fails mid-session, - calls flush() at stop (after resampler tail), finalise() on clean exit, and drops-to-last-flushed state on abort. LiveSessionSummary.audio_samples → audio_path: the path is already written by the time stop_live_transcription_session runs; no post-session write step remains for live capture. persist_audio_samples is kept for the offline save_audio command.
This commit is contained in:
@@ -12,4 +12,4 @@ pub use decode::decode_audio_file;
|
||||
pub use resample::resample_to_16khz;
|
||||
pub use streaming_resample::StreamingResampler;
|
||||
pub use vad::SpeechDetector;
|
||||
pub use wav::{read_wav, write_wav};
|
||||
pub use wav::{read_wav, write_wav, WavWriter};
|
||||
|
||||
Reference in New Issue
Block a user