Play BBC Radio on the Raspberry Pi AIY Project UPDATED!

UPDATE!: I’ve made a massive update to this to use the vlc python bindings and to pause and resume on any trigger. The code can be found here:

To get it to work you will need to copy the and files into your ~voice-recognizer-raspi/src/ folder (If you’ve made any changes to then back it up first!). VLC still needs to be installed.

Now when the radio is playing and you use any trigger the radio will stop while the box responds to the command and resume again once it’s finished. To stop the radio say “radio stop” or “radio off”.


I wanted to play the radio through my AIY Projects Box and after a lot of experimentation I found a way to do it. I also got some hints from this post I found on the Raspberry Pi forum about playing tracks from Youtube.

This uses VLC to play the radio stream, I initially tried mpd but couldn’t get it to work nicely alongside the voice recognition. I may persevere with mpd / mopidy as it would be great to be able to play anything.

First of all install vlc:
sudo apt-get install vlc

Then edit ~voice-recognizer-raspi/src/

Add this to the imports:

import RPi.GPIO as gpio
import time

Further down edit this part to add this class (added as a gist as wordpress was messing up the formatting!):

Then further down add this:
# =========================================
# Makers! Add your own voice commands here.
# =========================================
actor.add_keyword(_('radio'), playRadio(say,_('radio')))

Restart the voice recognition service:
sudo systemctl restart voice-recognizer.service
Check the voice recogniser logs for errors!
sudo journalctl -u voice-recognizer -e

Your AIY Project Box should now respond to radio commands by playing the correct BBC radio station, eg “Radio 1”, “Radio 1 extra” etc.
I’ve set mine up to play Radio 6 music as the default for the command “radio” as we listen to that 99% of the time! Change that by editing
station = ""
and replacing it with the stream for the station you want.

This should work with other radio streams, just add them to the elif list with the command you want to trigger them with.

Pressing the button stops the radio immediately and listens for another command.


Add a Comment

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