Play BBC Radio on the Raspberry Pi AIY Project UPDATED!

Using the new version of the AIY Project and don’t have an file? Use this mod instead.

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 needs to be installed:

sudo apt-get update
sudo apt-get install vlc

Double check that your and your files still have executable rights if not re-add them:

chmod +x voice-recognizer-raspi/src/
chmod +x voice-recognizer-raspi/src/

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

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”.

Listening from outside the UK

Unfortunately it seems that the high quality links won’t work from outside the UK so if you are having trouble getting this to work, you may see a 403 error, then try replacing the list of stations with this list:

'1': '',
'2': '',
'3': '',
'4': '',
'5': '',
'5 sports': '',
'6': '',
'1xtra': '',
'4 extra': '',

Other stations can be found here. Thanks to paulpoco in the comments for finding this out!

Using Voice Keywords – OK Google

This didn’t work with voice keywords as once the radio was playing it was hard to get the box to recognise the keyword or the command. To get around this I’ve come up with a method where if you want to use voice keywords you can get the box to then wait until the button is pressed and this will stop the radio.

To do this use the updated Github code and find these lines:

# Uncomment the following line if you want to use a voice trigger to start the radio and the button to stop it, radio will not pause and resume
# self.wait_for_button()

Delete the comment (and the space!) before self.wait_for_button()
Also, make sure you import the gpio module.

import RPi.GPIO as gpio

Pause and resume will no longer work with this method, the box will not respond to any commands until the button is pressed, then it will start listening for commands again.

Original Method

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 update
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 *