Skip to content

Fix ALSA device matching for hw:CARD=...,DEV=... format - #224

Merged
balloob merged 2 commits into
mainfrom
fix/alsa-device-matching
Apr 15, 2026
Merged

Fix ALSA device matching for hw:CARD=...,DEV=... format#224
balloob merged 2 commits into
mainfrom
fix/alsa-device-matching

Conversation

@balloob

@balloob balloob commented Apr 14, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Catch ValueError (in addition to PortAudioError) from sounddevice.check_output_settings — PortAudio raises ValueError for hw:CARD=...,DEV=... names it doesn't recognize
  • Validate the device exists in the ALSA device list before accepting it with safe defaults
  • Add focused tests for _try_alsa_device

Simpler alternative to #218 — 6 lines changed in production code vs ~80.

Fixes #208

🤖 Generated with Claude Code

Catch ValueError (in addition to PortAudioError) from
sounddevice.check_output_settings, then validate against the
ALSA device list before accepting the device with safe defaults.

Fixes #208

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings April 14, 2026 12:28

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes ALSA device resolution for hw:CARD=...,DEV=...-style names by handling ValueError from sounddevice.check_output_settings, validating against the system ALSA device list, and adding targeted unit tests for _try_alsa_device.

Changes:

  • Treat ValueError from sounddevice.check_output_settings(device=...) as “PortAudio doesn’t recognize the name”, then validate existence via aplay -L output.
  • Accept ALSA-listed devices with safe default channel/sample-rate values when PortAudio cannot query details.
  • Add unit tests covering PortAudio-accepted devices, PortAudio errors, and ALSA-only / hw:CARD=...,DEV=... scenarios.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
sendspin/audio_devices.py Expands _try_alsa_device() to handle ValueError and gate acceptance on the ALSA device list.
tests/test_audio_devices.py Adds focused tests for _try_alsa_device() behavior across PortAudio/ALSA matching paths.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread tests/test_audio_devices.py
Comment thread tests/test_audio_devices.py
When check_output_settings raises ValueError, _try_alsa_device falls
through to query_devices which must also be patched to avoid hitting
the real PortAudio backend.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@balloob
balloob merged commit ccb2bfd into main Apr 15, 2026
1 check passed
@balloob
balloob deleted the fix/alsa-device-matching branch April 15, 2026 18:39
@balloob balloob added the bugfix Fixes a bug label Apr 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bugfix Fixes a bug

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ALSA devices: No output device matching

2 participants