Automatic switching of sound to HDMI

I would like the sound and the image from the TV to switch automatically after connecting the HDMI. Currently, after connecting, for example, a TV via the HDMI port, there is basically no problem with the image. The sound must be manually switched in the “Sound” applet.

Has anyone tried this or other solutions? Do you have any suggestions for solving this problem?

I am a Linux beginner so please give me a detailed explanation.

Hi, first please connect your HDMI and run wpctl status from terminal. Then find part something as bellow:

Audio
 ├─ Devices:
 │      40. Built-in Audio                      [alsa]
 │      41. Built-in Audio                      [alsa]
 │  
 ├─ Sinks:
 │      44. Built-in Audio Digital Stereo (HDMI) [vol: 0.74]
 │    * 45. Built-in Audio Analog Stereo        [vol: 0.72]

You can see above on part Sinks there will presented with your current cards. Take a note of your HDMI ID number. From above example, the ID are 44.

Then run wpctl set-default 44. It will make your HDMI connection as default card and your other card as fallback if the HDMI connection not present.

To check, run again wpctl status and make sure the * sign already move to HDMI card.

3df1cdc798633e96da01cae7463abdc47175d245.png

wpctl status command does not see connected HDMI

When working with issues in fedora the first step should always be to do a full system update in case you have not already received a fix that may affect your issue. Please do sudo dnf upgrade then reboot and try again so you can tell if it has already been solved for you with a software update.

It may also be related to the HDMI cable in use. Some earlier and less expensive cables are designed to only carry the minimum data for video and do not support audio, and the system will not configure the hdmi audio device if it does not see the sink (in your case the TV) audio device at the other end. The fix for that is to try a different hdmi cable and possibly purchase a new & better cable.

If I change it manually or via pavucontrol, it works. It does not work automatically while the cable is connected.

pactl list sinks
43. odpływ
	Stan: RUNNING
	Nazwa: alsa_output.pci-0000_00_1b.0.hdmi-stereo
	Opis: Built-in Audio Cyfrowe stereo (HDMI)
	Sterownik: PipeWire
	Określenie próbki: s32le 2 k 48000 Hz
	Mapa kanałów: front-left,front-right
	Właściciel modułu: 4294967295
	Wyciszenie: nie
	Poziom głośności: front-left: 65536 / 100% / 0,00 dB,   front-right: 65536 / 100% / 0,00 dB
	                  balans 0,00
	Głośność podstawowa: 65536 / 100% / 0,00 dB
	Źródło monitora: alsa_output.pci-0000_00_1b.0.hdmi-stereo.monitor
	Opóźnienie: 0 us, skonfigurowano 0 us
	Flagi: HARDWARE DECIBEL_VOLUME LATENCY SET_FORMATS 
	Właściwości:
		alsa.card = "0"
		alsa.card_name = "HDA Intel PCH"
		alsa.class = "generic"
		alsa.device = "3"
		alsa.driver_name = "snd_hda_intel"
		alsa.id = "HDMI 0"
		alsa.long_card_name = "HDA Intel PCH at 0xd3710000 irq 31"
		alsa.name = "HDMI 0"
		alsa.resolution_bits = "16"
		alsa.subclass = "generic-mix"
		alsa.subdevice = "0"
		alsa.subdevice_name = "subdevice #0"
		api.alsa.card.longname = "HDA Intel PCH at 0xd3710000 irq 31"
		api.alsa.card.name = "HDA Intel PCH"
		api.alsa.path = "hdmi:0"
		api.alsa.pcm.card = "0"
		api.alsa.pcm.stream = "playback"
		audio.channels = "2"
		audio.position = "FL,FR"
		card.profile.device = "7"
		device.api = "alsa"
		device.class = "sound"
		device.id = "40"
		device.profile.description = "Cyfrowe stereo (HDMI)"
		device.profile.name = "hdmi-stereo"
		device.routes = "1"
		factory.name = "api.alsa.pcm.sink"
		media.class = "Audio/Sink"
		device.description = "Built-in Audio Cyfrowe stereo (HDMI)"
		node.name = "alsa_output.pci-0000_00_1b.0.hdmi-stereo"
		node.nick = "HDA Intel PCH"
		node.pause-on-idle = "false"
		object.path = "alsa:pcm:0:hdmi:0:playback"
		priority.driver = "696"
		priority.session = "696"
		factory.id = "18"
		client.id = "32"
		node.driver = "true"
		factory.mode = "merge"
		audio.adapt.follower = ""
		library.name = "audioconvert/libspa-audioconvert"
		object.id = "43"
		node.max-latency = "8192/48000"
	Porty:
		hdmi-output-0: HDMI/DisplayPort (typ: HDMI, priorytet: 5900, grupa dostępności: Legacy 5, niedostępne)
	Aktywny port: hdmi-output-0
	Formaty:
		pcm

:thinking: May be you want to run following commands:

# Connect your HDMI cable and select the output audio manually to this connection.
# Please make sure the audio already played from the HDMI.

# Move any contents inside `~/.local/state/wireplumber` to other place as backup.
mv ~/.local/state/wireplumber ~/to/backup/folder

# This command will  reinitialize your ALSA profile.
alsactl init

# Restart  pipewire and wireplumber
systemctl --user restart pipewire
systemctl --user restart wireplumber

# Check again with `wpctl status`.
wpctl status

# If you can find the sinks to HDMI, change the default to HDMI with `wpctl set-default ID` above.
1 Like

Assuming you’re using gnome:
On pavucontrol on the output devices tab make sure your hdmi output is set to be the fallback device.
It is the box on the far right of the screen on the line with the audio devices name in it with a check icon.
Mine looks something like:

You can also install: gnome-shell-extension-sound-output-device-chooser
You will still have to switch, but you should be able to do it with out opening additional applications. Left click on the (network/sound/power icon on the right) and you should be able to change it from there.

If that doesn’t work for you can start looking at doing something with udev and a script to automatically swap it or you can use a manual command to toggle or set it to what you want.

2 Likes