通过Python选择要播放的音频设备

通过Python选择要播放的音频设备,python,linux,python-3.x,audio,Python,Linux,Python 3.x,Audio,如何在linux中获取音频设备列表(如aplay-L)并选择音频设备作为输出?是否有要导入的LIB?它们已经进口了吗 我到处寻找你写均衡器时的要求,但从未找到满意的答案。 有一个alsaaudio库可用: import alsaaudio #alternative method pure python for device_number, card_name in enumerate(alsaaudio.cards()): print device_number, card_name

如何在linux中获取音频设备列表(如
aplay-L
)并选择音频设备作为输出?是否有要导入的LIB?它们已经进口了吗

我到处寻找你写均衡器时的要求,但从未找到满意的答案。
有一个alsaaudio库可用:

import alsaaudio   #alternative method pure python
for device_number, card_name in enumerate(alsaaudio.cards()):
    print device_number, card_name
最后,我在命令行上敲打了
pacmd
cat
选项,检索并解析结果以发现是什么。
示例:

    sink_list = os.popen('cat /proc/asound/cards | grep "\[" | cut -c2').readlines()
    for s in sink_list:
        s = s.strip()
        self.sinks_available.append("hw:"+s)
对于pulseaudio,您需要
pacmd

# Identify the default sound card device
    sink = os.popen('pacmd list | grep "device.master_device" | cut --delimiter== -f2').readline()
    if sink =="":
        sink = os.popen('pacmd list-cards | grep -C1 sinks | grep pci | cut --delimiter=/ -f1').readline()
这一切都是最不令人满意的,也不像python,但在魔鬼驾驶时必须如此