Headless Raspberry Pi – Tell me my IP address!

What is my IP address and can you email it to me?
Instructions for getting your IP address emailed to you can be found on the RPi wiki
It works. Yay.

What is my IP address, and can you tell it to me?
This is to get the Pi to find it’s own IP address and tell you vocally over the 3.5mm audio jack.
First of all, you need to install Festival, which is the text-to-speech converter.

Installation

  • Install the Festival package
    • apt-get install festival
  • Install the alsa utilities/drivers if you do not already have them
    • apt-get install alsa-utils
  • Edit /etc/modules
    • Make sure that
      • snd_bcm2835
    • is in the file.
    • Once it is (it might be already) you do not need to do the modprobe again after each reboot.
  • Push audio to the 3.5mm jack
    • amixer cset numid=3 1
  • (If you want to put it back to automatic, or HDMI, change it to 0 (auto) or 2 (HDMI))

Test out your audio

  • Do the following:
    • su root
    • cd /opt/vc/src/hello_pi
    • ./rebuild.sh
    • cd hello_audio
    • ./hello_audio.bin
  • You should hear something like a siren run through a bad 50s sci-fi tv show.
  • Let’s try testing ‘aplay’ to see if that works. Use one of the ‘alsa’ sample files.
    • aplay /usr/share/sounds/alsa/Front_Center.wav
  • Yes! It works. Dull, but it works.
  • Install mplayer:
    • apt-get install mplayer
  • Edit /etc/mplayer/mplayer.conf. Add the following line:
    • nolirc=yes
  • mplayer /usr/share/sounds/alsa/Front_Center.wav
  • Yes! Works!

Try out Festival

  • To make Festival say hello, try this:
    • echo “Hello” | festival –tts &
  • YES! It spoke to me!!! Woo-hoo!!!

The Script and running it

  • Return to your root folder:
    • cd /root
    • mkdir bin
    • cd bin
  • Create and edit a file called: say_my_ip_address.sh and use this:
#!/bin/sh
# First of all, see if you have an IP address yet
echo `hostname -I` > /tmp/check_ip.out
_CHECK_IP=`cat /tmp/check_ip.out`

# Find the length of the IP address
_LEN=`expr length $_CHECK_IP`

# Check the length of the IP address and make sure it’s sensible
if [ $_LEN -gt 3 ]; then
        # Construct your string to push to Festival
        echo “” > /tmp/shoutout.tmp
        echo “I am, a, Raspberry Pi. My I,P address is. ” >> /tmp/shoutout.tmp

        # This is so the IP address is said ‘nicely’
        for EACH in `hostname -I | grep -o -e “[^.]*”`; do
                for BIT in `echo $EACH | grep -o -e .`; do
                        echo $BIT >> /tmp/shoutout.tmp;
                        echo “. ” >> /tmp/shoutout.tmp;
                done
                echo “dot. ” >> /tmp/shoutout.tmp;
        done

        # And a bit of optional retro War Games!
        echo “. Would you like to play a game?” >> /tmp/shoutout.tmp
        cat /tmp/shoutout.tmp | festival –tts
        rm /tmp/shoutout.tmp
        rm /tmp/check_ip.out
else
        # If the IP address is not valid, report vocally and delayed re-run
        echo “I do not yet have an I,P address” | festival –tts
        sleep 5
        /root/bin/say_my_ip_address.sh 2&>/dev/null
fi

(All those fullstops and commas space out the words so it sounds like an IP address!)
  • Save and quit.
  • Make the file executable:
    • chmod a+x say_my_ip_address.sh
  • Edit /etc/rc.local
  • Add the following lines:
sudo -u root /root/bin/say_my_ip_address.sh &>/dev/null
  • And reboot
  • Don’t forget to have your earphones plugged in!

6 comments for “Headless Raspberry Pi – Tell me my IP address!

  1. >Hi Michael,

    I followed your instructions above but nothing happened.

    I finished "Installation" section. Then in "Test out your audio", after trying "aplay …" successfully, I skip mplayer.
    In "Try out Festival" section, nothing happens (it does not speak) after I enter the command: echo "Hello" | festival –tts
    Note: no '&' at the end of the command

    Please tell me which could be wrong.

    Thanks in advance,

    Josh

  2. >What Firmware are you running?
    I'm re-installing my SD card today, so will be following my own instructions so I should be able to find any bugs in the post as I go.

  3. >Hi Michael,

    I also got everything working (aplay, mplayer playing sound) but at echo "Hello"|festival –tts &

    I get the error:
    aplay: main:682: audio open error: Device or resource busy
    [1]+ Done echo "hello" | festival –tts
    I also have no sound problems with mpd/mpc.
    I am using the 15/7/2012 Raspbian-Wheezy image.

    Any ideas? Thanks for the well explained guides in your blog!

  4. >Found the solution to no sound with festival text to speech. I had sound with all other programs but none with festival. There seems to have been a major update to raspbian/debian on 15-08-2012 and updating raspbian to this made sound work.
    To update type:

    sudo apt-get update
    sudo apt-get upgrade
    It takes about 60 minutes but well worth it.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.