31

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.

1
  • What's your video card? Do you using any proprietary driver? May 4, 2016 at 23:58

8 Answers 8

33

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

pulseaudio --kill; pulseaudio --start
5
  • 1
    this doesn't work for me
    – Elliott
    Nov 10, 2017 at 12:59
  • 1
    This helped without the second start command already. I had to wait a couple of seconds and had to unmute the output. Jan 15, 2018 at 5:31
  • THIS FIRST COMMAND WORKS !!!! BOOM it is back! Oct 2, 2018 at 13:16
  • FWIW, I have been having this issue in ubuntu 18.04 and ubuntu 20.04 with XFCE, this command worked to solve the issue.
    – jhcaiced
    May 5, 2020 at 22:09
  • my case is HDMI audio was broken/freeze everytime my pc waked up from sleeping. pulseaudio --kill worked for me. Ubuntu 20.04.
    – le hien
    Apr 6, 2022 at 4:12
15

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.

1
  • 1
    I know this is pretty old but this disabled auto-switching when plugging in headphones on my system. Apr 20, 2019 at 22:53
12

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.

6
  • @PaulH. , @Toilal How did you edit the /etc/pulse/default.pa file? sudo gedit does not work for me.
    – Py-ser
    Dec 12, 2016 at 22:45
  • use gksu gedit /etc/pulse/default.pa
    – rubo77
    Apr 29, 2017 at 10:39
  • It was already commented out - SNIF! but the command .... pulseaudio --kill .....works well! Oct 2, 2018 at 13:37
  • This worked for me, thanks! Jul 22, 2021 at 0:50
  • The best answer. A permanent solution for this case.
    – cyfex
    Sep 23, 2022 at 2:17
3

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:

3

Fixing PulseAudio switching off HDMI sound on Suspend

This "undocumented feature" appeared with Ubuntu 16.04 and new version of PulseAudio 8.

Create a new file /lib/systemd/system-sleep/tv-sound and copy in:

#!/bin/sh

case $1/$2 in
  pre/*)
    echo "Going to $2..."
    # Place your pre suspend commands here, or `exit 0`
    # if no pre suspend action required
    sleep 1
    ;;
  post/*)
    echo "Waking up from $2..."
    # Place your post suspend (resume) commands here, or `exit 0` 
    # if no post suspend action required
    sleep 2
    export PULSE_RUNTIME_PATH="/run/user/1000/pulse/"
    sudo -u rick -E pacmd set-card-profile 0 output:hdmi-stereo
    ;;
esac

NOTE: replace user name rick (third line from the bottom) with your user name.

Then mark it executable with the command:

sudo chmod +x /lib/systemd/system-sleep/tv-sound

An additional step might be required if output:hdmi-stereo (the device for most people) is different on your system.

3
  • sorry, but this didn't fix it. Do I have to do more than this? restart anything? (I don't want to reboot, because that fixes the problem on my system anyway)
    – rubo77
    Apr 29, 2017 at 10:38
  • @rubo77 Did you change user ID rick to your own user ID? Apr 29, 2017 at 14:13
  • Sure. As you said 😃
    – rubo77
    Apr 29, 2017 at 16:19
2

Run:

$ pacmd list-cards

To display the index of your cards. For example, my pci sound card is at index 2. The sound profile for analogue output (again as an example) is called output:analog-stereo.

Then:

$ pacmd set-card-profile 2 output:analog-stereo

To set this as the output (give it a try). To make it permanent, edit /etc/pulse/default.pa and add:

set-card-profile 2  output:analog-stereo
set-default-sink 2

Restart pulseaudio or reboot to check persistence.

1
  • 3
    The HDMI audio was always persistant as default at reboot, it only changes to built in speakers after a resume from sleep. Doing what you say to do does not stop the hdmi changing to built in speakers after waking up. Is there a way to run the set-card-profile command when the system resumes from sleep?
    – MattJC
    Apr 26, 2016 at 18:09
1

Same happens for me but only if the HDMI monitor is not "awake" when OS starts or resumes: the list of devices in Settings > Sound doesn't even show HMDI/DisplayPort - Built-in Audio any more.

The fix for me is to suspend the session, ensure HDMI monitor is on, resume the session.

Suspend in Ubuntu 18.04 LTS is somewhat insanely hidden behind the PowerOff button in the drop down menu: hold mouse down on it, or press Alt to convert the PowerOff button into Suspend. Talk about hidden navigation!

2
  • +1, and thanks for describing how to find the hidden suspend! Some (who happen to have a terminal open perhaps) may prefer to run the command systemctl suspend instead!
    – Zanna
    May 10, 2018 at 9:43
  • Sorry folks, I have to vote against my own comment as it seems completely random: whether HDMI Audio appears in the sound devices list or not :(
    – mr0
    Jun 15, 2018 at 20:39
1

I have had this problem since Ubuntu 9.04. It never has worked and now that the children who just got HDMI or just got Ubuntu think the problem is something new so people trying to look at the latest changes in the setup are being misled. So let me make this clear: This problem has always been around and nobody is working on it. I've spent at least 20 hours researching this issue. So what I have done in the past:

  1. Reboot
  2. While turning on the TV (HDMI target) if I wiggle the mouse at just the right time it restores the sound maybe 50% of the time. This is a timing related/handshaking issue.
  3. In Ubuntu 14 I would change the screen resolution to something different then back again. This doesn't seem to work with Ubuntu 16
  4. Don't let it hibernate. An alternative is just do a timed shutdown. Later you just boot your computer rather than re-boot. Remember this is a TIMING issue, so I presume any of the ideas here can work if the timing happens to jog your system correctly.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .