Ubuntu changes sound device after suspend, how to fix?

So my setup currently is using a monitor plugged into my laptop via HDMI and using the speakers in that for audio not the inbuilt laptop ones. When the machine boots it uses HDMI by default, but I will often suspend the laptop throughout the day and whenever it resumes it switches the sound device to the inbuilt speakers.

It's not a big problem as you can imagine but is annoying, I wonder if there's a script I could use to force it to reselect HDMI after resume or disable the inbuilt speakers, or set as default some how. FYI both the inbuilt speakers are on the same 'sound card' but are two different devices. I use Ubuntu 16.04.


Solution 1:

If you don't want to reboot, simply restart pulseaudio:

pulseaudio --kill; pulseaudio --start

Solution 2:

I had the same problem on Ubuntu 17.10. After suspend, or even after dimming the Display, it would always change my audio output from Digital Output (desired) to HDMI even though my Display does not have any speakers. Commenting out the line

load-module module-switch-on-port-available

in /etc/pulse/default.pa did the trick as described in Disable sound through HDMI permanently.

Note that setting default sinks as pointed out above did not change the behavior. Also, the script provided above to set the audio card profile after suspend is user-specific.

Solution 3:

This issue may be related to a problem with Pulseaudio, version 8, as outlined in this (long) bug thread on freedesktop.org.

Basically, Pulseaudio reroutes the sound when it loses contact with HDMI and doesn't return it after HDMI is reconnected. It is fixed in version 9.

In order to return version 8 to the behavior of previous versions, follow these directions and reboot.

edit /etc/pulse/default.pa to comment out (add # to the start of) the line:

#load-module module-switch-on-port-available

Then set the sound output in Sound Settings and check that it persists by suspend/resume or blanking the screen. It did work for me.

Solution 4:

I fixed this issue by setting fixed pulse profile to output:hdmi-stereo on resume.

To get a list of pulse profiles: pacmd list-cards. To change pulse profile e.g.: pacmd set-card-profile 0 output:hdmi-stereo.

About running script after suspend: Run Script on Wakeup?

About running pacmd as root: [Solved] Control pulseaudio with shell script via pacmd / Newbie Corner / Arch Linux Forums: