我正在使用来自pyalsa的alsa网站模块。我可以设置音量,切换开关,但无法获得新的音量后,改变它的外部,例如,朋友。静音状态也是如此(get_switch,如果我没有错的话)。
怎么啦?我应该这样使用pyalsa吗?
from pyalsa import alsamixer
mixer = alsamixer.Mixer()
mixer.attach()
mixer.load()
alsa = alsamixer.Element(mixer, 'Master')
print(alsa.get_volume()) # shows e.g., 15729 (max 65536)
# run shell command `amixer set Master 50%`, the volume actually changes
print(alsa.get_volume()) # still shows 15729
alsa.set_volume_all(30000) # the volume also changes
print(alsa.get_volume()) # shows 30000编辑:我发现pyalsaaudio模块也是这样的。
发布于 2022-02-18 16:09:57
pyalsa不会自动处理等待混合器事件,必须使用Mixer.handle_events(...)
# change volume externally, e.g., with amixer command
mixer.handle_events()
alsa.get_volume() # returns the new valuehttps://stackoverflow.com/questions/71170159
复制相似问题