Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 206
mtrw Avatar asked Jan 07 '11 07:01

mtrw


1 Answers

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!'
like image 165
John Wiseman Avatar answered Oct 01 '22 18:10

John Wiseman