Ubuntu – Set default pulseaudio volume


When I reboot, the volume on the PulseAudio sinks is set to 100%. I know how to change the volume using pactl set-sink-volume, but that is only set temporarily. I could write a script that is run at startup, but it will not be applied if I connect a sink later. (i.e. a Bluetooth speaker)

Is there a config file where I can set the default volume that is given to a device when it is first loaded by PulseAudio? Or even the master volume at startup?

Clarification: The application is for a headless linux box, so the system shouldn't have to be rebooted and should be able to accept new devices without having to connect via ssh to adjust volumes, etc.

Best Answer

With PulseAudio 8.0 on Ubuntu 16.04 and a single sound card, you can set the default master volume to 50% with the following file. By including the system default you don't have to worry about changes in the distribution's defaults.

$ cat ~/.config/pulse/default.pa
.include /etc/pulse/default.pa

# Set volume to 50% on boot
set-sink-volume 0 32768

If you have multiple cards, replace the index number with the name since order is not guaranteed. In addition, if you want to adjust the volume determine the "base volume" which represents the max and calculate the equivalent percentage.

$ pacmd list-sinks | grep -e "name:" -e "index:" -e "base volume:"
  * index: 0
    name: <alsa_output.card0>
    base volume: 65536 / 100% / 0.00 dB
  * index: 1
    name: <alsa_output.card1>
    base volume: 32768 / 100% / 0.00 dB

For example, to specify the default volume of 70% for card1 the line would become:

set-sink-volume alsa_output.card1 22937
Related Question