You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Mac外接TI PCM2900C声卡PyAudio报-9998通道错误求助

问题:外接立体声声卡(TI PCM2900C)无法通过PyAudio进行输入捕获
  • 内置麦克风(设备2)和外接麦克风(设备1)可正常通过PyAudio捕获音频,但外接立体声声卡(设备0:USB AUDIO CODEC)始终触发错误
  • 尝试调整通道数(1/2)、采样率均无法解决问题
  • 通过PyAudio查询设备0的maxInputChannels返回0,与设备标称的立体声CODEC输入能力不符

测试代码

打开输入流的代码:

p = pyaudio.PyAudio()

# Open the selected audio input device
stream = p.open(
    format=pyaudio.paInt16,
    channels=2,
    rate=48000,
    input=True,
    input_device_index=0,
    frames_per_buffer=1024)

查询设备通道数的代码:

# Get the number of channels that the selected device supports
device_channels = p.get_device_info_by_host_api_device_index(0, device_index).get('maxInputChannels')
print('Input device channels is ', device_channels)

解决建议

  1. 系统层面确认设备输入状态

    • 打开macOS「声音」偏好设置,切换到「输入」标签,查看是否存在「USB AUDIO CODEC」设备。如果没有,说明系统未识别该设备的输入功能:
      • 检查设备连接:确认USB线插好,尝试更换USB端口
      • 确认设备模式:TI PCM2900C可能需要切换到输入模式(部分设备有物理开关或软件设置)
  2. 遍历所有主机API检查设备信息
    PyAudio默认使用主机API索引0(macOS下为Core Audio),但设备可能在其他API下有不同的识别结果,运行以下代码排查:

    p = pyaudio.PyAudio()
    for api_idx in range(p.get_host_api_count()):
        api_info = p.get_host_api_info_by_index(api_idx)
        print(f"主机API {api_idx}: {api_info['name']}")
        for dev_idx in range(api_info['deviceCount']):
            dev_info = p.get_device_info_by_host_api_device_index(api_idx, dev_idx)
            if dev_info['name'] == 'USB AUDIO  CODEC':
                print(f"  设备{dev_idx}: 最大输入通道数={dev_info['maxInputChannels']}")
    
  3. 更换音频库测试
    试试sounddevice库(基于PortAudio,与PyAudio同底层),可能有更好的设备兼容性:

    import sounddevice as sd
    # 打印所有设备信息
    print(sd.query_devices())
    # 尝试打开设备0的输入流
    try:
        with sd.InputStream(device=0, channels=2, samplerate=48000):
            print("输入流打开成功")
    except Exception as e:
        print(f"错误信息: {e}")
    
  4. 重置系统音频服务
    macOS下可以重启Core Audio服务,解决部分设备识别问题:

    sudo killall coreaudiod
    

内容的提问来源于stack exchange,提问作者Steven Sesselmann

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.06 03:35:24