{"record":{"id":"6dbb41eced3628a7","repo":"Aider-AI/aider","slug":"error-accessing-audio-input-device-err","errorCode":null,"errorMessage":"Error accessing audio input device: {err}","messagePattern":"Error accessing audio input device: (.+?)","errorType":"exception","errorClass":"SoundDeviceError","httpStatus":null,"severity":"error","filePath":"aider/voice.py","lineNumber":138,"sourceCode":"\n        try:\n            sample_rate = int(self.sd.query_devices(self.device_id, \"input\")[\"default_samplerate\"])\n        except (TypeError, ValueError):\n            sample_rate = 16000  # fallback to 16kHz if unable to query device\n        except self.sd.PortAudioError:\n            raise SoundDeviceError(\n                \"No audio input device detected. Please check your audio settings and try again.\"\n            )\n\n        self.start_time = time.time()\n\n        try:\n            with self.sd.InputStream(\n                samplerate=sample_rate, channels=1, callback=self.callback, device=self.device_id\n            ):\n                prompt(self.get_prompt, refresh_interval=0.1)\n        except self.sd.PortAudioError as err:\n            raise SoundDeviceError(f\"Error accessing audio input device: {err}\")\n\n        with sf.SoundFile(temp_wav, mode=\"x\", samplerate=sample_rate, channels=1) as file:\n            while not self.q.empty():\n                file.write(self.q.get())\n\n        use_audio_format = self.audio_format\n\n        # Check file size and offer to convert to mp3 if too large\n        file_size = os.path.getsize(temp_wav)\n        if file_size > 24.9 * 1024 * 1024 and self.audio_format == \"wav\":\n            print(\"\\nWarning: {temp_wav} is too large, switching to mp3 format.\")\n            use_audio_format = \"mp3\"\n\n        filename = temp_wav\n        if use_audio_format != \"wav\":\n            try:\n                new_filename = tempfile.mktemp(suffix=f\".{use_audio_format}\")\n                audio = AudioSegment.from_wav(temp_wav)","sourceCodeStart":120,"sourceCodeEnd":156,"githubUrl":"https://github.com/Aider-AI/aider/blob/5dc9490bb35f9729ef2c95d00a19ccd30c26339c/aider/voice.py#L120-L156","documentation":"The second audio failure point in raw_record_and_transcribe: after the sample-rate query succeeds, opening sd.InputStream for the selected device raised sounddevice.PortAudioError, re-raised as SoundDeviceError with the underlying PortAudio message appended ('Error accessing audio input device: {err}'). Unlike error 51, the device enumerated but the stream could not be opened — typically the device is busy, has zero input channels despite listing, or sample-rate mismatch.","triggerScenarios":"Opening the input stream with device=self.device_id when another app holds the mic exclusively (Zoom/Meet/browser), the queried default_samplerate is unsupported by the device, or the device disappeared between enumeration and stream open (USB unplugged).","commonSituations":"Conference call holding the microphone when aider voice is invoked; USB mic unplugged mid-flow; devices whose advertised default_samplerate is rejected by PortAudio on open; macOS mic permission not granted to the terminal app.","solutions":["Read the appended PortAudio text — 'Device unavailable' means busy (close other apps using the mic), 'Invalid sample rate' means rate mismatch.","Close other applications capturing the mic (browser tabs, conferencing apps) and retry.","Grant microphone permission to your terminal/IDE (macOS System Settings > Privacy & Security > Microphone).","Reconnect/reselect the USB device or pass an explicit working device_name to Voice()."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"import sounddevice as sd\n\ndef can_open_input(device=None) -> bool:\n    try:\n        with sd.InputStream(device=device, channels=1, samplerate=16000):\n            return True\n    except Exception:\n        return False","typeGuard":null,"tryCatchPattern":"from aider.voice import SoundDeviceError, Voice\ntry:\n    text = Voice(device_name=dev).record_and_transcribe()\nexcept SoundDeviceError as e:\n    if \"Error accessing audio input device\" in str(e):\n        # underlying PortAudio text is appended: busy vs rate vs permission\n        print(f\"Mic unavailable: {e}\")\n        text = input(\"Type instead: \")\n    else:\n        raise","preventionTips":["Close other apps holding the mic (conferencing clients, browser tabs) before invoking voice.","Grant terminal apps microphone permission on macOS.","Dry-run open an InputStream with your target samplerate at startup to fail fast."],"tags":["audio","voice","portaudio","device-busy","permissions","aider"],"backgroundTag":null,"analyzedSha":"5dc9490bb35f9729ef2c95d00a19ccd30c26339c","analyzedAt":"2026-08-15T05:40:10.498Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}