File tree Expand file tree Collapse file tree 1 file changed +16
-3
lines changed Expand file tree Collapse file tree 1 file changed +16
-3
lines changed Original file line number Diff line number Diff line change @@ -723,10 +723,23 @@ def query_devices(device=None, kind=None):
723723 if not info :
724724 raise PortAudioError ('Error querying device {0}' .format (device ))
725725 assert info .structVersion == 2
726+ name_bytes = _ffi .string (info .name )
727+ try :
728+ # We don't know beforehand if DirectSound and MME device names use
729+ # 'utf-8' or 'mbcs' encoding. Let's try 'utf-8' first, because it more
730+ # likely raises an exception on 'mbcs' data than vice versa, see also
731+ # https://github.com/spatialaudio/python-sounddevice/issues/72.
732+ # All other host APIs use 'utf-8' anyway.
733+ name = name_bytes .decode ('utf-8' )
734+ except UnicodeDecodeError :
735+ if info .hostApi in (
736+ _lib .Pa_HostApiTypeIdToHostApiIndex (_lib .paDirectSound ),
737+ _lib .Pa_HostApiTypeIdToHostApiIndex (_lib .paMME )):
738+ name = name_bytes .decode ('mbcs' )
739+ else :
740+ raise
726741 device_dict = {
727- 'name' : _ffi .string (info .name ).decode ('mbcs' if info .hostApi in (
728- _lib .Pa_HostApiTypeIdToHostApiIndex (_lib .paDirectSound ),
729- _lib .Pa_HostApiTypeIdToHostApiIndex (_lib .paMME )) else 'utf-8' ),
742+ 'name' : name ,
730743 'hostapi' : info .hostApi ,
731744 'max_input_channels' : info .maxInputChannels ,
732745 'max_output_channels' : info .maxOutputChannels ,
You can’t perform that action at this time.
0 commit comments