Expand description
§Voice I/O — a talking application in five lines
The Live API speaks PCM16: 16 kHz in, 24 kHz out. Everything between a microphone and that contract — resampling, channel down-mix, playback buffering, and barge-in (the user speaks over the model; buffered speech must vanish now) — is plumbing every voice application needs and none should write. This module is that plumbing, engineered as two primitives:
pump— the device-independent duplex core. Feed it microphone frames on a channel at any sample rate; receive playback frames on another at any sample rate. It resamples both directions, forwardsLiveEvent::Audioto your speaker channel, and turns an interruption into an explicitPlayback::Flushso stale audio is dropped, not played. Works with any audio backend — or none (tests drive it with plain channels).Talk::talk(featurevoice-io) — the whole loop on the system’s default microphone and speakers viacpal, with drain signaling wired back into the session’s voice reactor. Ctrl-C or session end stops it. Without the feature there is notalk()method on the handle: theTalkextension trait is only compiled whenvoice-iois enabled (Linux also needslibasound2-dev).
ⓘ
// `voice-io` feature: the doctest cannot compile without it.
let session = Live::builder()
.instruction("You are a helpful concierge.")
.greeting("Greet the caller.")
.connect_from_env().await?;
session.talk().await?;Re-exports§
pub use dsp::AudioBus;pub use dsp::ChainMetrics;pub use dsp::ChainSnapshot;pub use dsp::DspChain;pub use dsp::DspStage;pub use dsp::IntStage;pub use dsp::StageSnapshot;
Modules§
- dsp
- DSP foundation for the mic chain: a float audio bus, a stage contract, and a metered chain runner.
Structs§
- Denoiser
- RNNoise noise suppression as a mic-chain stage. One instance per stream — the network is stateful across frames.
- Noise
Gate - A reference
InputAudioProcessor: an energy gate that silences frames whose RMS falls below a threshold, with a hold so word tails are not chopped. A floor, not a denoiser — it removes constant low-level room noise between utterances and nothing more. - Voice
Pump - The two halves of a running duplex pump. Ends on its own when the session
closes or either channel hangs up;
abortends it early.
Enums§
- Playback
- One playback instruction to the speaker side.
- Voice
IoError - Errors from the device layer.
Constants§
- SESSION_
INPUT_ HZ - The sample rate the Live API expects on its input stream.
- SESSION_
OUTPUT_ HZ - The sample rate the Live API produces on its output stream.
Traits§
- Input
Audio Processor - The mic-chain stage trait — one
process_frameover a PCM16 frame in place. Defined by the L1 runtime (Live::mic_processortakes the same trait), re-exported here so a voice application has one name for it. A per-frame processor applied to outgoing microphone audio insideLiveHandle::send_audio— the L1 seam the L2voicechain (denoiser, noise gate) plugs into so hosted surfaces (web bridge, API server) get the same hardened path as native pumps. Runs on the send path: keep it fast and allocation-light. - Talk
- Run a full-duplex voice conversation on the system’s default audio devices.
Functions§
- downmix
- Down-mix interleaved multi-channel PCM16 to mono by averaging.
- pump
- Run the device-independent duplex loop between audio channels and a session.
- pump_
processed pump, with a chain ofInputAudioProcessors applied to each microphone frame before resampling — the insertion point for denoisers and client-side voice-activity gates. Processors run in order at the mic’s native rate; an emptied frame (all-zero) still flows, so the session’s own VAD sees continuous audio.- resample
- Linear-interpolation resampling for mono PCM16.