zeroclaw-labs/zeroclaw · error · anyhow::Error

Unsupported input sample format: {format}

Error message

Unsupported input sample format: {format}

What it means

Raised by PcmSampleFormat::try_from in the voice_wake channel when the cpal SampleFormat reported by the default input device's default_input_config() matches none of the twelve variants the channel maps (F32/F64/I8-I64/U8-U64 including 24-bit). Because the match covers every variant of the cpal version this crate was built against, the wildcard arm only fires when the compiled cpal exposes a format variant this code was never taught — i.e. a cpal/zeroclaw-channels version mismatch.

Source

Thrown at crates/zeroclaw-channels/src/voice_wake.rs:57

impl TryFrom<cpal::SampleFormat> for PcmSampleFormat {
    type Error = anyhow::Error;

    fn try_from(format: cpal::SampleFormat) -> Result<Self> {
        match format {
            cpal::SampleFormat::F32 => Ok(Self::F32),
            cpal::SampleFormat::F64 => Ok(Self::F64),
            cpal::SampleFormat::I8 => Ok(Self::I8),
            cpal::SampleFormat::I16 => Ok(Self::I16),
            cpal::SampleFormat::I24 => Ok(Self::I24),
            cpal::SampleFormat::I32 => Ok(Self::I32),
            cpal::SampleFormat::I64 => Ok(Self::I64),
            cpal::SampleFormat::U8 => Ok(Self::U8),
            cpal::SampleFormat::U16 => Ok(Self::U16),
            cpal::SampleFormat::U24 => Ok(Self::U24),
            cpal::SampleFormat::U32 => Ok(Self::U32),
            cpal::SampleFormat::U64 => Ok(Self::U64),
            format => bail!("Unsupported input sample format: {format}"),
        }
    }
}

fn build_input_stream<T>(
    device: &cpal::Device,
    config: cpal::StreamConfig,
    audio_tx: mpsc::Sender<Vec<f32>>,
) -> Result<cpal::Stream, cpal::Error>
where
    T: cpal::SizedSample,
    f32: cpal::FromSample<T>,
{
    use cpal::traits::DeviceTrait;

    device.build_input_stream(
        config,
        move |data: &[T], _: &cpal::InputCallbackInfo| {

View on GitHub (pinned to 88bb9c8533)

Solutions

  1. Align versions: pin cpal to the exact version zeroclaw-channels was built against (cargo update -p cpal --precise <ver>) or update zeroclaw-channels to a release that maps the new format.
  2. Run cargo tree -i cpal to find who pulled the mismatched cpal copy.
  3. As a workaround, point the OS default input device at a plain 16-bit/float PCM device so default_input_config() reports a mapped format.
  4. If it reproduces with aligned versions, report the device and its reported format so the mapping gains the variant.

Example fix

# before — Cargo.lock drifted, newer cpal adds a SampleFormat variant
# cargo tree -i cpal  -> cpal v0.16.x (mapping written for 0.15)

# after — pin back to the compatible release
cargo update -p cpal --precise 0.15.3
Defensive patterns

Strategy: validation

Validate before calling

// Probe the default input device's format before starting the channel.
use cpal::traits::{DeviceTrait, HostTrait};
let device = cpal::default_host().default_input_device()
    .ok_or_else(|| anyhow::anyhow!("no default input device"))?;
let fmt = device.default_input_config()?.sample_format();
let supported = matches!(fmt, cpal::SampleFormat::F32 | cpal::SampleFormat::F64
    | cpal::SampleFormat::I8 | cpal::SampleFormat::I16 | cpal::SampleFormat::I24
    | cpal::SampleFormat::I32 | cpal::SampleFormat::I64 | cpal::SampleFormat::U8
    | cpal::SampleFormat::U16 | cpal::SampleFormat::U24 | cpal::SampleFormat::U32
    | cpal::SampleFormat::U64);
anyhow::ensure!(supported, "device reports unmapped sample format {fmt}; align cpal/zeroclaw-channels versions");

Try / catch

match voice_wake.listen(tx).await {
    Ok(()) => unreachable!(),
    Err(e) if e.to_string().contains("Unsupported input sample format") => {
        // Version skew, not runtime state: fail loudly with the reported format;
        // do not retry — pin versions or update the channel mapping first.
    }
    Err(e) => return Err(e),
}

Prevention

When it happens

Trigger: VoiceWakeChannel::listen -> device.default_input_config() returns a SampleFormat added by a newer cpal than the one zeroclaw-channels' enum mapping supports (cargo resolved a newer cpal semver-compatible copy, or a custom build mixed versions); exotic host/device back-ends reporting a rare format land on the wildcard arm. The error surfaces at channel startup, before any audio flows.

Common situations: A `cargo update` bumps cpal to a release that introduces a new SampleFormat variant while zeroclaw-channels is pinned older; building with a fork/patched cpal; a new ALSA/CoreAudio device exposing a format the current mapping predates.

Related errors


AI-assisted analysis of zeroclaw-labs/zeroclaw@88bb9c8533 (2026-08-23). Data as JSON: /api/errors/e5f1e4337bc8df46. Report an issue: GitHub.