import ctypes
from ctypes import *
from ctypes import wintypes
n=ctypes.windll.winmm.waveInGetNumDevs() #获取系统中存在的波形音频输入设备数
# 定义WAVEINCAPS结构体
class WAVEINCAPS(ctypes.Structure):
_fields_ = [
("wMid", wintypes.WORD), #制造商标识符
("wPid", wintypes.WORD), #产品标识符
("vDriverVersion", wintypes.DWORD), #设备驱动程序的版本号,高阶字节是主要版本号,低顺序字节是次要版本号
("szPname", wintypes.CHAR * 32), #制造商名称
("dwFormats", wintypes.DWORD), #支持的标准格式,可以是以下组合:
#看:https://learn.microsoft.com/zh-cn/windows/win32/api/mmeapi/ns-mmeapi-waveincaps
("wChannels", wintypes.WORD), #支持的声道数
("wReserved1", wintypes.WORD), #保留参数
]
for i in range(n):
caps = WAVEINCAPS()
mm=ctypes.windll.winmm.waveInGetDevCapsA(i, ctypes.byref(caps), ctypes.sizeof(caps)) #获取给定的波形音频输入设备的信息
'''
参数1:音频输入设备标识【设备ID】
参数2:caps是WAVEINCAPS结构对象--WAVEINCAPS结构的指针
参数3:WAVEINCAPS结构的大小(以字节为单位)
返回值:MMRESULT 函数执行的结果
MMSYSERR_NOERROR 表示执行成功
MMSYSERR_BADDEVICEID 索引越界
MMSYSERR_NODRIVER 没有就绪的设备
MMSYSERR_NOMEM 不能分配或者锁定内存
'''
print(f"Device {i}: {caps.szPname}")
'''
我的输出:Device 0: b'\xc2\xf3\xbf\xcb\xb7\xe7 (Realtek(R) Audio)'
'''
ctypes--音频
猜你喜欢
转载自blog.csdn.net/lm68140318/article/details/132461123
今日推荐
周排行