Skip to content

Commit a7c3259

Browse files
committed
ASIO: retry decoding device name after UnicodeDecodeError
1 parent 4ae39d9 commit a7c3259

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

sounddevice.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -574,13 +574,15 @@ def query_devices(device=None, kind=None):
574574
# 'utf-8' or 'mbcs' encoding. Let's try 'utf-8' first, because it more
575575
# likely raises an exception on 'mbcs' data than vice versa, see also
576576
# https://github.com/spatialaudio/python-sounddevice/issues/72.
577-
# All other host APIs use 'utf-8' anyway.
578577
name = name_bytes.decode('utf-8')
579578
except UnicodeDecodeError:
580-
if info.hostApi in (
581-
_lib.Pa_HostApiTypeIdToHostApiIndex(_lib.paDirectSound),
582-
_lib.Pa_HostApiTypeIdToHostApiIndex(_lib.paMME)):
579+
api_idx = _lib.Pa_HostApiTypeIdToHostApiIndex
580+
if info.hostApi in (api_idx(_lib.paDirectSound), api_idx(_lib.paMME)):
583581
name = name_bytes.decode('mbcs')
582+
elif info.hostApi == api_idx(_lib.paASIO):
583+
# See https://github.com/spatialaudio/python-sounddevice/issues/490
584+
import locale
585+
name = name_bytes.decode(locale.getpreferredencoding())
584586
else:
585587
raise
586588
device_dict = {

0 commit comments

Comments
 (0)