Raspberry Pi Startup and Shutdown Sound

by sawfish5 in Circuits > Raspberry Pi

1779 Views, 5 Favorites, 0 Comments

Raspberry Pi Startup and Shutdown Sound

F720798F-6B92-4D59-9A0A-2CC636A5D084.jpeg

As many old computers had startup and shutdown sounds, I wanted my raspberry pi to do the same. Using some mp3 files and a system file, my method is easy to recreate. Enjoy!

Supplies

CBDE2644-C4E1-4C83-A735-875CE42911AC.jpeg

Raspberry Pi running Raspberry Pi OS (I am using a pi 400, but any will work)

Mouse

Keyboard

Find Your Sounds

54EA5EA1-4591-46B3-B6BF-130DF3DEC4BA.jpeg

I have always been pretty fond of the Windows XP sounds, so I will be using those, though any .mp3, .m4a, or .wav file will work. I downloaded my sounds from winhistory.de, which has a wide assortment of windows startup and shutdown sounds, free.

Save Your Sounds

31CC7DA6-5BA7-4B9D-BF77-2BDD2CADD349.png

Save your sounds as startup.mp3, and shutdown.mp3, changing the endings to your file type. Move them to /home/pi/Downloads if they are not already there, and continue.

Move Your Sounds

step3.1.png
step3.2.png
5452F179-7E1B-41E0-8985-49497B8E6BC2.png

You can't move files in the os folders, so you will have to use the terminal for these steps.


Ensure that you have sudo privileges, then open your terminal and enter:

sudo mkdir /etc/sound

This makes a folder in /etc called "sound". This is where your sound files will go. To move them there, enter

sudo mv /home/pi/Downloads/startup.mp3 /etc/sound

and

sudo mv /home/pi/Downloads/shutdown.mp3 /etc/sound


These commands will move your sound files to the "sound" folder.

Open your file manager, and go to /etc/sound, and make sure that your files are there. If they are, you can move on.

Create .service File

step4.1.png
step4.2.png

Next, you have to create a .service file called "sound.service". Open a new terminal, and enter

sudo nano /etc/systemd/system/sound.service

This creates a new file called "sound.service" located in '/etc/systemd/system' in the nano editor. After entering the command, you will be presented with a blank text editor, which is your files contents. Paste the following code into the editor:

[Unit]
Description=Runs script at system shutdown

[Service]
Type=oneshot
RemainAfterExit=true
ExecStart=/bin/omxplayer /etc/sound/startup.mp3
ExecStop=/bin/omxplayer /etc/sound/shutdown.mp3

[Install]
WantedBy=multi-user.target

Let me explain what this does. The top '[Unit]' lines do nothing to the script, but they let the user see what the purpose of the file is. The '[Service]' lines are the actual scripts. 'Type' declares the type of script it is, and 'RemainAfterExit' declares whether or not the the 'Exec' commands should be run after the service is stopped. 'ExecStart' and 'ExecStop' are short for "Execute on Start" and "Execute on Stop". The file paths after those tell the pi to open your sound files using omxplayer. And '[Install]' and 'WantedBy' tells the pi what file to use to run the script.

After you finish pasting your code, use Ctrl + O to write out (save) your file, click enter to confirm the file to write, and then Ctrl + X to exit the editor.

Enable Your Script

step5.1.png

The last step is to enable your script. To do this, open another terminal, and type

sudo systemctl enable sound

This enables your script so that it will run on start-up, and stay active until shutdown.

Reboot

step6.1.png

All thats left is to reboot your pi so the changes take effect. Type

sudo reboot

into your terminal. If you did everything correctly, you should be greeted with the chime of your sound when the pi finishes booting. If your sound starts late so you only hear the last half of it, change your sound files so they have about 2 seconds of silence before the actual sound starts. If you hear no sound at all, go back into your scripts, and check your file paths. If that doesn't work, try re-enabling the script. If you still can't get it to work, leave a comment, and I will do my best to help you out.

Good Luck!