Created
August 16, 2015 03:19
-
-
Save virtuald/bacc4bafabf267a0831e 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.DirectSoundEnumerateW | |
_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(200) | |
if _StringFromGUID2(lpGUID, C.byref(buf), 200): | |
dev = buf.value | |
devices.append((dev, lpszDesc)) | |
return True | |
_DirectSoundEnumerateW(_LPDSENUMCALLBACK(cb_enum), None) | |
return devices | |
if __name__ == '__main__': | |
for devid, desc in get_devices(): | |
print '%38s: %s' % (devid, desc) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment