我正在尝试确定声卡是否支持格式(速率/深度)。我发现无论指定的速率和深度如何,pyaudio 都会返回 True。如何仅显示声卡本机支持的模式?我已经在 windows、mac、ubuntu、fedora 上复制了这个。我已经包含了一个有效的代码片段来帮助解决这个问题。
import pyaudio
pa = pyaudio.PyAudio()
try:
default_device_id = pa.get_default_output_device_info()['index']
except IOError:
print ("There is no default device")
exit(1)
try:
result = pa.is_format_supported(rate=48000, output_device=default_device_id, output_channels=2, output_format = pyaudio.paFloat32)
print("Unexpected, device does not really support this result was: %s" % result)
except ValueError:
print("Expected Unsupported Device")