Audio pipeline
All audio handling flows through one shared crate,crates/echo-audio, a member of the cargo workspace alongside src-tauri and cli. Live capture is fully in memory on every platform: there are no temporary WAV files in the recording path. The reasoning is in ADR 0005.
Rules
- Never re-implement resample, downmix, normalize or WAV reading anywhere else. Import from
echo_audio. - The model dispatch lives only in
src-tauri/src/transcription/mod.rs::transcribe_source. - Open mic (VAD) works on all platforms. Its state machine consumes 256-sample chunks from
echo_audio::capture, which is what Silero v5 requires.
What the crate contains
- Sample math: downmix, peak normalize, peak and RMS.
- Linear and streaming resamplers.
- WAV reading and writing.
- Live capture through
cpal(cargo featurecapture). AudioSource, the switch between disk and memory.
The AudioSource switch
echo_audio::AudioSource { File(PathBuf) | Memory(AudioBuffer) } is the single point where disk and memory meet. Live capture produces Memory. A dropped file or an explicit path produces File. samples_mono_16k() resolves either to canonical 16 kHz mono f32, borrowing rather than copying a buffer that is already at 16 kHz.
The TranscriptionBackend trait has one required method, transcribe_samples, plus a provided transcribe(&AudioSource). Backends never touch files.
Capture pipeline
- Chunk sizes: 1024 samples for plain recording (
RECORD_CHUNK_SAMPLESinsrc-tauri/src/audio/recorder.rs), 256 for Silero VAD v5. - The
StreamingResampleris tested for equivalence against the batch resampler across arbitrary chunk boundaries. - On macOS an AVFoundation microphone-permission request runs before capture, because
cpalsilently sees no devices until access is granted.
WSL capture (parec)
cpal’s Linux host is ALSA only. WSLg exposes the passed-through Windows microphone as a PulseAudio source (RDPSource on /mnt/wslg/PulseServer), not an ALSA device. On a stock WSL box cpal::default_host().default_input_device() therefore returns nothing even though pactl lists the mic.
crates/echo-audio/src/capture.rs adds a #[cfg(target_os = "linux")] runtime branch. When echo_audio::wsl::wslg_pulse_available() is true (WSL environment markers and the /mnt/wslg/PulseServer socket), the capture thread spawns:
Chunker the cpal path uses. Asking parec for 16 kHz mono f32 makes the resampler a passthrough. Everything downstream is shared.
Why parec rather than the alternatives:
libpulse-simplewould add alibpulse-devbuild dependency.parecneeds no new build or CI dependency; it ships inpulseaudio-utils, the package that already providespactl.- An ALSA-to-Pulse configuration (
~/.asoundrc,libasound2-plugins) is per user and fragile.
cpal/ALSA path. The .deb declares pulseaudio-utils and libasound2-plugins as dependencies in src-tauri/tauri.conf.json5.
The persisted input_device setting (mapped in src-tauri/src/audio/recorder.rs) becomes parec --device=<name>; default or unset omits the flag. On WSL the value is a Pulse source name; on Windows and macOS it is a cpal device display name.
Smoke test on a WSL machine:
echophrase CLI still uses cpal and ALSA directly.
Normalization
Two normalizers exist, for different jobs. See Audio normalization for the Whisper details.echo_audioprovides peak normalization for the canonical 16 kHz form (used by the CLItranscodecommand, which has--no-normalize).- The Candle Whisper path applies its own amplify-only normalization, because Whisper is not scale invariant.
Hands-free end to end test
On macOS you can verify record, transcribe and paste with no human interaction, using the speakers as the audio source:key code 105 is F13, the remapped Dictation key and the default macOS record hotkey (shown as “F5” in the UI; see macOS dictation key). say plays through the speakers and the microphone picks it up, so real audio goes through the real capture stack. To assert in-memory behavior, check that stdout has no temp-file lines and no new *.wav appears under the app data or temp directories during the cycle.
Requirements: the dev app running, microphone and accessibility permission granted to the terminal, and speakers audible to the microphone. Fixture-based tests are described in tests/audio/CLAUDE.md.