You are not logged in.

#1 2019-01-25 20:03:45

Wild Penguin
Member
Registered: 2015-03-19
Posts: 406

[SOLVED] Moving pulseaudio sink-inputs, or parsing pactl/pacmd output

Hi,

I'm trying to make a single script which will preferentially move a certain applications (Clementine) sink-input to a certain sink. My goal is to make a kind of multi-room audio setup controllable with an android phone/tablet (with the help of module-native-protocol-tcp and, say, KDE Connect).

The stream can be moved simply with a command:

pactl move-sink-input N T

Where "N" is the sink-input to be moved and "T" is the sink, and works fine when done manually.

But the problem is, these numbers will change, and the names (which even can not be used for the sink-input AFAIK) are not at all useful for parsing the sink-inputs:

$ pactl list short sink-inputs
287     1       63      protocol-native.c       float32le 2 kan. 48000Hz
304     1       105     protocol-native.c       float32le 2 kan. 44100Hz


The full output has the relevant informataion, but the output is not that easy to parse (pacmd/pactl can give this exact same output):

Sink Input #304
        Driver: protocol-native.c
        Owner Module: 13
        Client: 105
        Sink: 1
        Sample Specification: float32le 2 kan. 44100Hz
        Channel Map: front-left,front-right
        Format: pcm, format.sample_format = "\"float32le\""  format.channels = "2"  format.rate = "44100"  format.channel_map = "\"front-left,front-right\""
        Corked: no
        Mute: no
        Volume: front-left: 49152 /  75% / -7,50 dB,   front-right: 49152 /  75% / -7,50 dB
                balance 0,00
        Buffer Latency: 105374 usec
        Sink Latency: 18205 usec
        Resample method: copy
        Properties:
                media.name = "”XIII” artistilta ”Tomasz Stanko Quartet”"
                application.name = "Clementine"
                native-protocol.peer = "UNIX socket client"
                native-protocol.version = "32"
                media.role = "music"
                application.process.id = "1474"
                application.process.user = "****"
                application.process.host = "*********"
                application.process.binary = "clementine"
                application.language = "fi_FI.UTF-8"
                window.x11.display = ":0"
                application.process.machine_id = "c6dad35a9b1e4962972d0e178e26a64e"
                application.process.session_id = "1"
                application.icon_name = "clementine"
                module-stream-restore.id = "sink-input-by-media-role:music"
                media.title = "XIII"
                media.artist = "Tomasz Stanko Quartet"

Of course I could just move all inputs to the wanted sink, but that is unnecessary, as I would like to move only one application (EDIT: but would make the parsing more simple, and work as a "just hack it" -solution ... but also is kind of more error prone, and may cause unnecessary resampling etc.).

Has anyone made a script to parse pactl (pacmd) output?

Alternatively, any other possible solutions to achieve this are welcome!

The limitation here is that there is another KODI box, which I want to occasionally use as just an audio output (in a headless mode). This would also seem very future proof, as it is easy to add module-native-protocol-tcp into any device running in a home network, and the found sinks will be automatically named in a usable way.

EDIT: Marking as solved as the script linked below indeed works fine, after minor edits to reflect my setup. Thanks @quequotion !

Last edited by Wild Penguin (2019-01-26 19:05:45)

Offline

#2 2019-01-25 20:20:59

Wild Penguin
Member
Registered: 2015-03-19
Posts: 406

Re: [SOLVED] Moving pulseaudio sink-inputs, or parsing pactl/pacmd output

Ok,

with another search found this post with a nice script snippet: https://bbs.archlinux.org/viewtopic.php … 7#p1693617

The script seems to work (by obviously editing it to my needs).

Offline

Board footer

Powered by FluxBB