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: https://github.com/ktinkerer/aiyprojects-raspbian/tree/add_pause_and_resume/src
To get it to work you will need to copy the main.py action.py and vlc.py files into your ~voice-recognizer-raspi/src/ folder (If you’ve made any changes to action.py 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/actions.py
Add this to the imports:
import RPi.GPIO as gpio
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.
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
and replacing it with the stream for the station you want.
station = "http://bbcmedia.ic.llnwd.net/stream/bbcmedia_6music_mf_p?s=1494265223"
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.