我想查询我的音频设备并获取其所有可用的采样率。我正在使用 Python 2.6 的 Ubuntu 机器上运行在 PortAudio v19 之上的 PyAudio 0.2。
问问题
14339 次
3 回答
7
在 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!'
于 2012-08-06T23:40:03.447 回答
4
使用sounddevice模块,您可以这样做:
import sounddevice as sd
samplerates = 32000, 44100, 48000, 96000, 128000
device = 0
supported_samplerates = []
for fs in samplerates:
try:
sd.check_output_settings(device=device, samplerate=fs)
except Exception as e:
print(fs, e)
else:
supported_samplerates.append(fs)
print(supported_samplerates)
当我尝试这个时,我得到了:
32000 Invalid sample rate
128000 Invalid sample rate
[44100, 48000, 96000]
您还可以检查是否支持特定数量的通道或特定数据类型。有关更多详细信息,请查看文档:check_output_settings()。您当然也可以使用check_input_settings()检查设备是否是受支持的输入设备。
如果您不知道设备 ID,请查看query_devices()。
我认为这仍然不相关,但这也适用于 Python 2.6,您只需从print
语句中删除括号并替换except Exception as e:
为except Exception, e:
.
于 2016-01-04T16:53:12.387 回答
0
直接使用 Portaudio,您可以运行以下命令:
for (int i = 0, end = Pa_GetDeviceCount(); i != end; ++i) {
PaDeviceInfo const* info = Pa_GetDeviceInfo(i);
if (!info) continue;
printf("%d: %s\n", i, info->name);
}
感谢另一个线程
于 2011-05-11T22:33:18.247 回答