I use this implementation on my RuneAudio player to play a sound when the raspberry pi is powered on.
-
Place your audio file in /var/local/
cp startupsound.mp3 /var/local/
-
Create /usr/bin/startupsound.sh with these contents:
#!/bin/sh # uses mpg123 to play /usr/local/startupsound.mp3 through # the card 1 interface. It uses a buffer of 10000kb to make # up for a delay in some recievers using optical input. /usr/bin/mpg123 -a hw:1,0 -b 10000 /usr/local/startupsound.mp3
-
Make it executable
chmod +x /usr/bin/startupsound.sh
-
Test to make sure the sound is playable
/usr/bin/startupsound.sh
-
Create /usr/lib/systemd/system/startupsound.service
[Unit] Description=Startup Sound After=alsa-restore.target [Service] Type=oneshot ExecStart=/usr/bin/startupsound.sh [Install] WantedBy=multi-user.target
-
Reload the systemd service files
systemctl daemon-reload
-
Test the service by starting it (make sure your speakers are on!)
systemctl start startupsound
-
Enable the sound at boot
systemctl enable startupsound
journalctl -u startupsound