You are not logged in.

#1 2018-08-29 04:48:06

doubleslash
Member
Registered: 2011-08-16
Posts: 80

[SOLVED]How to find the audio sink that is being used?

Hello,
I have a bluetooth speaker and speakers built into my laptop. I can use pavucontrol to select which sink is to be used for playback. Now, I'd like to make keybindings to control the volume through pactl like

 pactl set-sink-volume 0 -5%

in which 0 is the index of the sink. For my set up, the index is either 0 or 1 depending on which speaker is being used. I'd like the keybinding to succesfully change the volume of whichever speaker that happens to be in use. Therefore, before I use the pactl command above, I need to find the index of the active speaker. What command can do that for me?
Thanks

Last edited by doubleslash (2018-08-29 21:27:44)

Offline

#2 2018-08-29 07:37:37

V1del
Forum Moderator
Registered: 2012-10-16
Posts: 21,626

Re: [SOLVED]How to find the audio sink that is being used?

use pacmd list-sinks to find the sink that is actively running and use that one's index. Or alternatively, which might be a bit more robust, use sink names instead of indices, they shouldn't change. Not on my Arch so I can't give you a direct extraction example, but that should be doable.

Or if you set the bluetooth to be the 'default' device you can use the pseudo sink @DEFAULT_SINK@ which will always resolve to the configured default sink. You could also combine that with e.g. load-module module-switch-on-connect in your /etc/pulse/default.pa (if you intend to use that, place that line before the if.. udev device detection block) which will switch all running applications to the bluetooth speaker, set the bluetoth speaker as default sink and revert all of that on disconnect.

Offline

#3 2018-08-29 21:27:07

doubleslash
Member
Registered: 2011-08-16
Posts: 80

Re: [SOLVED]How to find the audio sink that is being used?

Thanks for your advice. I wrote the following python code to implement the idea

from subprocess import PIPE, Popen 
activesink = 'pactl list sinks short | awk \'{print $1,$7}\''
process = Popen(activesink, shell=True, stdin=PIPE, stdout=PIPE, stderr=PIPE)
stdout, stderr = process.communicate()
res = stdout.splitlines()
#res is an array like  [b'0' 'SUSPENDED',b'4' 'RUNNING']

Offline

Board footer

Powered by FluxBB