Podcast Player for the Raspberry Pi AIY Project
|I’ve added a podcast player with pause, resume and play a random episode to my MagPi Raspberry Pi Google AIY Projects box.
The code for the podcast player is here: https://github.com/ktinkerer/aiyprojects-raspbian/tree/podcast_player
You will need to copy actions.py, main.py and vlc.py from this branch and put them in your ~voice-recognizer-raspi/src/ folder.
This needs vlc to be installed.
sudo apt-get update
sudo apt-get install vlc
You also need to install the python package feedparser.
sudo pip install feedparser
Check vlc is working using:
cvlc http://a.files.bbci.co.uk/media/live/manifesto/audio/simulcast/hls/uk/sbr_high/ak/bbc_6music.m3u8
This should start playing a radio stream. Stop it with ctrl-c
Add your own podcasts in the list of urls, I’ve left some of my podcasts as an example but you will probably want to delete these. You need the podcast rss feed for this to work.
Restart the voice recognition service:
sudo systemctl restart voice-recognizer.service
Play podcasts with the command “podcast
Check the logs for errors using
sudo journalctl -u voice-recognizer -f
You may need to tweak your podcast names depending on what the voice recogniser registers.
If you want to use all the mods I’ve made they are on this branch: https://github.com/ktinkerer/aiyprojects-raspbian/tree/my_mods/src
Using Voice Keywords – OK Google
This didn’t work with voice keywords as once the podcast 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 podcast playing.
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 podcast and the button to stop it, podcast 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.
Currently, if the podcast finishes playing the box will still be unresponsive until the button is pressed. I am trying to think of a way to get around this, any ideas let me know.
Hey Ktinkerer, loving your work. I decided to give your mods a whirl and downloaded the github files but now im getting the following error.
^Cpi@raspberrypi:~ $ sudo journalctl -u voice-recognizer -f
— Logs begin at Mon 2017-05-22 02:07:40 PDT. —
May 18 06:22:35 raspberrypi python3[1452]: ^
May 18 06:22:35 raspberrypi python3[1452]: SyntaxError: invalid syntax
May 18 06:22:35 raspberrypi systemd[1]: voice-recognizer.service: main process exited, code=exited, status=1/FAILURE
May 18 06:22:35 raspberrypi systemd[1]: Unit voice-recognizer.service entered failed state.
May 18 06:22:35 raspberrypi systemd[1]: voice-recognizer.service holdoff time over, scheduling restart.
May 18 06:22:35 raspberrypi systemd[1]: Stopping voice recognizer…
May 18 06:22:35 raspberrypi systemd[1]: Starting voice recognizer…
May 18 06:22:35 raspberrypi systemd[1]: voice-recognizer.service start request repeated too quickly, refusing to start.
May 18 06:22:35 raspberrypi systemd[1]: Failed to start voice recognizer.
May 18 06:22:35 raspberrypi systemd[1]: Unit voice-recognizer.service entered failed state.
Any ideas what ive done wrong?
Sorry ignore the above error message. It was actually this error message.
May 18 06:22:35 raspberrypi systemd[1]: voice-recognizer.service: main process exited, code=exited, status=1/FAILURE
May 18 06:22:35 raspberrypi systemd[1]: Unit voice-recognizer.service entered failed state.
May 18 06:22:35 raspberrypi systemd[1]: voice-recognizer.service holdoff time over, scheduling restart.
May 18 06:22:35 raspberrypi systemd[1]: Stopping voice recognizer…
May 18 06:22:35 raspberrypi systemd[1]: Starting voice recognizer…
May 18 06:22:35 raspberrypi systemd[1]: Started voice recognizer.
May 18 06:22:35 raspberrypi python3[1450]: File “src/main.py”, line 7
May 18 06:22:35 raspberrypi python3[1450]:
May 18 06:22:35 raspberrypi python3[1450]: ^
May 18 06:22:35 raspberrypi python3[1450]: SyntaxError: invalid syntax
May 18 06:22:35 raspberrypi systemd[1]: voice-recognizer.service: main process exited, code=exited, status=1/FAILURE
May 18 06:22:35 raspberrypi systemd[1]: Unit voice-recognizer.service entered failed state.
May 18 06:22:35 raspberrypi systemd[1]: voice-recognizer.service holdoff time over, scheduling restart.
May 18 06:22:35 raspberrypi systemd[1]: Stopping voice recognizer…
May 18 06:22:35 raspberrypi systemd[1]: Starting voice recognizer…
May 18 06:22:35 raspberrypi systemd[1]: Started voice recognizer.
May 18 06:22:35 raspberrypi python3[1452]: File “src/main.py”, line 7
May 18 06:22:35 raspberrypi python3[1452]:
May 18 06:22:35 raspberrypi python3[1452]: ^
May 18 06:22:35 raspberrypi python3[1452]: SyntaxError: invalid syntax
May 18 06:22:35 raspberrypi systemd[1]: voice-recognizer.service: main process exited, code=exited, status=1/FAILURE
May 18 06:22:35 raspberrypi systemd[1]: Unit voice-recognizer.service entered failed state.
May 18 06:22:35 raspberrypi systemd[1]: voice-recognizer.service holdoff time over, scheduling restart.
May 18 06:22:35 raspberrypi systemd[1]: Stopping voice recognizer…
May 18 06:22:35 raspberrypi systemd[1]: Starting voice recognizer…
May 18 06:22:35 raspberrypi systemd[1]: voice-recognizer.service start request repeated too quickly, refusing to start.
May 18 06:22:35 raspberrypi systemd[1]: Failed to start voice recognizer.
May 18 06:22:35 raspberrypi systemd[1]: Unit voice-recognizer.service entered failed state.
May 18 06:27:46 raspberrypi systemd[1]: Starting voice recognizer…
May 18 06:27:46 raspberrypi systemd[1]: Started voice recognizer.
May 18 06:27:46 raspberrypi systemd[1]: voice-recognizer.service: main process exited, code=exited, status=203/EXEC
May 18 06:27:46 raspberrypi systemd[1]: Unit voice-recognizer.service entered failed state.
May 18 06:27:46 raspberrypi systemd[1]: voice-recognizer.service holdoff time over, scheduling restart.
May 18 06:27:46 raspberrypi systemd[1]: Stopping voice recognizer…
May 18 06:27:46 raspberrypi systemd[1]: Starting voice recognizer…
May 18 06:27:46 raspberrypi systemd[1]: Started voice recognizer.
May 18 06:27:47 raspberrypi systemd[1]: voice-recognizer.service: main process exited, code=exited, status=203/EXEC
May 18 06:27:47 raspberrypi systemd[1]: Unit voice-recognizer.service entered failed state.
May 18 06:27:47 raspberrypi systemd[1]: voice-recognizer.service holdoff time over, scheduling restart.
May 18 06:27:47 raspberrypi systemd[1]: Stopping voice recognizer…
May 18 06:27:47 raspberrypi systemd[1]: Starting voice recognizer…
May 18 06:27:47 raspberrypi systemd[1]: Started voice recognizer.
May 18 06:27:47 raspberrypi systemd[1]: voice-recognizer.service: main process exited, code=exited, status=203/EXEC
May 18 06:27:47 raspberrypi systemd[1]: Unit voice-recognizer.service entered failed state.
May 18 06:27:47 raspberrypi systemd[1]: voice-recognizer.service holdoff time over, scheduling restart.
May 18 06:27:47 raspberrypi systemd[1]: Stopping voice recognizer…
May 18 06:27:47 raspberrypi systemd[1]: Starting voice recognizer…
May 18 06:27:47 raspberrypi systemd[1]: Started voice recognizer.
May 18 06:27:47 raspberrypi systemd[1]: voice-recognizer.service: main process exited, code=exited, status=203/EXEC
May 18 06:27:47 raspberrypi systemd[1]: Unit voice-recognizer.service entered failed state.
May 18 06:27:47 raspberrypi systemd[1]: voice-recognizer.service holdoff time over, scheduling restart.
May 18 06:27:47 raspberrypi systemd[1]: Stopping voice recognizer…
May 18 06:27:47 raspberrypi systemd[1]: Starting voice recognizer…
May 18 06:27:47 raspberrypi systemd[1]: Started voice recognizer.
May 18 06:27:47 raspberrypi systemd[1]: voice-recognizer.service: main process exited, code=exited, status=203/EXEC
May 18 06:27:47 raspberrypi systemd[1]: Unit voice-recognizer.service entered failed state.
May 18 06:27:47 raspberrypi systemd[1]: voice-recognizer.service holdoff time over, scheduling restart.
May 18 06:27:47 raspberrypi systemd[1]: Stopping voice recognizer…
May 18 06:27:47 raspberrypi systemd[1]: Starting voice recognizer…
May 18 06:27:47 raspberrypi systemd[1]: voice-recognizer.service start request repeated too quickly, refusing to start.
May 18 06:27:48 raspberrypi systemd[1]: Failed to start voice recognizer.
May 18 06:27:48 raspberrypi systemd[1]: Unit voice-recognizer.service entered failed state.
Hmm that’s weird, line 7 of main.py is just the comments. I’ll test it again.
It works for me, I think maybe double check that main.py looks right on your copy?
Thanks ive done that but now get the following message:
May 22 02:07:44 raspberrypi systemd[1]: Starting voice recognizer…
May 22 02:07:44 raspberrypi systemd[1]: Started voice recognizer.
May 22 02:07:44 raspberrypi systemd[1]: voice-recognizer.service: main process exited, code=exited, status=203/EXEC
May 22 02:07:44 raspberrypi systemd[1]: Unit voice-recognizer.service entered failed state.
May 22 02:07:45 raspberrypi systemd[1]: voice-recognizer.service holdoff time over, scheduling restart.
May 22 02:07:45 raspberrypi systemd[1]: Stopping voice recognizer…
May 22 02:07:45 raspberrypi systemd[1]: Starting voice recognizer…
May 22 02:07:45 raspberrypi systemd[1]: voice-recognizer.service start request repeated too quickly, refusing to start.
May 22 02:07:45 raspberrypi systemd[1]: Failed to start voice recognizer.
May 22 02:07:45 raspberrypi systemd[1]: Unit voice-recognizer.service entered failed state.
Hmm, are there any other details further back in the log?
Unfortunately no its not a very helpful log:
pi@raspberrypi:~ $ sudo journalctl -u voice-recognizer -f
— Logs begin at Mon 2017-05-22 02:07:40 PDT. —
May 18 07:14:20 raspberrypi systemd[1]: Starting voice recognizer…
May 18 07:14:20 raspberrypi systemd[1]: Started voice recognizer.
May 18 07:14:20 raspberrypi systemd[1]: voice-recognizer.service: main process exited, code=exited, status=203/EXEC
May 18 07:14:20 raspberrypi systemd[1]: Unit voice-recognizer.service entered failed state.
May 18 07:14:20 raspberrypi systemd[1]: voice-recognizer.service holdoff time over, scheduling restart.
May 18 07:14:20 raspberrypi systemd[1]: Stopping voice recognizer…
May 18 07:14:20 raspberrypi systemd[1]: Starting voice recognizer…
May 18 07:14:20 raspberrypi systemd[1]: voice-recognizer.service start request repeated too quickly, refusing to start.
May 18 07:14:20 raspberrypi systemd[1]: Failed to start voice recognizer.
May 18 07:14:20 raspberrypi systemd[1]: Unit voice-recognizer.service entered failed state.
It seems to be another problem unrelated to your code.
No it’s not helpful! Have you tried going back to the original main.py and action.py?
Okay I think ive solved it, took awhile but it seems like my main.py was set as non executable. Changed that and rebooted and ive not got errors now. Fingers crossed it remains that way! Thanks for your help.
Glad you sorted it!
If you are looking for a solution to the button requirement, you can check out my code here:
https://github.com/mpember/aiyprojects-raspbian/tree/aiyprojects/src
While the podcast functionality is handled differently, the button-press ‘problem’ is solved by simple removing the listener and returning control at the end of the playback. I use MPD, but that it primarily because my AIY kit doubles as a UPnP renderer, It should be possible to modify the code to use VLC.
Thanks for the comments, this post is a little outdated now as I’ve moved to the newer version of aiyprojects and rewritten most of my mods to suit that. I’ve also started using mpd recently and I’m finding that works better than vlc did.
Fwiw, my code is also based on the most recent iteration of the AIY code.
Since some of the podcasts were taking a while to load, I wrote a simple podcatching service that caches the podcast data.
That’s great, would you mind if I add it to my list of mods?
You are welcome to post a link. Documentation is non-existent, and it contains a bunch of code and features other than just the podcast code. I’ve just added code which uses MQTT to control power switches. Previously, I added Kodi-related code found from another site. Some of that will rely on code not included in the repo.
I love this project, I’m going to make one for my 85 year old father who is struggling with dimentia. Is there any way to make it continuously play podcasts until you press the button again to stop it?
Also, is it possible to make the button start up the podcast player and stop it instead of sending it to the voice assistant? I really want a single function box that just plays podcasts continuously by pressing a button and that’s it.