RaspOS Lite (Bookworm):  HDMI Audio on RPI4

*** Ghadzooks!   I just tried this again and it didn't work!   Nevermind the fixes on this page until I figure out whats going on ... recently, when/if  I don't see hdmi listed as an option in raspi-conf, I simply install pulseaudio-utils and do a "pactl list sinks".  Seems to work on latest RaspOS Lite. ***

Fix for a recent Raspberry Pi Struggle:  Getting HDMI audio working on latest version of RaspOS Lite (64-bit Bookworm).

BackgroundRecently installed a software suite (OVOS) that included pipewire for audio processing.  Twas a struggle getting HDMI audio to work on a Raspberry Pi 4 because RaspOS Lite only seemed to offer the 3.5mm (bcm2835) audio device in rasp-config, alsa, etc.   Likely also a problem on previous generations of RPI's w/ HDMI *and* Headphone jacks using Bookworm/RaspOS Lite 64-bit/Pipewire.   Have not tested RaspOS Lite 32-bit but something is not right here on 64-bit Lite! 

Fix:  After a lot of fumbling and searching here's the quick tweak that worked for me ...
(Hack warning:  There may be a better/right way to do this!  I am a very inexperienced pipewire plumber!)

The following tweak was preformed after OVOS (and Pipewire) were installed - it assumes pipewire is installed.  

object.path = "alsa:pcm:2:hdmi:2:playback"

factory.id = "18"

client.id = "34"
device.id = "58"

priority.session = "1000"
priority.driver = "1000"
node.description = "Built-in Audio Digital Stereo (HDMI)"

node.name = "alsa_output.platform-fef00700.hdmi.hdmi-stereo"
node.nick = "MAI PCM i2s-hifi-0"

media.class = "Audio/Sink"


File should now look something like this:

[Unit]

Description=PipeWire Multimedia Service
# We require pipewire.socket to be active before starting the daemon, because

# while it is possible to use the service without the socket, it is not clear

# why it would be desirable.

#

# A user installing pipewire and doing `systemctl --user start pipewire`

# will not get the socket started, which might be confusing and problematic if

# the server is to be restarted later on, as the client autospawn feature

# might kick in. Also, a start of the socket unit will fail, adding to the

# confusion.

#

# After=pipewire.socket is not needed, as it is already implicit in the

# socket-service relationship, see systemd.socket(5).

Requires=pipewire.socket

ConditionUser=!root


[Service]

LockPersonality=yes

MemoryDenyWriteExecute=yes

NoNewPrivileges=yes

RestrictNamespaces=yes

SystemCallArchitectures=native

SystemCallFilter=@system-service

Type=simple

ExecStart=/usr/bin/pipewire

Restart=on-failure

Slice=session.slice

ExecStartPost=/usr/bin/pw-cli set-default-node 32


[Install]

Also=pipewire.socket

WantedBy=default.target


Simple as THAT!?!?   You will need to reload user units and restart pipewire or reboot

systemctl --user daemon-reload
systemctl --user restart pipewire.service

------

Not totally sure if this is a RaspOS issue or the OVOS installer but there HAS to be a better way to deal with this - will update this mess as if I come upon one!   In meantime, this worked for me - I hope it helps others ... good luck