Module voice

Module voice 

Source
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, forwards LiveEvent::Audio to your speaker channel, and turns an interruption into an explicit Playback::Flush so stale audio is dropped, not played. Works with any audio backend — or none (tests drive it with plain channels).
  • Talk::talk (feature voice-io) — the whole loop on the system’s default microphone and speakers via cpal, with drain signaling wired back into the session’s voice reactor. Ctrl-C or session end stops it. Without the feature there is no talk() method on the handle: the Talk extension trait is only compiled when voice-io is enabled (Linux also needs libasound2-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.
NoiseGate
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.
VoicePump
The two halves of a running duplex pump. Ends on its own when the session closes or either channel hangs up; abort ends it early.

Enums§

Playback
One playback instruction to the speaker side.
VoiceIoError
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§

InputAudioProcessor
The mic-chain stage trait — one process_frame over a PCM16 frame in place. Defined by the L1 runtime (Live::mic_processor takes the same trait), re-exported here so a voice application has one name for it. A per-frame processor applied to outgoing microphone audio inside LiveHandle::send_audio — the L1 seam the L2 voice chain (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 of InputAudioProcessors 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.