My speakers are plugged via optical output. Each time my screen wake up from sleep, pusleaudio automatically switch to HDMI audio where nothing is plugged.

How can I prevent that ?

  • The Real Question is "why is this the default behaviour?" How is it good?, that everytime you want to listen to something you have to change the configuration. Just pure bad dev. Thank you for asking this question, because the answer was spot on. Commented Sep 1, 2022 at 12:54

3 Answers 3


Let me know if this doesn't work for you and I'll delete my answer. I don't have your speaker system but this should work.

Disable automatic device switching

When signal is lost to during sleep, Pulse Audio is automatically configured to activate the default source (your HDMI). Upon resume the sound device is still on HDMI. To override this setting, tell Pulse Audio to never switch sound devices automatically:

  • edit the file /etc/pulse/default.pa
  • find the line load-module module-switch-on-port-available
  • insert a # at the beginning of the line to disable automatic port switching
  • save file and exit editor
  • type pulseaudio -k to reload configuration
  • Works like a charm, thanks. Just for the note I restarted pulse without rebooting using 'pulseaudio -k' . Commented Aug 2, 2018 at 19:31
  • @VincentTschanz Thank you for your comment. I've updated the answer with it. Commented Nov 4, 2018 at 13:53
  • This is problematic since it disable automatic speaker / headphone toggling :/ Commented Nov 3, 2019 at 21:46
  • @PetterSundlöf Yes you would have to switch output devices manually. It's the lesser of two evils. Commented Nov 4, 2019 at 0:11
  • I wonder if you could have a look at this related question of mine, on Unix.SX.
    – einpoklum
    Commented Feb 26, 2021 at 18:45

WinEunuuchs2Unix's post is correct, but I had to adjust module-switch-on-connect instead of module-switch-on-port-available. Here's an easy one-liner:

sudo sed -i 's/^load-module module-switch-on-connect$/# load-module module-switch-on-connect/g' /etc/pulse/default.pa && pulseaudio -k
  • By keeping switch-on-port-available and disabling swith-on-connect I finally managed what I want: automatic switching between speakers/headphones, but ignoring my docking station. Thank you! This has been bugging me for about a year now.
    – Sebastiaan
    Commented Feb 23, 2021 at 9:31
  • @Sebastiaan What's the exact difference between on-port-available and on-connect?
    – einpoklum
    Commented Feb 26, 2021 at 18:45
  • 1
    on-connect is the event that a new device is connected which has an audio port, such as a usb dock. on-port-available is the event that a port becomes usable, for example when you insert a mini jack.
    – Sebastiaan
    Commented Feb 26, 2021 at 20:59

By the way just related I had the same problem. There seem to be a bug report up on Launchpad https://bugs.launchpad.net/ubuntu/+source/pulseaudio/+bug/1847570

  • That bug report is for Ubuntu 19.10 released October 2019. This question is from August 2018. Commented Nov 18, 2019 at 3:06

You must log in to answer this question.

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