如何使用PyAudio或PortAudio获取设备的音频采样率列表?

mtr*_*trw 6 audio portaudio pyaudio

我想查询我的音频设备并获取所有可用的采样率.我在使用Python 2.6的Ubuntu机器上使用PyAudio 0.2,它运行在PortAudio v19之上.

Joh*_*man 5

在pyaudio分发中,test/system_info.py显示如何确定设备支持的采样率.请参阅从第49行开始部分.

简而言之,您使用的PyAudio.is_format_supported方法,例如


devinfo = p.get_device_info_by_index(1)  # Or whatever device you care about.
if p.is_format_supported(44100.0,  # Sample rate
                         input_device=devinfo['index'],
                         input_channels=devinfo['maxInputChannels'],
                         input_format=pyaudio.paInt16):
  print 'Yay!'