Skip to main content

Module codec

Module codec 

Source
Expand description

Audio bridging for the hardware session: Opus <-> PCM and PCM <-> WAV.

The rest of Core speaks WAV/PCM (whisper transcribe, OuteTTS synth), while the device link speaks Opus (PROTOCOL.md §2):

  • Uplink mic: Opus, mono, 16 kHz, 60 ms frames (960 samples/frame).
  • Downlink TTS: Opus, mono, 24 kHz, 60 ms frames (1440 samples/frame).

This module owns the codec edges so super::session only ever deals in decoded PCM / WAV bytes. Opus runs through audiopus (which vendors libopus via audiopus_sys, so no system libopus is required); WAV read/write runs through hound.

Structs§

DecodedWav
Parsed PCM from a WAV blob (mono i16 at its native rate). Returned by wav_to_pcm16 so the TTS WAV produced by OuteTTS can be re-encoded as Opus.
DownlinkEncoder
Opus encoder for the 24 kHz mono TTS downlink. One per TTS stream.
UplinkDecoder
Opus decoder for the 16 kHz mono mic uplink. One per session (Opus decoder state is stateful across frames).

Constants§

DOWNLINK_RATE
TTS downlink sample rate (Hz).
FRAME_MS
Frame duration in milliseconds (both directions).
UPLINK_RATE
Mic uplink sample rate (Hz).

Functions§

pcm16_to_wav
Wrap 16 kHz mono PCM (i16) as a RIFF/WAV byte blob for the whisper/meetings transcribe path, which takes WAV file bytes.
resample_to
Linear-interpolation resampler to the 24 kHz Opus downlink rate. OuteTTS already emits 24 kHz mono, so this is a near-no-op fast path when rates match; it exists so a different TTS engine (a ?engine= sidecar at another rate) still produces a correctly-pitched downlink rather than a chipmunk artifact.
wav_to_pcm16
Decode a WAV blob to mono i16 PCM. Down-mixes any multi-channel input and converts float samples to i16. The sample rate is read from the header so the caller can resample to the 24 kHz Opus downlink as needed.