Turn your Raspberry Pi into a white noise machine

What you need for this guide

  • A Raspberry Pi with debian* installed
  • The Internet
  • A 3.5mm male-to-male ("headphones"-style) audio cable
  • An old stereo with auxiliary input
**This guide is based on debian/raspian however it may work in another distro.

How to set up the Pi

With your Pi connected to the internet, at the command line type in

sudo apt-get update
sudo apt-get install sox
export AUDIODEV=hw:0,0
export AUDIODRIVER=alsa

This installs sox and set the environment variables needed for the Pi to find your audio device.

Now open the startup jobs list,

sudo nano /etc/crontab

and insert the following text into a new line at the end of the file.

@reboot pi play -b 16 -n synth 0 brownnoise

Close the file and save.  This will create brown noise, which I find more soothing than white but you can also use white noise or pink noise by replacing "brownnoise" with "whitenoise" or "pinknoise".  Note that we are specifying 16bit output because 32 is not supported.

The final steps

The sound we selected will now automatically start playing on boot. Plug your 3.5mm cable from the Pi into your stereo and plug in the power cable.  Note that it will take a minute for your Pi to boot up before you get any audio.  Turn on the stereo and adjust your bass and treble levels to your preference so that the noise generated is exactly how you want it.

Some Considerations

While you may need a keyboard, ethernet, and monitor to set up the script, presumably, you're going to want to plug in only the audio and power cables when you actually set it up to your stereo.  This means you will not have a way to properly shut down the Pi when you want to turn it off.  Turning off the Pi without shutting down has a small chance of damaging data on the memory card and making the Pi unable to boot.  For this reason, you should try to avoid turning off the Pi unnecessarily.  You might also consider backing up your memory card.


1 comment:

  1. Thanks for your post, it was really useful. I did have to spend some time troubleshooting, because I didn't realize the default audio on the Pi is HDMI... After correcting that, it worked like a charm!