Close

Setting up the Pi to loop sound file at boot

A project log for Snap Crackle Pi

Make your gas fireplace sound like the real thing with way too much technology.

ericEric 11/24/2014 at 02:530 Comments

Step 1: Get Raspian image.

Step 2: Burn image to an SD card.

Step 3: Transfer the fireplace WAV file to the raspberry pi.

wget -O fireplace.wav http://soundbible.com/grab.php?id=1543&type=wav

Step 4: Play sound at boot up, by creating /etc/init.d/fireplace.sh file:

#!/bin/sh
while [ true ]; do aplay /home/pi/fireplace.wav; done;

Now make this file executable:

sudo chmod 755 /etc/init.d/fireplace.sh

Now add this script to all the defaut runlevels:

sudo update-rc.d fireplace.sh defaults

Reboot and you should be all set!

If you don't like the volume, you can log in to your Pi and then run the command line mixer:

alsa-mixer

The save your settings to a file using the alsactl ("also control") program:

mkdir ~/.config
 alsactl --file ~/.config/asound.state store

Then you will want to load these settings before you loop your sound file at boot by editing your fireplace.sh script as follows:

#!/bin/sh 
alsactl --file /home/pi/.config/asound.state restore 
while [ true ]; do aplay /home/pi/fireplace.wav; done;

Next up: an amplified speaker to hear the sounds.

Discussions