From 7733e86cfd11add4cd202eedc028d3f22cfd4e68 Mon Sep 17 00:00:00 2001 From: iamdoubz <> Date: Mon, 13 Jul 2026 19:19:05 -0500 Subject: [PATCH] feat(audio): write_wav_mono_16k helper for persisting the mic voiceprint (FR-SPK) --- src-tauri/src/audio/mod.rs | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/src-tauri/src/audio/mod.rs b/src-tauri/src/audio/mod.rs index d815904..597cfed 100644 --- a/src-tauri/src/audio/mod.rs +++ b/src-tauri/src/audio/mod.rs @@ -946,6 +946,28 @@ pub fn read_wav_mono_16k(path: &Path) -> Result, AudioError> { Ok(resampler.process(&mono)) } +/// Write mono 16kHz `f32` samples as a Float32 WAV — the format +/// [`read_wav_mono_16k`] reads back. Used to persist the mic voiceprint sample +/// next to a retained recording so it can be re-matched on reprocess (FR-SPK). +pub fn write_wav_mono_16k(path: &Path, samples: &[f32]) -> Result<(), AudioError> { + let spec = WavSpec { + channels: 1, + sample_rate: 16_000, + bits_per_sample: 32, + sample_format: SampleFormat::Float, + }; + let mut writer = + WavWriter::create(path, spec).map_err(|e| AudioError::Capture(format!("write wav: {e}")))?; + for &s in samples { + writer + .write_sample(s) + .map_err(|e| AudioError::Capture(format!("write wav: {e}")))?; + } + writer + .finalize() + .map_err(|e| AudioError::Capture(format!("write wav: {e}"))) +} + /// Ceiling on how far the still-flowing stream may run ahead of a stalled /// partner before the mixer forwards it alone — so a muted/dead microphone (or a /// silent system output) can't hold up the live transcript. 0.5s @ 16kHz.