{"record":{"id":"c8a401b3fdc1203d","repo":"Aider-AI/aider","slug":"unsupported-audio-format-audio-format","errorCode":null,"errorMessage":"Unsupported audio format: {audio_format}","messagePattern":"Unsupported audio format: (.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"aider/voice.py","lineNumber":74,"sourceCode":"                        device_id = i\n                        break\n                if device_id is None:\n                    available_inputs = [d[\"name\"] for d in devices if d[\"max_input_channels\"] > 0]\n                    raise ValueError(\n                        f\"Device '{device_name}' not found. Available input devices:\"\n                        f\" {available_inputs}\"\n                    )\n\n                print(f\"Using input device: {device_name} (ID: {device_id})\")\n\n                self.device_id = device_id\n            else:\n                self.device_id = None\n\n        except (OSError, ModuleNotFoundError):\n            raise SoundDeviceError\n        if audio_format not in [\"wav\", \"mp3\", \"webm\"]:\n            raise ValueError(f\"Unsupported audio format: {audio_format}\")\n        self.audio_format = audio_format\n\n    def callback(self, indata, frames, time, status):\n        \"\"\"This is called (from a separate thread) for each audio block.\"\"\"\n        import numpy as np\n\n        rms = np.sqrt(np.mean(indata**2))\n        self.max_rms = max(self.max_rms, rms)\n        self.min_rms = min(self.min_rms, rms)\n\n        rng = self.max_rms - self.min_rms\n        if rng > 0.001:\n            self.pct = (rms - self.min_rms) / rng\n        else:\n            self.pct = 0.5\n\n        self.q.put(indata.copy())\n","sourceCodeStart":56,"sourceCodeEnd":92,"githubUrl":"https://github.com/Aider-AI/aider/blob/5dc9490bb35f9729ef2c95d00a19ccd30c26339c/aider/voice.py#L56-L92","documentation":"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.","triggerScenarios":"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.","commonSituations":"Porting code that recorded to m4a/ogg on other platforms; passing a format constant from another library's enum; assuming case-insensitivity.","solutions":["Use exactly one of 'wav', 'mp3', or 'webm' (lowercase).","Normalize user input: lower().strip() and reject/convert unsupported formats before constructing Voice.","If you need m4a/ogg, record as 'webm' or 'wav' and convert externally after record_and_transcribe returns."],"exampleFix":"# before\nvoice = Voice(audio_format=\"m4a\")  # ValueError: Unsupported audio format\n\n# after\nfmt = \"m4a\".lower().strip()\nvoice = Voice(audio_format=fmt if fmt in {\"wav\", \"mp3\", \"webm\"} else \"wav\")","handlingStrategy":"type-guard","validationCode":"VALID_FORMATS = (\"wav\", \"mp3\", \"webm\")\n\ndef make_voice(audio_format):\n    fmt = str(audio_format).strip().lower()\n    if fmt not in VALID_FORMATS:\n        raise ValueError(f\"audio_format must be one of {VALID_FORMATS}; defaulting to wav\")\n    from aider.voice import Voice\n    return Voice(audio_format=fmt)","typeGuard":"def is_supported_audio_format(v) -> bool:\n    return isinstance(v, str) and v in (\"wav\", \"mp3\", \"webm\")","tryCatchPattern":null,"preventionTips":["Lowercase and membership-check user input before constructing Voice.","Convert other formats (m4a/ogg) to wav externally after recording rather than passing them in."],"tags":["audio","voice","validation","file-format","aider"],"backgroundTag":null,"analyzedSha":"5dc9490bb35f9729ef2c95d00a19ccd30c26339c","analyzedAt":"2026-08-15T05:40:10.498Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}