Raspberry Pi Radio Config Notes

!!!!!! These notes assumes your Raspberry Pi resides on a secure, trusted network (e.g. behind a firewall in your own home). No consideration has been given to security. !!!!!!

Run raspi-config to turn on ssh, set boot to console, and expand filesystem

sudo apt-get update sudo apt-get dist-upgrade sudo apt-get install nginx fcgiwrap spawn-fcgi vim pulseaudio mplayer tmux

Edit /etc/network/interfaces to set static IP:

auto eth0
iface eth0 inet static

Add the www-data user to the audio, pulse groups. Edit /etc/group:


Edit /etc/pulse/daemon.conf

daemonize = yes
system-instance = yes
exit-idle-time = -1

Edit /etc/default/pulseaudio


Find the name of your prefered audio output with pacmd list-sinks.

Edit /etc/pulse/client.conf

default-sink = alsa_output.usb-C-Media_INC._USB_Sound_Device-00-MicroII.analog-stereo

/usr/bin/amixer set Master 26%

cat /dev/urandom | pacat ^C

tmux new-session -s michiganradio -d ‘pulseaudio -D ; mplayer’

Web Server Setup

sudo mkdir /var/www sudo mkdir /var/www/cgi-bin sudo chown -R www-data:www-data /var/www/

sudo cp /etc/nginx/sites-available/default /etc/nginx/sites-available/dist-default

Edit /etc/nginx/sites-enabled/default:

server {
    root /var/www/;
    index index.html;
    server_name localhost;
    location / {
        try_files $uri/ /index.html;
    location /cgi-bin {
        include fastcgi_params;
        fastcgi_pass unix:/var/run/fcgiwrap.socket;

Restart nginx: sudo service nginx restart.

Minimal Web Radio Control

Create /var/www/index.html:

<!DOCTYPE html>
<html lang="en-us">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Raspberry Pi</title>
function dumbHttpRequest(url) {
    var request = new XMLHttpRequest();"get", url, true);
<h1>Raspberry Pi</h1>
<p><button onclick="dumbHttpRequest('/cgi-bin/play-michiganradio.cgi');">Play Michigan Radio</button></p>
<p><button onclick="dumbHttpRequest('/cgi-bin/stop-michiganradio.cgi');">Stop Michigan Radio</button></p>
<p><button onclick="dumbHttpRequest('/cgi-bin/increase-volume.cgi');">Increase Volume</button></p>
<p><button onclick="dumbHttpRequest('/cgi-bin/decrease-volume.cgi');">Decrease Volume</button></p>

Create /var/www/cgi-bin/play-michiganradio.cgi:

/bin/echo -e "Content-type: text/html\r\n\r\n"
/usr/bin/tmux new-session -s michiganradio -d 'mplayer -cache 1024'

Create /var/www/cgi-bin/stop-michiganradio.cgi:

/bin/echo -e "Content-type: text/html\r\n\r\n"
/usr/bin/tmux kill-session -t michiganradio

Create /var/www/cgi-bin/increase-volume.cgi:

/bin/echo -e "Content-type: text/html\r\n\r\n"
/usr/bin/amixer set Master 1%+

Create /var/www/cgi-bin/decrease-volume.cgi:

/bin/echo -e "Content-type: text/html\r\n\r\n"
/usr/bin/amixer set Master 1%-


cd /var/www/cgi-bin sudo chown www-data:www-data ./* sudo chmod u+x ./*

Speech Synthesis

sudo apt-get install espeak

The espeak package works, but it outputs at 22050Hz, which my external USB speaker doesn’t like.

This fails: espeak “Test Test Test test test test test test test”

This works: espeak “Test Test Test test test test test test test” –stdout | mplayer -cache 1024 -af resample=44100:0:0 -