My Raspberry Pi baby monitor writeup got some love from the Raspberry Pi site and CNN.
To kick things up a notch, I just added web streaming audio to the mix. With the help of icecast2 and darkice, the Raspberry Pi transcodes live audio to MP3 and broadcasts it over HTTP.
@t3node wrote up an excellent guide on live mp3 streaming using the Raspberry Pi. Using that post as a guide, here’s what I did to get it working.
Download darkice source
First, add the Raspbian source repository if it isn’t already loaded. Add this line to /etc/apt/sources.list
deb-src http://mirrordirector.raspbian.org/raspbian/ wheezy main contrib non-free rpi
Update packages and install the darkice dependencies.
$ sudo apt-get update
$ sudo apt-get --no-install-recommends install build-essential devscripts autotools-dev fakeroot dpkg-dev debhelper autotools-dev dh-make quilt ccache libsamplerate0-dev libpulse-dev libaudio-dev lame libjack-jackd2-dev libasound2-dev libtwolame-dev libfaad-dev libflac-dev libmp4v2-dev libshout3-dev libmp3lame-dev
Grab the source package for darkice.
$ mkdir src; cd src/
$ apt-get source darkice
Modify the compilation options to match Raspbian.
$ cd darkice-1.0
$ vi debian/rules
debian/rules
should look like this:
1 2 3 4 5 6 7 8 9 10 |
|
Beware, ‘make’ wants tabs instead of spaces. To be on the safe side, you can download this rules file instead.
Before you build the new .deb package, change the version to reflect MP3 support:
$ debchange -v 1.0-999~mp3+1
Your editor will open to edit the changelog.
1 2 3 4 5 6 7 |
|
Build and install darkice
Now build and install your custom darkice package.
$ dpkg-buildpackage -rfakeroot -uc -b
$ sudo dpkg -i ../darkice_1.0-999~mp3+1_armhf.deb
Darkice is now installed. To configure it, copy the template config file to /etc
.
$ sudo cp /usr/share/doc/darkice/examples/darkice.cfg /etc/
Here’s my sample config file:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
|
Install icecast2 and begin monitoring
Now you’ll need to install icecast2 to stream the audio over the network.
$ sudo apt-get install icecast2
The installer will ask you for a few passwords, make sure you set the source password as the same one for darkice (*SOURCE_PASS*
in the sample config above).
Now start icecast2 and darkice.
$ sudo service icecast2 start
$ sudo darkice
DarkIce 1.0 live audio streamer, http://code.google.com/p/darkice/
Copyright (c) 2000-2007, Tyrell Hungary, http://tyrell.hu/
Copyright (c) 2008-2010, Akos Maroy and Rafael Diniz
This is free software, and you are welcome to redistribute it
under the terms of The GNU General Public License version 3 or
any later version.
Using config file: /etc/darkice.cfg
Using ALSA DSP input device: plughw:1,0
Using POSIX real-time scheduling, priority 98
Darkice will run in the foreground (CTRL+C to exit).
Now open up a browser and navigate to http://{Raspberry Pi IP}:8000. Click on m3u and your audio player should play the baby monitor audio. It even works on the iPhone.
The one downside is that there’s a 5-10 second delay when using this method. But since I’m just interested in a baby monitor, 5-10 seconds doesn’t matter that much. Also, take care to add some authentication and secure passwords before you try this over the Internet.