Add a hack to fix pulseaudio default volume
Default volume, on first boot, in the greeter, matters a lot for
speech-synthesis installations.
On my test systems (KVM and VirtualBox, on Linux host), it defaults to
muted, and volume set to 6%. Couldn't figure out why. No idea how many
systems out there are impacted by such a bogus default.
Let's add a nasty workaround, we'll drop it when we switch to pipewire +
wireplumber by default.
Arnaud Rebillout
1 year, 3 months ago
0 | #!/bin/sh | |
1 | ||
2 | setup_pulseaudio() { | |
3 | # Only for lightdm or sddm. Actually what really matters is | |
4 | # whether pulseaudio is running. But let's err on the side | |
5 | # of being too restrictive. | |
6 | [ $(whoami) = lightdm ] || [ $(whoami) = sddm ] || return 0 | |
7 | # Only on first boot - either the pulseaudio cookie doesn't exist, | |
8 | # or it has just been created. | |
9 | if [ -e $HOME/.config/pulse/cookie ]; then | |
10 | if [ "$(( $(date +%s) - $(stat -c %Y $HOME/.config/pulse/cookie) ))" -gt 30 ]; then | |
11 | return 0 | |
12 | fi | |
13 | fi | |
14 | # Only if pactl (from pulseaudio-utils) is installed. | |
15 | [ -x /usr/bin/pactl ] || return 0 | |
16 | # | |
17 | # Make sure that pulseaudio is unmuted, and volume is higher than 25%. | |
18 | # | |
19 | #pactl get-sink-mute @DEFAULT_SINK@ | |
20 | #pactl get-sink-volume @DEFAULT_SINK@ | |
21 | muted=$(pactl get-sink-mute @DEFAULT_SINK@ | grep '^Mute:' | sed 's/^Mute: //') | |
22 | volume=$(pactl get-sink-volume @DEFAULT_SINK@ | grep -Po '\d+(?=%)' | head -n 1) | |
23 | if [ "$muted" = yes ]; then | |
24 | pactl set-sink-mute @DEFAULT_SINK@ false | |
25 | fi | |
26 | if [ "$volume" -lt 25 ]; then | |
27 | pactl set-sink-volume @DEFAULT_SINK@ 75% | |
28 | fi | |
29 | } | |
30 | ||
31 | # Workaround for the case when pulseaudio defaults to muted and volume close to | |
32 | # zero. Seen in VM (QEMU and VirtualBox) on a Linux host. Probably due to a bug | |
33 | # in PA or ALSA, but we handle it here, out of a better place. | |
34 | setup_pulseaudio |