Skip to main content

Module audio

Module audio 

Source
Expand description

Audio capture: the sources, the recordings they write, and the canonical 16 kHz mono format shared by everything that reads them. A Clip is finished audio at its own rate.

RecordingReader builds on every target. Everything that opens a microphone, a model, or a file is native.

Structs§

Clip
Mono samples and the rate they were taken at.
Microphonemicrophone and non-target_family=wasm
The default microphone, ready to record. open() chooses a private per-user spool directory and a 60-second maximum duration; the builder overrides either.
MicrophoneBuildermicrophone and non-target_family=wasm
PreparedMicrophonemicrophone and non-target_family=wasm
A microphone whose fallible setup is done. Opening it starts the worker thread, which opens the input device.
RecordedAudio
The result of a finished recording: its length and, on a target with a filesystem, its WAV. A WAV this crate wrote is deleted when its owner drops. A caller’s own file is only borrowed. A recording ended by RecordingWriter::finish has none.
Recording
What one capture’s writer and readers share: each reader’s queue of unread samples, the count written, and how capture ended. It keeps no history: a sample lives only in the queues of readers yet to take it.
RecordingReader
A window onto a recording, readable while capture is still writing it. One reader; RecordingReader::fork adds another.
RecordingWriter
The write end of a Recording.
ResamplerNon-target_family=wasm
Converts mono f32 audio at any sample rate to canonical 16 kHz.
SilenceDurationNon-target_family=wasm
StopSignal
The capture-side stop check. Owned by the capture worker, which drops it the moment recording ends — owners can rely on that drop for cleanup.
Stopper
A handle that ends a recording from anywhere: clone it, hand it to a hotkey or UI, call stop().
WakeWordControlmicrophone and non-target_family=wasm
WakeWordMonitormicrophone and non-target_family=wasm
WakeWordSuspensionmicrophone and non-target_family=wasm
WavReplayCaptureNon-target_family=wasm

Enums§

CaptureError
ClipError
MicrophoneErrorNon-target_family=wasm
RecordingModeNon-target_family=wasm
ReplayPaceNon-target_family=wasm
How a WAV replay delivers its samples. Immediate writes the whole file before start returns. Realtime writes it at recorded speed, so transcription overlaps capture as on a real press.
ResampleErrorNon-target_family=wasm
SilenceDurationErrorNon-target_family=wasm
SpoolErrorNon-target_family=wasm
WakeWordEventmicrophone and non-target_family=wasm
WakeWordFailuremicrophone and non-target_family=wasm
WavErrorNon-target_family=wasm
WavReplayErrorNon-target_family=wasm

Constants§

CANONICAL_SAMPLE_RATE
CHANNELS

Traits§

AudioCaptureNon-target_family=wasm
A source of canonical 16 kHz mono audio. Each implementation bounds how long a recording runs.

Functions§

canonical_duration
How long samples canonical samples last.
canonical_samples
How many canonical samples duration spans, rounded down. Saturates at u64::MAX.
check_default_input_devicemicrophone and non-target_family=wasm
Checks the default microphone as LiveStream::open does, without opening a stream, because that triggers the permission prompt. Returns the device name.
f32_from_pcm16
pcm16_from_f32Non-target_family=wasm
The nearest 16-bit sample to sample, saturating outside -1.0..1.0.
read_wavNon-target_family=wasm
Reads a PCM WAV, 8- to 32-bit integer or 32-bit float, at any rate a Clip accepts, as mono audio at the file’s rate. Channels are averaged. Unlike RecordingReader::from_wav_file, it sets no length limit.
remove_all_spoolsNon-target_family=wasm
write_wavNon-target_family=wasm
Writes clip to path as mono 16-bit PCM at its own rate, replacing any file there.