如何获取 pw-top 的静态(快照)?

如何获取 pw-top 的静态(快照)?

我需要从管道的 pw-top 获取静态输出,以用于我想要制作的脚本。我真的只需要一份管道设备列表。

例如,我希望能够运行pw-top | grep output然后做一些事情。基本上,我想获取管道设备及其 ID 的列表。

我想要的输出类型,仅适用于扬声器和耳机:

<device name> <id>
<device name> <id>
<device name> <id>

ETC

我尝试了以下方法:

[aggam@aggam-archlinux ~]$ pactl list cards | grep -E 'port.type|Name|Card'
Card #39
    Name: alsa_card.pci-0000_01_00.1
                port.type = "hdmi"
                port.type = "hdmi"
                port.type = "hdmi"
                port.type = "hdmi"
                port.type = "hdmi"
                port.type = "hdmi"
Card #40
    Name: alsa_card.usb-0c76_USB_PnP_Audio_Device-00
                port.type = "mic"
Card #41
    Name: alsa_card.pci-0000_00_1f.3
                port.type = "mic"
                port.type = "mic"
                port.type = "line"
                port.type = "line"
                port.type = "headphones"
                port.type = "spdif"

  1. 有些显示为扬声器和麦克风?我猜耳机都是...
  2. 这些是pulsaudio设备,我想避免出现问题,所以我想要它们的pipewire设备ID

编辑2:我的pw-top:

S   ID  QUANT   RATE    WAIT    BUSY   W/Q   B/Q  ERR FORMAT           NAME
S   28      0      0    ---     ---   ---   ---     0                  Dummy-Driver
S   29      0      0    ---     ---   ---   ---     0                  Freewheel-Driver
S   36      0      0    ---     ---   ---   ---     0                  Midi-Bridge
S   42      0      0    ---     ---   ---   ---     0                  alsa_output.pci-0000_01_00.1.hdmi-stereo-extra3
S   43      0      0    ---     ---   ---   ---     0                  alsa_input.usb-0c76_USB_PnP_Audio_Device-00.mono-fallback
S   44      0      0    ---     ---   ---   ---     0                  alsa_output.pci-0000_00_1f.3.analog-stereo
S   45      0      0    ---     ---   ---   ---     0                  alsa_input.pci-0000_00_1f.3.analog-stereo
S   71      0      0    ---     ---   ---   ---     0                  alsa_output.usb-KURZWEIL_MPS-Piano-00.analog-stereo
S   69      0      0    ---     ---   ---   ---     0                  alsa_input.usb-KURZWEIL_MPS-Piano-00.analog-stereo
I   67      0      0   0.0us   0.0us  0.00  0.00    0    F32LE 2 48000 Firefox

注意钢琴的输出是 71. 的输出pactl list short sinks

42  alsa_output.pci-0000_01_00.1.hdmi-stereo-extra3 PipeWire    s32le 2ch 48000Hz   SUSPENDED
44  alsa_output.pci-0000_00_1f.3.analog-stereo  PipeWire    s32le 2ch 48000Hz   SUSPENDED
401 alsa_output.usb-KURZWEIL_MPS-Piano-00.analog-stereo PipeWire    s16le 2ch 48000Hz   SUSPENDED

请注意钢琴突然变成了 401...

答案1

我想到了!我最终没有使用 shell 命令,而是制作了整个 python 脚本。该脚本获取所有设备,创建它们的字典,然后让您使用 dmenu/bemenu 选择您想要的设备。

该脚本可以在这里找到在我的 github 上,但这部分的代码是:

sp = subprocess.run(['wpctl', 'status'], stdout=subprocess.PIPE).stdout.decode('utf-8')\
        .split("Sinks")[1].split('├─')[0]
newsp = []

for line in sp.split('\n'):
    if '.' in line:
        newsp.append(line.replace(' ', '')[1:])

devices = {}  # name: id
for line in newsp:
    line = line.split('.')
    devices[line[1].split('[vol')[0]] = line[0].replace('*', '')

相关内容