gpt4 book ai didi

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

转载 作者:塔克拉玛干 更新时间:2023-11-03 00:44:13 27 4
gpt4 key购买 nike

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

最佳答案

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

import alsaaudio   #alternative method pure python
for device_number, card_name in enumerate(alsaaudio.cards()):
print device_number, card_name

我最终将 pacmdcat 选项添加到命令行,检索并解析结果以发现什么是什么。
示例:

    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 一样,但当魔鬼开车时必须这样做

关于python - 通过 Python 选择要播放的音频设备,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39147723/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com