Aider-AI/aider · error · ValueError

Unsupported audio format: {audio_format}

Error message

Unsupported audio format: {audio_format}

What it means

Voice.__init__ in aider/voice.py validates the audio_format constructor argument against the whitelist ["wav", "mp3", "webm"] — the formats the transcription path can encode with soundfile. Anything else (including uppercase variants like 'WAV', 'm4a', 'ogg') raises ValueError immediately at construction. The value only affects the temp-file suffix/encoding used when sending audio to the transcription API.

Source

Thrown at aider/voice.py:74

                        device_id = i
                        break
                if device_id is None:
                    available_inputs = [d["name"] for d in devices if d["max_input_channels"] > 0]
                    raise ValueError(
                        f"Device '{device_name}' not found. Available input devices:"
                        f" {available_inputs}"
                    )

                print(f"Using input device: {device_name} (ID: {device_id})")

                self.device_id = device_id
            else:
                self.device_id = None

        except (OSError, ModuleNotFoundError):
            raise SoundDeviceError
        if audio_format not in ["wav", "mp3", "webm"]:
            raise ValueError(f"Unsupported audio format: {audio_format}")
        self.audio_format = audio_format

    def callback(self, indata, frames, time, status):
        """This is called (from a separate thread) for each audio block."""
        import numpy as np

        rms = np.sqrt(np.mean(indata**2))
        self.max_rms = max(self.max_rms, rms)
        self.min_rms = min(self.min_rms, rms)

        rng = self.max_rms - self.min_rms
        if rng > 0.001:
            self.pct = (rms - self.min_rms) / rng
        else:
            self.pct = 0.5

        self.q.put(indata.copy())

View on GitHub (pinned to 5dc9490bb3)

Solutions

  1. Use exactly one of 'wav', 'mp3', or 'webm' (lowercase).
  2. Normalize user input: lower().strip() and reject/convert unsupported formats before constructing Voice.
  3. If you need m4a/ogg, record as 'webm' or 'wav' and convert externally after record_and_transcribe returns.

Example fix

# before
voice = Voice(audio_format="m4a")  # ValueError: Unsupported audio format

# after
fmt = "m4a".lower().strip()
voice = Voice(audio_format=fmt if fmt in {"wav", "mp3", "webm"} else "wav")
Defensive patterns

Strategy: type-guard

Validate before calling

VALID_FORMATS = ("wav", "mp3", "webm")

def make_voice(audio_format):
    fmt = str(audio_format).strip().lower()
    if fmt not in VALID_FORMATS:
        raise ValueError(f"audio_format must be one of {VALID_FORMATS}; defaulting to wav")
    from aider.voice import Voice
    return Voice(audio_format=fmt)

Type guard

def is_supported_audio_format(v) -> bool:
    return isinstance(v, str) and v in ("wav", "mp3", "webm")

Prevention

When it happens

Trigger: Instantiating Voice(audio_format=...) with any string not exactly 'wav', 'mp3', or 'webm' — e.g. 'm4a', 'ogg', 'WAV', 'flac'. Raises in __init__ before any recording occurs.

Common situations: Porting code that recorded to m4a/ogg on other platforms; passing a format constant from another library's enum; assuming case-insensitivity.

Related errors


AI-assisted analysis of Aider-AI/aider@5dc9490bb3 (2026-08-15). Data as JSON: /api/errors/c8a401b3fdc1203d. Report an issue: GitHub.