gpt4 book ai didi

python - 在Linux上使用Python暂停和/或恢复音频

转载 作者:行者123 更新时间:2023-12-02 22:30:40 32 4
gpt4 key购买 nike

感谢您的关注!我想暂停和/或恢复使用pythont在后台播放的音频,这种方式使用pynput:

from pynput.keyboard import Controller, Key

c = Controller()
c.press(Key.media_play_pause)

但是音频仍在播放。似乎没有错误,但是没有用。

最佳答案

您可能想尝试使用playerctl,您可以将其用于命令行工具

subprocess.call(("playerctl", "play-pause"))

但是,playerctl可能未预先安装在系统上,因此您可能必须
  • sudo apt install playerctl
  • pacman -Syu playerctl
  • sudo dnf install playerctl
  • sudo zypper install playerctl

  • (取决于您的发行版)

    这不需要 pynput,但需要 subprocess( import subprocess)。如果您不在乎样式和安全性,那么您当然也可以使用 os.system("playerctl play-pause")

    关于python - 在Linux上使用Python暂停和/或恢复音频,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62120276/

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