Xfce Forum

Sub domains

You are not logged in.

#1 2017-05-05 13:51:34

Registered: 2017-05-05
Posts: 4

How to play a sound when a "XF86AudioVolume" key is pressed

Hi there,

Like the title say, I'd like to have some sound played (like a "pop") when I change the volume with the keyboard.

First thing first!
Here what I've done so far:
In Appearance settings the system sound is enable (both)
In pavucontrol system sound volume is at 100%
I've set the GTK_MODULES environment variable with canberra-gtk-module (in /etc/X11/Xsession.d)
I've set in xsettings>net>SoundThemeName => freedesktop
In /usr/share/sounds/freedesktop/ there is a audio-volume-change.ogg file among many other ogg files.

After all that, I've get few sounds when a window is maximized and minimized etc... but all I'm looking for is a sound when I change the volume... and nothing.

If I've understand things wright, The "problem" seems to come from libcanberra, Which do not implement audio-volume-change.
But is there any other way to get what I want??

PS: In Gnome, that I was using before moving to xfce, the sound was playing when I pressed XF86AudioRaiseVolume or XF86AudioLowerVolume.



#2 2017-05-05 14:19:03

Registered: 2017-05-05
Posts: 4

Re: How to play a sound when a "XF86AudioVolume" key is pressed

Ok I've found a way but dunno if it is a "nice way" of doing it.
I've created 2 scripts almost equivalent, one for VolumeRaise and the other for VolumeLower (code below)

pactl set-sink-volume 0 -5%
paplay /usr/share/sounds/freedesktop/stereo/audio-volume-change.ogg

In keyboard settings, I've just added theses scripts with the correspondent key.

So now I've got the sound + notification + panel icon when I press  XF86AudioRaiseVolume or XF86AudioLowerVolume

Does anybody came across a problem like this one, and how did you get it done?


I've made a change in the audio-volume-up.sh script. I stop it from being able to raise volume more than 180%.
Careful: volume is language dependent, it should work for English and French.



vol=$(pacmd list-sinks | awk '/volume: f/ {gsub(/\%/,"",$5);print $5}')

if [ "$vol" -ge "$max" ]; then
	paplay /usr/share/sounds/freedesktop/stereo/audio-volume-change.ogg
	pactl set-sink-volume 0 +5%
	paplay /usr/share/sounds/freedesktop/stereo/audio-volume-change.ogg

Last edited by moooartin (2017-05-05 15:32:07)


#3 2017-05-05 17:19:59

From: Canada
Registered: 2011-06-02
Posts: 4,372

Re: How to play a sound when a "XF86AudioVolume" key is pressed

You are correct in that the libcanberra implementation doesn't implement the volume-change event so you won't be able to use that. And Xfce doesn't have any sort of internal mechanism to do this. The script that you've created seems to be a good implementation of this functionality. Thanks for sharing!

BTW, welcome to the forums.

How To Ask For Help           Xfce FAQ                            Xfce Release Information
The Xfce Community          Xfce Tips and Tricks


Board footer

Powered by FluxBB