Nipo358
Posts: 1
Joined: Thu Jan 03, 2019 5:16 pm

Playing a sound on PC Startup?

Thu Jan 03, 2019 5:24 pm

So i'm helping a friend build their first PC and they would like to have a small noise play on startup. I was thinking about using a Raspberry Pi in order to accomplish this. Are there any ways to go about this?

bzt
Posts: 564
Joined: Sat Oct 14, 2017 9:57 pm

Re: Playing a sound on PC Startup?

Fri Jan 04, 2019 12:22 pm

Hi,

Yes. There's a script "/etc/rc.local" which will be called during boot (somewhere at the end). You can put a command in it which plays a sound.
Now about playing a sound, I suspect you don't have the sound sample in raw, therefore you'll need something to decode it. There are many command line tools for that, try one of these:
- mpg123
- mpg321
- mplayer
- cvlc
All of the above are capable of playing an MP3 for example, and I've ordered the list by complexity (mpg123 is the simplest with least dependency, cvlc requires the most).

One last note, you should play the sound in the background and let the bootup continue during the playback. For that, you have to append an and "&" at the end of the command. Also it is very important to return with a success code from rc.local. Putting all together:

/etc/rc.local:

Code: Select all

mpg123 /home/pi/startupchime.mp3 &
exit 0

Cheers,
bzt

User avatar
thagrol
Posts: 3178
Joined: Fri Jan 13, 2012 4:41 pm
Location: Darkest Somerset, UK
Contact: Website

Re: Playing a sound on PC Startup?

Fri Jan 04, 2019 1:43 pm

Nipo358 wrote:
Thu Jan 03, 2019 5:24 pm
So i'm helping a friend build their first PC and they would like to have a small noise play on startup. I was thinking about using a Raspberry Pi in order to accomplish this. Are there any ways to go about this?
Need more info.

bzt's answer is assuming that the Pi is the PC or that it will be booted by the PC. In the second case you'll need to find a way to do a clean shutdown when the PC is switched off.

If it's a "standard" PC, it should be possible without using a Pi though it will depend on which OS it's running. bzt's solution for linux, hit google for Windows or Mac OS.

If you want to use a Pi in addition to the PC, the trick is detecting when the PC has started up (is that power on, OS loaded, user logged in,...) and ensuring a clean shutdown of the Pi to avoid SD card corruption.
Arguing with strangers on the internet since 1993.

klricks
Posts: 7172
Joined: Sat Jan 12, 2013 3:01 am
Location: Grants Pass, OR, USA
Contact: Website

Re: Playing a sound on PC Startup?

Fri Jan 04, 2019 2:07 pm

Also a set of powered speakers would need to be connected to the RPi.
Probably USB powered speakers would work well here.
Unless specified otherwise my response is based on the latest and fully updated RPiOS Buster w/ Desktop OS.

Return to “Other projects”