如何获取使用PyAudio或PortAudio我的设备的音频采样率的名单? [英] How do I get a list of my device's audio sample rates using PyAudio or PortAudio?

查看:747
本文介绍了如何获取使用PyAudio或PortAudio我的设备的音频采样率的名单?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想我的查询音频设备,并得到所有可用的采样率。我使用PyAudio 0.2,运行于PortAudio V19之上,一个Ubuntu的机器上使用Python 2.6。

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.

推荐答案

在pyaudio分布,测试/ system_info.py 显示了如何确定设备支持的采样率。请参阅<一个href=\"http://people.csail.mit.edu/hubert/git/?p=pyaudio.git;a=blob;f=test/system_info.py;h=3c81432d7ffa3feaae06fa9804f41ffa03d4865d;hb=HEAD#l49\"相对=nofollow>开始于行49 部分。

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.

总之,使用 PyAudio.is_format_supported 的方法,例如

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

这篇关于如何获取使用PyAudio或PortAudio我的设备的音频采样率的名单?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆