-
-
Save papr/208eb04d7b73ef63607f8ff92c3a34ac to your computer and use it in GitHub Desktop.
Enumerate all Windows audio devices using python+ctypes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import ctypes.wintypes | |
import ctypes as C | |
_dsound_dll = C.windll.LoadLibrary("dsound.dll") | |
_DirectSoundEnumerateW = _dsound_dll.DirectSoundCaptureEnumerateW | |
_LPDSENUMCALLBACK = C.WINFUNCTYPE(C.wintypes.BOOL, | |
C.wintypes.LPVOID, | |
C.wintypes.LPCWSTR, | |
C.wintypes.LPCWSTR, | |
C.wintypes.LPCVOID) | |
_ole32_dll = C.oledll.ole32 | |
_StringFromGUID2 = _ole32_dll.StringFromGUID2 | |
def get_devices(): | |
devices = [] | |
def cb_enum(lpGUID, lpszDesc, lpszDrvName, _unused): | |
dev = "" | |
if lpGUID is not None: | |
buf = C.create_unicode_buffer(500) | |
if _StringFromGUID2(C.c_int64(lpGUID), C.byref(buf), 00): | |
dev = buf.value | |
devices.append((dev, lpszDesc, lpszDrvName)) | |
return True | |
_DirectSoundEnumerateW(_LPDSENUMCALLBACK(cb_enum), None) | |
return devices | |
if __name__ == '__main__': | |
for devid, desc, name in get_devices(): | |
print('%s: %s | %s' % (devid, desc, name)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment