How do I get a list of my device's audio sample rates using PyAudio or PortAudio?

后端 未结 3 1801
忘了有多久
忘了有多久 2020-12-19 06:46

I\'d like to query my audio device and get all its available sample rates. I\'m using PyAudio 0.2, which runs on top of PortAudio v19, on an Ubuntu machine with Python 2.6.

3条回答
  •  清歌不尽
    2020-12-19 07:04

    In the pyaudio distribution, test/system_info.py shows how to determine supported sample rates for devices. See the section that starts at line 49.

    In short, you use the PyAudio.is_format_supported method, e.g.

    
    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!'
    

提交回复
热议问题