Skip to content

Allow exact matches to include the hostapi's name in _get_device_id #360

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 4 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion sounddevice.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
import atexit as _atexit
import os as _os
import platform as _platform
import re as _re
import sys as _sys
from ctypes.util import find_library as _find_library
from _sounddevice import ffi as _ffi
Expand Down Expand Up @@ -2737,6 +2738,10 @@ def _check(err, msg=''):
raise PortAudioError(errormsg, err)


def _remove_alsa_id(device_string):
return _re.sub(r" \(hw:[0-9]+,[0-9]+\)$", "", device_string)


def _get_device_id(id_or_query_string, kind, raise_on_error=False):
"""Return device ID given space-separated substrings."""
assert kind in ('input', 'output', None)
Expand Down Expand Up @@ -2770,6 +2775,7 @@ def _get_device_id(id_or_query_string, kind, raise_on_error=False):
exact_device_matches = []
for id, device_string, hostapi_string in device_list:
full_string = device_string + ', ' + hostapi_string
device_string = _remove_alsa_id(device_string)
pos = 0
for substring in substrings:
pos = full_string.lower().find(substring, pos)
Expand All @@ -2778,7 +2784,10 @@ def _get_device_id(id_or_query_string, kind, raise_on_error=False):
pos += len(substring)
else:
matches.append((id, full_string))
if device_string.lower() == query_string:
if (
query_string[: len(device_string)].lower()
== device_string.lower()
):
exact_device_matches.append(id)

if kind is None:
Expand Down