Play BBC Radio on the Raspberry Pi AIY Project UPDATED!
|Using the new version of the AIY Project and don’t have an action.py 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: https://github.com/ktinkerer/aiyprojects-raspbian/tree/radio_player/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 needs to be installed:
sudo apt-get update
sudo apt-get install vlc
Double check that your main.py and your status-monitor.py files still have executable rights if not re-add them:
chmod +x voice-recognizer-raspi/src/main.py
chmod +x voice-recognizer-raspi/src/status-monitor.py
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': 'http://bbcmedia.ic.llnwd.net/stream/bbcmedia_radio1_mf_p',
'2': 'http://bbcmedia.ic.llnwd.net/stream/bbcmedia_radio2_mf_p',
'3': 'http://bbcmedia.ic.llnwd.net/stream/bbcmedia_radio3_mf_p',
'4': 'http://bbcmedia.ic.llnwd.net/stream/bbcmedia_radio4fm_mf_p',
'5': 'http://bbcmedia.ic.llnwd.net/stream/bbcmedia_radio5live_mf_p',
'5 sports': 'http://bbcmedia.ic.llnwd.net/stream/bbcmedia_radio5extra_mf_p',
'6': 'http://bbcmedia.ic.llnwd.net/stream/bbcmedia_6music_mf_p',
'1xtra': 'http://bbcmedia.ic.llnwd.net/stream/bbcmedia_radio1xtra_mf_p',
'4 extra': 'http://bbcmedia.ic.llnwd.net/stream/bbcmedia_radio4extra_mf_p',
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/action.py
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
and replacing it with the stream for the station you want.
else:
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.
Hi, thanks for this information. Although I have vlc working to play tracks from Youtube I just get silence with this radio streaming related mod. Tried the command line and it works but there are a few errors that pop up regardless.
Any insight on where I could focus further research would be appreciated.
What are the errors?
Hi, sorry I just got another chance to try. The errors, in addition to the listener process interfering with “could you try that again” whilst the music plays is:
~ $ cvlc “http://bbcmedia.ic.llnwd.net/stream/bbcmedia_6music_mf_p?s=1494265223”
VLC media player 2.2.5 Weatherwax (revision 2.2.5-0-g9275f0fefa)
[01a06dc8] pulse audio output error: PulseAudio server connection failure: Connection refused
[0198ddd0] core interface error: no suitable interface module
[019678f8] core libvlc error: interface “globalhotkeys,none” initialization failed
[0198ddd0] dbus interface error: Failed to connect to the D-Bus session daemon: Unable to autolaunch a dbus-daemon without a $DISPLAY for X11
[0198ddd0] core interface error: no suitable interface module
[019678f8] core libvlc error: interface “dbus,none” initialization failed
[0198ddd0] dummy interface: using the dummy interface module…
[73b009b0] http access: Raw-audio server found, mp3 demuxer selected
[73c0fa10] mpgatofixed32 audio converter error: libmad error: bad main_data_begin pointer
[73c0fa10] mpgatofixed32 audio converter error: libmad error: bad main_data_begin pointer
It looks like a vlc error, did you do “sudo apt-get update” before you installed vlc?
yes I did. I will have another go starting with a fresh install.
I am still struggling after using the latest GitHub copies of main.py, vlc.py and action.py.
The following is the piutput from journal after saying “play Radio 1”. It keeps starting and stopping with interleaved “Could you try that again”. It is looking like I will have to rebuild the O/S as I cannot so far solve the PulseAudio errors even after removing it then removing and reinstalling VLC.
sudo journalctl -u voice-recognizer -f
— Logs begin at Thu 2017-06-01 18:54:24 PDT. —
May 26 07:07:30 Google_AIY python3[572]: [0237a808] pulse audio output error: PulseAudio server connection failure: Connection refused
May 26 07:07:30 Google_AIY python3[572]: [2017-05-26 07:07:30,778] INFO:root:setting radio state stopped
May 26 07:07:30 Google_AIY python3[572]: [2017-05-26 07:07:30,826] INFO:main:ready…
May 26 07:16:29 Google_AIY systemd[1]: Stopping voice recognizer…
May 26 07:16:29 Google_AIY python3[572]: arecord: pcm_read:2031: read error: Interrupted system call
May 26 07:16:29 Google_AIY systemd[1]: Starting voice recognizer…
May 26 07:16:29 Google_AIY systemd[1]: Started voice recognizer.
May 26 07:16:32 Google_AIY python3[1219]: [2017-05-26 07:16:32,917] INFO:audio:started recording
May 26 07:16:33 Google_AIY python3[1219]: [016ddab8] pulse audio output error: PulseAudio server connection failure: Connection refused
May 26 07:16:33 Google_AIY python3[1219]: [01612dc8] pulse audio output error: PulseAudio server connection failure: Connection refused
May 26 07:16:33 Google_AIY python3[1219]: [2017-05-26 07:16:33,485] INFO:root:setting radio state stopped
May 26 07:16:33 Google_AIY python3[1219]: [2017-05-26 07:16:33,490] INFO:main:ready…
May 26 07:16:53 Google_AIY python3[1219]: [2017-05-26 07:16:53,284] INFO:trigger:clap detected
May 26 07:16:53 Google_AIY python3[1219]: [2017-05-26 07:16:53,286] INFO:main:listening…
May 26 07:16:53 Google_AIY python3[1219]: [2017-05-26 07:16:53,288] INFO:main:recognizing…
May 26 07:16:53 Google_AIY python3[1219]: [2017-05-26 07:16:53,289] INFO:root:pausing radio
May 26 07:16:56 Google_AIY python3[1219]: [2017-05-26 07:16:56,105] INFO:speech:event_type: 1
May 26 07:16:56 Google_AIY python3[1219]: [2017-05-26 07:16:56,109] INFO:main:thinking…
May 26 07:16:56 Google_AIY python3[1219]: [2017-05-26 07:16:56,146] INFO:speech:transcript: play Radio 1
May 26 07:16:57 Google_AIY python3[1219]: [2017-05-26 07:16:57,258] INFO:root:starting radio: play 1
May 26 07:16:57 Google_AIY python3[1219]: [2017-05-26 07:16:57,258] INFO:root:searching for: play 1
May 26 07:17:01 Google_AIY python3[1219]: [2017-05-26 07:17:01,624] INFO:root:stream http://a.files.bbci.co.uk/media/live/manifesto/audio/simulcast/hls/uk/sbr_high/ak/bbc_6music.m3u8
May 26 07:17:01 Google_AIY python3[1219]: [2017-05-26 07:17:01,629] INFO:root:setting radio state playing
May 26 07:17:01 Google_AIY python3[1219]: [2017-05-26 07:17:01,630] INFO:main:handled local command: play Radio 1
May 26 07:17:01 Google_AIY python3[1219]: [2017-05-26 07:17:01,631] INFO:root:resuming radio playing
May 26 07:17:01 Google_AIY python3[1219]: [2017-05-26 07:17:01,648] INFO:main:ready…
May 26 07:17:01 Google_AIY python3[1219]: [6fb0da98] httplive stream: HTTP Live Streaming (a.files.bbci.co.uk/media/live/manifesto/audio/simulcast/hls/uk/sbr_high/ak/bbc_6music.m3u8)
May 26 07:17:02 Google_AIY python3[1219]: [6fb0ee98] ts demux: MPEG-4 descriptor not found for pid 0x22 type 0xf
May 26 07:17:02 Google_AIY python3[1219]: [6fb12468] packetizer_mpeg4audio packetizer: AAC channels: 2 samplerate: 48000
May 26 07:17:02 Google_AIY python3[1219]: [70e03de0] pulse audio output error: PulseAudio server connection failure: Connection refused
May 26 07:17:03 Google_AIY python3[1219]: [2017-05-26 07:17:03,271] INFO:trigger:clap detected
May 26 07:17:03 Google_AIY python3[1219]: [2017-05-26 07:17:03,273] INFO:main:listening…
May 26 07:17:03 Google_AIY python3[1219]: [2017-05-26 07:17:03,275] INFO:main:recognizing…
May 26 07:17:03 Google_AIY python3[1219]: [2017-05-26 07:17:03,276] INFO:root:pausing radio
May 26 07:17:07 Google_AIY python3[1219]: [6f100c68] http access error: cannot connect to as-hls-uk-live.akamaized.net:80
May 26 07:17:07 Google_AIY python3[1219]: [6f100c68] access_mms access error: cannot connect to as-hls-uk-live.akamaized.net:80
May 26 07:17:07 Google_AIY python3[1219]: [6fb0da98] core stream error: no suitable access module for `http://as-hls-uk-live.akamaized.net/pool_6/live/bbc_6music/bbc_6music.isml/bbc_6music-audio=320000-233720038.ts’
May 26 07:17:07 Google_AIY python3[1219]: [6fb0da98] httplive stream error: downloading segment 233720038 from stream 0 failed
^Cpi@Google_AIY:~/voice-recognizer-raspi/src $
I’m also getting pulseaudio errors but it still seems to work. The problem is you’ve said “play radio 1” instead of just “radio 1” so it’s looking for a station named “play 1” which doesn’t exist. If you wanted to you could change the keyword to “play radio” which should work although I haven’t tested it.
Followed the new instructions with vlc.py
its great but is there a way to get playback to pause when the button is pressed, as the radio playback interferes with voice input so google has a hard time making out what i’m trying to say
Did you copy the full main.py and action.py?
Hi, didn’t realise i had to copy main.py, sorted now, thanks 🙂
Thank you for all the information with voice recognition this project is really over the top good job!!
I get a list of error on restarting the service, am I right in thinking I need cloud platform enabled first?
Traceback (most recent call last):
File “src/main.py”, line 304, in
main()
File “src/main.py”, line 159, in main
do_recognition(args, recorder, recognizer, player)
File “src/main.py”, line 166, in do_recognition
actor = action.make_actor(say)
File “/home/pi/voice-recognizer-raspi/src/action.py”, line 372, in make_actor
actor.add_keyword(_(‘radio’), playRadio(say, _(‘radio’)))
[2017-05-12 14:23:41,466] INFO:audio:started recording
File “/home/pi/voice-recognizer-raspi/src/action.py”, line 228, in __init__
self.instance = vlc.Instance()
File “/home/pi/voice-recognizer-raspi/src/vlc.py”, line 1692, in __new__
return libvlc_new(len(args), args)
File “/home/pi/voice-recognizer-raspi/src/vlc.py”, line 4355, in libvlc_new
ctypes.c_void_p, ctypes.c_int, ListPOINTER(ctypes.c_char_p))
File “/home/pi/voice-recognizer-raspi/src/vlc.py”, line 254, in _Cfunction
raise NameError(‘no function %r’ % (name,))
NameError: no function ‘libvlc_new’
Thanks!
You don’t need to use the cloud speech API, I’m not. Have you got vlc installed and working? You can test that with cvlc and one of the stream URLs.
I had installed it using your guide, but it threw some errors, which I assumed were for video codex errors, will try installing again and testing!
Great project. Works very well. Thanks for publishing it.
I have copied your files(everything,it does more or less what I want) but when I play the radio it keeps stopping for an input. This only happens when I enable the clap trigger. Would you know how to fix this?
Also the timer you have created just seems to hang and makes me need to restart it. Any thoughts?
Yes I should add a note that the clap trigger is likely to get triggered by the radio. I found it was being falsely triggered a lot. Interesting about the timer, I’d better check that, thanks.
I’m really sorry I’ve just tested the timer and you’re right I’ve missed out
import threading
on the version on Github, add that to the imports and it should work. I’ll modify it now.Great! The timer works now, thanks.
I don’t believe it’s the sound trigerring the it because I have setup playing music through youtube through vlc and that does not activate the clap. I have used the youtube guide that you have attached in your post(I think it’s the only one that exists for a now)
The youtube player is hard coded to use the button as a trigger so it won’t respond to any others. I’ve set this up to pause the radio then play it again on any trigger so I think the sound will be triggering it. The code in this post works the same as the youtube player, it totally stops the radio when you press the button but it doesn’t resume, so if you want to use clap as a trigger you might be better off using that. The github code is updated to pause on resume on any trigger.
Glad the timer started working!
So if I setup a new trigger and only have that stop it would that fix? If not I will just do that. Thanks for your help and quick replies
A non noise based trigger would work, as far as I can tell the clap trigger is triggered by a loud noise so it’s triggering itself.
Great project!
Everything is working fine, and being a liker of classical music I have substituted the default radio 6 for a Classic Fm feed. I used:
‘radio’: ‘http://media-ice.musicradio.com/ClassicFMMP3’
for the default feed and also added a selector shown below to the end of the list (with commas before and after).
‘radio classic’: ‘http://media-ice.musicradio.com/ClassicFMMP3’ which worked fin still works OK, but it would be nice to know what causes this and if it should be solved.
Oops. Some of teh previous comment seems to have been missed out.
should have said. Everything works fine, but I notice a recurring error when running the system with a manual start, namely
PureAudio server connection failure: Connection refused
As I say, it works fine, but it would be nice to eliminate this if possible.
It’s pulseaudio I think, I’ve been trying to get mpd to work but that doesn’t play at all alongside the voice-recogniser so considering vlc is working I’m not going to change any pulseaudio settings! If you find a solution let me know.
Try sudo apt-get update then sudo apt-get upgrade, I tried this and it seems to have stopped the pulse audio errors.
I’ve tried this, but for some reason amending actions.py stops the project working. If i run “sudo journalctl -u voice-recognizer -e ” assuggested, then i get the following:
Testing the Google Cloud Speech API…
Speech recognition failed with 1
/home/pi/voice-recognizer-raspi/env/lib/python3.4/site-packages/urllib3/contrib/socks.py:37: DependencyWarning: SOCKS support in urllib3 requires the installation of optional dependencies: specifically, PySocks. For more information, see https://urllib3.readthedocs.io/en/latest/contrib.html#socks-proxies
DependencyWarning
Traceback (most recent call last):
File “/home/pi/voice-recognizer-raspi/src/speech.py”, line 256, in do_request
return self._handle_response_stream(response_stream)
File “/home/pi/voice-recognizer-raspi/src/speech.py”, line 201, in _handle_response_stream
for resp in response_stream:
File “/home/pi/voice-recognizer-raspi/env/lib/python3.4/site-packages/grpc/_channel.py”, line 363, in __next__
return self._next()
File “/home/pi/voice-recognizer-raspi/env/lib/python3.4/site-packages/grpc/_channel.py”, line 357, in _next
raise self
grpc._channel._Rendezvous:
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File “/home/pi/voice-recognizer-raspi/src/speech.py”, line 445, in
print(‘down response:’, req.do_request())
File “/home/pi/voice-recognizer-raspi/src/speech.py”, line 261, in do_request
raise Error(‘Exception in speech request’) from exc
__main__.Error: Exception in speech request
Failed to test the Cloud Speech API. Please see error above.
Press Enter to close…^CTraceback (most recent call last):
File “/home/pi/voice-recognizer-raspi/checkpoints/check_cloud.py”, line 98, in
input(‘Press Enter to close…’)
KeyboardInterrupt
Press Enter to close…
Any ideas please??
Did it work before you amended the actions.py? That looks like an error in the cloud speech API. Do you have cloud speech enabled? The radio should work with or without cloud speech.
Thanks – I sorted the billing and it fixed that issue…. but I still get errors when I run the “sudo journalctl -u voice-recognizer -f” command – it’s referring to syntax errors in other py files. I’ll try again in a few days but might have to come back and seek further help if that’s OK. Off on holiday for a few days 🙂
Have a great holiday!!
You might have seen this but this link is in how to play radio using mpd.
Is it what you want. Thanks for your continuous development and keep the great work
https://www.hackster.io/vvanhee/internet-streaming-radio-with-google-aiy-1edff3?utm_source=Hackster.io+newsletter&utm_campaign=cbfc52cda0-EMAIL_CAMPAIGN_2017_05_03&utm_medium=email&utm_term=0_6ff81e3e5b-cbfc52cda0-140978485&mc_cid=cbfc52cda0&mc_eid=e31cd83101
I’ve made some progress in using mpd it’s at: https://github.com/ktinkerer/aiyprojects-raspbian/tree/mpd mpd needs to be run as user pi for it to work, thank you for the link, I’ll take a look.
Thanks in advance for the help and the great project!
I can play from cvlc with a couple of errors:
(env) pi@raspberrypi:~/voice-recognizer-raspi/src $ cvlc http://bbcmedia.ic.llnwd.net/stream/bbcmedia_radio1xtra_mf_p?s=1494265403
VLC media player 2.2.5 Weatherwax (revision 2.2.5-0-g9275f0fefa)
[0127cb50] pulse audio output error: PulseAudio server connection failure: Connection refused
[012049e0] dummy interface: using the dummy interface module…
[73d009b0] http access: Raw-audio server found, mp3 demuxer selected
[7440ff80] mpgatofixed32 audio converter error: libmad error: bad main_data_begin pointer
I have copied in your action.py, vlc.py and main.py but when I start the AIY i get:
(env) pi@raspberrypi:~/voice-recognizer-raspi $ src/main.py
/home/pi/voice-recognizer-raspi/env/lib/python3.4/site-packages/urllib3/contrib/socks.py:37: DependencyWarning: SOCKS support in urllib3 requires the installation of optional dependencies: specifically, PySocks. For more information, see https://urllib3.readthedocs.io/en/latest/contrib.html#socks-proxies
DependencyWarning
[2017-05-19 15:49:40,568] INFO:audio:started recording
[01fa5250] pulse audio output error: PulseAudio server connection failure: Connection refused
[01ec8198] pulse audio output error: PulseAudio server connection failure: Connection refused
[2017-05-19 15:49:42,031] INFO:root:setting radio state stopped
[2017-05-19 15:49:42,118] INFO:main:ready…
Press the button on GPIO 23 then speak, or press Ctrl+C to quit…
When I press and say Radio 1, I get:
[2017-05-19 15:50:12,509] INFO:main:listening…
[2017-05-19 15:50:12,510] INFO:main:recognizing…
[2017-05-19 15:50:12,511] INFO:root:pausing radio
[2017-05-19 15:50:14,640] INFO:speech:event_type: 1
[2017-05-19 15:50:14,644] INFO:main:thinking…
[2017-05-19 15:50:14,649] INFO:speech:transcript: Radio 1
[2017-05-19 15:50:15,647] INFO:root:starting Radio 1
[2017-05-19 15:50:15,648] INFO:root:stream http://a.files.bbci.co.uk/media/live/manifesto/audio/simulcast/hls/uk/sbr_high/ak/bbc_radio_one.m3u8
[2017-05-19 15:50:15,666] INFO:root:setting radio state playing
[2017-05-19 15:50:15,667] INFO:main:handled local command: Radio 1
[2017-05-19 15:50:15,667] INFO:root:resuming radio playing
[2017-05-19 15:50:15,675] INFO:main:ready…
[6e803580] httplive stream: HTTP Live Streaming (a.files.bbci.co.uk/media/live/manifesto/audio/simulcast/hls/uk/sbr_high/ak/bbc_radio_one.m3u8)
[6e804a50] http access error: error: HTTP/1.1 403 Forbidden
[6e804a50] http access error: error: HTTP/1.0 403 Forbidden
[6e804a50] access_mms access error: error: HTTP/1.0 403 Forbidden
[6e803580] core stream error: no suitable access module for `http://as-hls-uk-live.akamaized.net/pool_7/live/bbc_radio_one/bbc_radio_one.isml/bbc_radio_one-audio%3d320000.norewind.m3u8′
[6e803580] httplive stream error: No playable streams found in Meta playlist
[6e804b30] es demux error: cannot peek
[6e804b30] es demux error: cannot peek
[6e804b30] es demux error: cannot peek
[6e804b30] es demux error: cannot peek
[6e804b30] es demux error: cannot peek
It played? Pulseaudio seems to like to throw errors!
Sorry just reread your comment and it looks like it didn’t play. It’s weird it doesn’t seem to like the url for radio one, which I’ve just tested and works. Not sure what is going wrong!
Hi, I have been trying to update my voice-recogniser-raspi folder to your latest my_mods branch but whenever I do I always get a (code=exited,error 203).
Do you know why this happens and how to fix it or am I missing something?
Thanks
Someone else had a similar problem I think. Double check that the python files you’ve changed are still executable.
Doing chmod +x fixed that issue.
Thanks a lot for the quick reply
Actually I am wrong. It was the original folde which is why it worked. How can I change the permissions from the whole folder in command line?
Not sure, you could try something like this: https://unix.stackexchange.com/questions/49884/how-to-make-executable-of-all-files-excluding-a-few-file-types
No it does not seem to work. Do you know which files it is that need to be excecutable because then I will just do it manually
All the python ones I guess!
Fixed it!! I had to install feedparser in python.
Question for the podcast. I have added this url http://androidauthority.libsyn.com/rss and called it android. However after restarting it and saying ‘podcast android’ it says ‘podcast not found’. Thoughts??
Thank you for time and patience. I really appreciate it.
Glad it’s working! Watch the logs as you say the commands to check what it thinks you are saying, I had to tweak some of the names of my podcasts.
May 20 10:26:32 raspberrypi python3[3170]: [2017-05-20 10:26:32,249] INFO:main:ready…
May 20 10:28:44 raspberrypi python3[3170]: [2017-05-20 10:28:44,832] INFO:main:listening…
May 20 10:28:44 raspberrypi python3[3170]: [2017-05-20 10:28:44,833] INFO:main:recognizing…
May 20 10:28:44 raspberrypi python3[3170]: [2017-05-20 10:28:44,834] INFO:root:pausing podcast state is stopped
May 20 10:28:44 raspberrypi python3[3170]: [2017-05-20 10:28:44,834] INFO:root:pausing radio
May 20 10:28:48 raspberrypi python3[3170]: [2017-05-20 10:28:48,092] INFO:speech:event_type: 1
May 20 10:28:48 raspberrypi python3[3170]: [2017-05-20 10:28:48,094] INFO:main:thinking…
May 20 10:28:48 raspberrypi python3[3170]: [2017-05-20 10:28:48,097] INFO:speech:transcript: Podcast Android
May 20 10:28:49 raspberrypi python3[3170]: [2017-05-20 10:28:49,137] INFO:root:podcast command:podcast android
May 20 10:28:49 raspberrypi python3[3170]: [2017-05-20 10:28:49,138] INFO:root:setting podcast state stopped
May 20 10:28:51 raspberrypi python3[3170]: [2017-05-20 10:28:51,462] INFO:main:handled local command: Podcast Android
May 20 10:28:51 raspberrypi python3[3170]: [2017-05-20 10:28:51,463] INFO:root:resume podcast state is stopped
May 20 10:28:51 raspberrypi python3[3170]: [2017-05-20 10:28:51,464] INFO:root:resuming radio stopped
May 20 10:28:51 raspberrypi python3[3170]: [2017-05-20 10:28:51,465] INFO:main:ready…
I can’t see anything wrong so I guess it is the link that is wrong then
It looks like it picked up the right command, may be handling the RSS feed wrong, I’ll test it in the morning.
Thank you so much
Ok it turns out it was a case error, for some reason it was capitalising Podcast only for Podcast Android! I’ve tweaked the code so this shouldn’t be an issue and uploaded it to github https://github.com/ktinkerer/aiyprojects-raspbian/tree/podcast_player
is it just this line:
voice_command = ((voice_command.replace(self.keyword, ”, 1)).strip()).lower()
that needs to be changed? I have added my own stuff to your complete github and I don’t want to break it
Yes that should sort it out.
Thank you so much. That has fixed it. I really appreciate all the time you have spent with me and everyone else.
That’s ok, glad it’s working!
I believe that there is the same issue in recognition for the radio because when I try to play nottingham it says it is not found and says that I said this: radio Nottingham when I believe it should be Radio Nottingham.
Just wanted to let you know
Ah! Thank you, yes probably the same issue, will take a look in the morning.
Hopefully the final thing in a while haha but the radio streams need to be .m3u8 right because it sort of hangs trying this link http://player.listenlive.co/49121
I tested them with cvlc to find ones that work, not all did, but that sounds about right.
Thanks a ton
Using this link with cvlc works http://www.surfmusic.de/m3u/cjfm-virgin-radio-96-95-9-fm,15712.m3u but when I then put it into action.py it just hangs even though it recognises the command. It says: python3[3047]: [6bb0edd8] es demux error: cannot peek. Thoughts?
No idea but I’ll have a look in the morning!
I see what you mean, I’ve just tested it, and I’ve no idea why it won’t play using the AIY box, I would expect it to as vlc manages to play it, with the same es demux errors. Sorry!
Thank you for trying.
I’ve come up with a fix of sorts, for some reason python vlc doesn’t handle m3u playlists even though vlc can. I’ve no idea why. I’ve changed it so that it just looks for m3u and parses it itself.
The fix is here: https://github.com/ktinkerer/aiyprojects-raspbian/blob/radio_player/src/action.py
If you are just copying the updated bit into your action.py there are also 2 new imports so don’t miss those:
import requests
import re
I’ve copied it exactly into mine and I get: code=exited,status=1/FAILURE
Do you know why that is? I have added the imports to the end of the list. Could it be all the other imports I need?
Thanks
Normally you get a different error for missing imports but you could add them to make sure. Did it say anything else?
I think I have realised what it is. I had to install the feedparser to use it and so I believe I probably have to do the same. I will let you know tomorrow when I have chance
You say, “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 butthen you say modify actions.py? Do you mean action.py?
I am confused is there such a thing as actions.py?
I kinda got it working by over riding the 1st station with http://bbcmedia.ic.llnwd.net/stream/bbcmedia_radio1_mf_p?s=1494265262 the m3u8 wasn’t working.
Think I need to start over.
Yes sorry typo, I’ve changed that. Also check which version of vlc you have running,
vlc --version
as it should have said to do:sudo apt-get update
sudo apt-get install vlc
This is the version I’ve got: VLC media player 2.2.5 Weatherwax (revision 2.2.5-0-g9275f0fefa)
Ok so I downloaded the main.py, VLC.py, action.py. Then add the lines from this post?
action.py says updated but does it include the changes from this post?
Sorry about all the questions.
Off topic: what is that weird voice that sometimes plays instead of the normal good sounding one? Like if I ask 2+2 I get the good voice but if I say power off I get the crappy distorted voice?
Ahh I’ve just realised the link in this post was pointing to an outdated branch! Try this one for the up to date version, you’ll need the main.py and action.py from here: https://github.com/ktinkerer/aiyprojects-raspbian/tree/radio_player/src
Back up your action.py first? Or alternatively you can get a fresh copy from
https://github.com/google/aiyprojects-raspbian/tree/master/src
Yes it could be possible to move some out into other files and import them if you wanted to.I tried to make it clear earlier that the rest of the post was my original method, you don’t need to add that as well.
I think that is the local voice that Google have used, I think people have had success changing it to different things
https://www.raspberrypi.org/forums/viewtopic.php?f=114&t=182384&p=1162459#p1162459
Will try tonight. Thanks.
Is it main.py and status-monitor.py the only files that need to be chmod +x?
Yes those are the ones that are executable in mine.
May 23 22:46:41 RaspAIY python3[561]: [2017-05-23 22:46:41,790] INFO:speech:transcript: Radio 2
May 23 22:46:41 RaspAIY python3[561]: [2017-05-23 22:46:41,940] INFO:root:starting radio: 2
May 23 22:46:41 RaspAIY python3[561]: [2017-05-23 22:46:41,941] INFO:root:searching for: 2
May 23 22:46:41 RaspAIY python3[561]: [2017-05-23 22:46:41,941] INFO:root:stream http://a.files.bbci.co.uk/media/live/manifesto/audio/simulc
May 23 22:46:41 RaspAIY python3[561]: [2017-05-23 22:46:41,942] INFO:root:setting radio state playing
May 23 22:46:41 RaspAIY python3[561]: [2017-05-23 22:46:41,943] INFO:main:handled local command: Radio 2
May 23 22:46:41 RaspAIY python3[561]: [2017-05-23 22:46:41,944] INFO:root:resuming radio playing
May 23 22:46:41 RaspAIY python3[561]: [2017-05-23 22:46:41,946] INFO:main:ready…
May 23 22:46:42 RaspAIY python3[561]: [6e804050] httplive stream: HTTP Live Streaming (a.files.bbci.co.uk/media/live/manifesto/audio/simulca
May 23 22:46:42 RaspAIY python3[561]: [6e80d8b0] http access error: error: HTTP/1.1 403 Forbidden
May 23 22:46:42 RaspAIY python3[561]: [6e80d8b0] http access error: error: HTTP/1.0 403 Forbidden
May 23 22:46:43 RaspAIY python3[561]: [6e80d8b0] access_mms access error: error: HTTP/1.0 403 Forbidden
May 23 22:46:43 RaspAIY python3[561]: [6e804050] core stream error: no suitable access module for `http://as-hls-uk-live.akamaized.net/pool_
May 23 22:46:43 RaspAIY python3[561]: [6e804050] httplive stream error: No playable streams found in Meta playlist
May 23 22:46:43 RaspAIY python3[561]: [6e80d8b0] es demux error: cannot peek
May 23 22:46:43 RaspAIY python3[561]: [6e80d8b0] es demux error: cannot peek
May 23 22:46:43 RaspAIY python3[561]: [6e80d8b0] es demux error: cannot peek
May 23 22:46:43 RaspAIY python3[561]: [6e80d8b0] es demux error: cannot peek
May 23 22:46:43 RaspAIY python3[561]: [6e80d8b0] es demux error: cannot peek
May 23 22:46:43 RaspAIY python3[561]: [2017-05-23 22:46:43,488] INFO:main:listening…
May 23 22:46:43 RaspAIY python3[561]: [2017-05-23 22:46:43,489] INFO:main:recognizing…
May 23 22:46:43 RaspAIY python3[561]: [2017-05-23 22:46:43,490] INFO:root:pausing radio
May 23 22:46:46 RaspAIY python3[561]: [2017-05-23 22:46:46,496] INFO:speech:event_type: 1
May 23 22:46:46 RaspAIY python3[561]: [2017-05-23 22:46:46,498] INFO:main:thinking…
May 23 22:46:46 RaspAIY python3[561]: [2017-05-23 22:46:46,502] INFO:speech:transcript: play radio
May 23 22:46:47 RaspAIY python3[561]: [2017-05-23 22:46:47,058] INFO:root:starting radio: play
May 23 22:46:47 RaspAIY python3[561]: [2017-05-23 22:46:47,059] INFO:root:searching for: play
May 23 22:46:50 RaspAIY python3[561]: [2017-05-23 22:46:50,961] INFO:root:stream http://a.files.bbci.co.uk/media/live/manifesto/audio/simulc
May 23 22:46:50 RaspAIY python3[561]: [2017-05-23 22:46:50,964] INFO:root:setting radio state playing
May 23 22:46:50 RaspAIY python3[561]: [2017-05-23 22:46:50,967] INFO:main:handled local command: play radio
May 23 22:46:50 RaspAIY python3[561]: [2017-05-23 22:46:50,968] INFO:root:resuming radio playing
May 23 22:46:50 RaspAIY python3[561]: [2017-05-23 22:46:50,971] INFO:main:ready…
May 23 22:46:51 RaspAIY python3[561]: [6fa1b610] httplive stream: HTTP Live Streaming (a.files.bbci.co.uk/media/live/manifesto/audio/simulca
May 23 22:46:51 RaspAIY python3[561]: [6fa19f30] http access error: error: HTTP/1.1 403 Forbidden
May 23 22:46:52 RaspAIY python3[561]: [6fa19f30] http access error: error: HTTP/1.0 403 Forbidden
May 23 22:46:52 RaspAIY python3[561]: [6fa19f30] access_mms access error: error: HTTP/1.0 403 Forbidden
May 23 22:46:52 RaspAIY python3[561]: [6fa1b610] core stream error: no suitable access module for `http://as-hls-uk-live.akamaized.net/pool_
May 23 22:46:52 RaspAIY python3[561]: [6fa1b610] httplive stream error: No playable streams found in Meta playlist
May 23 22:46:52 RaspAIY python3[561]: [6fa19f30] es demux error: cannot peek
May 23 22:46:52 RaspAIY python3[561]: [6fa19f30] es demux error: cannot peek
May 23 22:46:52 RaspAIY python3[561]: [6fa19f30] es demux error: cannot peek
May 23 22:46:52 RaspAIY python3[561]: [6fa19f30] es demux error: cannot peek
May 23 22:46:52 RaspAIY python3[561]: [6fa19f30] es demux error: cannot peek
May 23 22:46:55 RaspAIY python3[561]: [2017-05-23 22:46:55,379] INFO:main:listening…
May 23 22:46:55 RaspAIY python3[561]: [2017-05-23 22:46:55,380] INFO:main:recognizing…
May 23 22:46:55 RaspAIY python3[561]: [2017-05-23 22:46:55,381] INFO:root:pausing radio
May 23 22:46:58 RaspAIY python3[561]: [2017-05-23 22:46:58,698] INFO:speech:event_type: 1
May 23 22:46:58 RaspAIY python3[561]: [2017-05-23 22:46:58,700] INFO:main:thinking…
May 23 22:46:58 RaspAIY python3[561]: [2017-05-23 22:46:58,704] INFO:speech:transcript: stop radio
May 23 22:46:58 RaspAIY python3[561]: [2017-05-23 22:46:58,831] INFO:root:radio stopped
May 23 22:46:58 RaspAIY python3[561]: [2017-05-23 22:46:58,833] INFO:root:setting radio state stopped
May 23 22:46:58 RaspAIY python3[561]: [2017-05-23 22:46:58,836] INFO:main:handled local command: stop radio
May 23 22:46:58 RaspAIY python3[561]: [2017-05-23 22:46:58,838] INFO:root:resuming radio stopped
May 23 22:46:58 RaspAIY python3[561]: [2017-05-23 22:46:58,841] INFO:main:ready…
So everyone is editing action.py
I was wondering if there was a way to just have 1 line that imports another py that lists the other actions you are adding so you don’t actually mess up action.py?
Have each of your added actions as a separate py file in a different directory so you keep the main for clean, then have something like action_added.py that lists each actions’ own py file?
The real solution would be to have a directory say called “plugins”. And something in action.py that integrates all the *.py files in the “plugins” folder.
And if people had a declaration at the begining of their pluginsActionExample.py file to assign a different “command” than the default one so different commands don’t clash.
I think I was wrong about my error:
● voice-recognizer.service – voice recognizer
Loaded: loaded (/lib/systemd/system/voice-recognizer.service; enabled)
Active: failed (Result: start-limit) since Wed 2017-05-24 11:46:28 PDT; 6s ago
Process: 11570 ExecStart=/home/pi/voice-recognizer-raspi/env/bin/python3 -u src/main.py (code=exited, status=1/FAILURE)
Main PID: 11570 (code=exited, status=1/FAILURE)
May 24 11:46:28 raspberrypi systemd[1]: Unit voice-recognizer.service entered failed state.
May 24 11:46:28 raspberrypi systemd[1]: voice-recognizer.service holdoff time over, scheduling restart.
May 24 11:46:28 raspberrypi systemd[1]: Stopping voice recognizer…
May 24 11:46:28 raspberrypi systemd[1]: Starting voice recognizer…
May 24 11:46:28 raspberrypi systemd[1]: voice-recognizer.service start request repeated too quickly, refusing to start.
May 24 11:46:28 raspberrypi systemd[1]: Failed to start voice recognizer.
May 24 11:46:28 raspberrypi systemd[1]: Unit voice-recognizer.service entered failed state.
That is what it says. it only happens when I use your new radio and can be fixed by replacing it back to your old radio. Any thoughts?
Thanks
I realised this afternoon that the link in the post was outdated so check you’ve got the right version. Also check that main.py is from the same version.
If you want to email me your action.py and main.py I can check them in the morning. It’s admin@ktinkerer.co.uk
I redid the three files. Did the restart. Said “Radio”, it said “Radio Search not found, playing Radio 6” but nothing is playing.
Going to install PySocks and see what happens, urllib3 requires optional dependencies.
pi@RaspAIY:~/voice-recognizer-raspi/src $ sudo journalctl -u voice-recognizer -f
— Logs begin at Sat 2017-08-12 21:55:12 PDT. —
May 24 17:56:17 RaspAIY python3[563]: [2017-05-24 17:56:17,097] INFO:main:Playing 16.4752 seconds of audio…
May 24 17:56:33 RaspAIY python3[563]: [2017-05-24 17:56:33,678] INFO:root:resuming radio stopped
May 24 17:56:33 RaspAIY python3[563]: [2017-05-24 17:56:33,680] INFO:main:ready…
May 24 18:52:04 RaspAIY systemd[1]: Stopping voice recognizer…
May 24 18:52:04 RaspAIY systemd[1]: Starting voice recognizer…
May 24 18:52:04 RaspAIY systemd[1]: Started voice recognizer.
May 24 18:52:05 RaspAIY python3[17600]: /home/pi/voice-recognizer-raspi/env/lib/python3.4/site-packages/urllib3/contrib/socks.py:37: DependencyWarning: SOCKS support in urllib3 requires the installation of optional dependencies: specifically, PySocks. For more information, see https://urllib3.readthedocs.io/en/latest/contrib.html#socks-proxies
May 24 18:52:05 RaspAIY python3[17600]: DependencyWarning
May 24 18:52:08 RaspAIY python3[17600]: [2017-05-24 18:52:08,111] INFO:audio:started recording
May 24 18:52:08 RaspAIY python3[17600]: [017a6f08] pulse audio output error: PulseAudio server connection failure: Connection refused
May 24 18:52:08 RaspAIY python3[17600]: [016c7e38] pulse audio output error: PulseAudio server connection failure: Connection refused
May 24 18:52:08 RaspAIY python3[17600]: [2017-05-24 18:52:08,695] INFO:root:setting radio state stopped
May 24 18:52:08 RaspAIY python3[17600]: [2017-05-24 18:52:08,707] INFO:main:ready…
May 24 18:52:43 RaspAIY python3[17600]: [2017-05-24 18:52:43,720] INFO:main:listening…
May 24 18:52:43 RaspAIY python3[17600]: [2017-05-24 18:52:43,724] INFO:main:recognizing…
May 24 18:52:43 RaspAIY python3[17600]: [2017-05-24 18:52:43,726] INFO:root:pausing radio
May 24 18:52:46 RaspAIY python3[17600]: [2017-05-24 18:52:46,590] INFO:speech:event_type: 1
May 24 18:52:46 RaspAIY python3[17600]: [2017-05-24 18:52:46,594] INFO:main:thinking…
May 24 18:52:46 RaspAIY python3[17600]: [2017-05-24 18:52:46,892] INFO:speech:transcript: 2 + 2
May 24 18:52:48 RaspAIY python3[17600]: [2017-05-24 18:52:48,535] INFO:main:Playing 1.7630 seconds of audio…
May 24 18:52:50 RaspAIY python3[17600]: [2017-05-24 18:52:50,425] INFO:root:resuming radio stopped
May 24 18:52:50 RaspAIY python3[17600]: [2017-05-24 18:52:50,428] INFO:main:ready…
May 24 18:52:51 RaspAIY python3[17600]: [2017-05-24 18:52:51,912] INFO:main:listening…
May 24 18:52:51 RaspAIY python3[17600]: [2017-05-24 18:52:51,914] INFO:main:recognizing…
May 24 18:52:51 RaspAIY python3[17600]: [2017-05-24 18:52:51,915] INFO:root:pausing radio
May 24 18:52:54 RaspAIY python3[17600]: [2017-05-24 18:52:54,903] INFO:speech:event_type: 1
May 24 18:52:54 RaspAIY python3[17600]: [2017-05-24 18:52:54,905] INFO:main:thinking…
May 24 18:52:54 RaspAIY python3[17600]: [2017-05-24 18:52:54,987] INFO:speech:transcript: radio
May 24 18:52:56 RaspAIY python3[17600]: [2017-05-24 18:52:56,364] INFO:root:starting radio:
May 24 18:52:56 RaspAIY python3[17600]: [2017-05-24 18:52:56,365] INFO:root:searching for:
May 24 18:53:00 RaspAIY python3[17600]: [2017-05-24 18:53:00,280] INFO:root:stream http://a.files.bbci.co.uk/media/live/manifesto/audio/simulcast/hls/uk/sbr_high/ak/bbc_6music.m3u8
May 24 18:53:00 RaspAIY python3[17600]: [2017-05-24 18:53:00,284] INFO:root:setting radio state playing
May 24 18:53:00 RaspAIY python3[17600]: [2017-05-24 18:53:00,285] INFO:main:handled local command: radio
May 24 18:53:00 RaspAIY python3[17600]: [2017-05-24 18:53:00,285] INFO:root:resuming radio playing
May 24 18:53:00 RaspAIY python3[17600]: [2017-05-24 18:53:00,289] INFO:main:ready…
May 24 18:53:01 RaspAIY python3[17600]: [6f20f3d0] httplive stream: HTTP Live Streaming (a.files.bbci.co.uk/media/live/manifesto/audio/simulcast/hls/uk/sbr_high/ak/bbc_6music.m3u8)
May 24 18:53:02 RaspAIY python3[17600]: [6f207880] http access error: error: HTTP/1.1 403 Forbidden
May 24 18:53:02 RaspAIY python3[17600]: [6f207880] http access error: error: HTTP/1.0 403 Forbidden
May 24 18:53:02 RaspAIY python3[17600]: [6f207880] access_mms access error: error: HTTP/1.0 403 Forbidden
May 24 18:53:02 RaspAIY python3[17600]: [6f20f3d0] core stream error: no suitable access module for `http://as-hls-uk-live.akamaized.net/pool_6/live/bbc_6music/bbc_6music.isml/bbc_6music-audio%3d320000.norewind.m3u8′
May 24 18:53:02 RaspAIY python3[17600]: [6f20f3d0] httplive stream error: No playable streams found in Meta playlist
May 24 18:53:02 RaspAIY python3[17600]: [6f203b68] es demux error: cannot peek
May 24 18:53:02 RaspAIY python3[17600]: [6f203b68] es demux error: cannot peek
May 24 18:53:02 RaspAIY python3[17600]: [6f203b68] es demux error: cannot peek
May 24 18:53:02 RaspAIY python3[17600]: [6f203b68] es demux error: cannot peek
May 24 18:53:02 RaspAIY python3[17600]: [6f203b68] es demux error: cannot peek
Which version of vlc is this with?
VLC media player 2.2.5 Weatherwax (revision 2.2.5-0-g9275f0fefa)
I’ve just thought, are you in the UK? I wonder if you are being blocked from accessing it as you are getting a 403 error?
I am in BC, Canada. I thought the same thing, but the other links work without the m3u8.
def get_station(self, station_name):
# replace the stream for the first line $
stations = {
‘1’: ‘http://bbcmedia.ic.llnwd.net/s$
‘2’: ‘http://bbcmedia.ic.llnwd.net/s$
‘3’: ‘http://bbcmedia.ic.llnwd.net/s$
‘4’: ‘http://bbcmedia.ic.llnwd.net/s$
‘5’: ‘http://bbcmedia.ic.llnwd.net/s$
‘6’: ‘http://bbcmedia.ic.llnwd.net/s$
‘1 extra’: ‘http://bbcmedia.ic.llnwd$
‘4 extra’: ‘http://bbcmedia.ic.llnwd$
‘nottingham’: ‘http://bbcmedia.ic.ll$
‘london’: ‘http://bbcmedia.ic.llnwd.$
‘scotland’: ‘http://bbcmedia.ic.llnw$
‘wales’: ‘http://bbcmedia.ic.llnwd.n$
‘test’: ‘http://a.files.bbci.co.uk/m$
}
return stations[station_name]
I got the stations working with different links.
Bit of googling and it sounds like the high quality links that I’ve added don’t work outside the UK. I’ll add something to my post. Thanks for the info and the links that work!
http://www.suppertime.co.uk/blogmywiki/2015/04/updated-list-of-bbc-network-radio-urls/ This site lists the URLS that I got working, I couldn’t the m3u8 ones to work.
One I have setup as “1 extra” but the voice input doesn’t seem to catch the word extra properly. Another one setup as “4 extra” and the voice input catches the I put properly.
I notice when saying “1 extra” vs “4 extra” no matter how clear I say it even I hear the word extra does seem clear enough after the 1 vs after the 4.
I found it heard 1 extra as 1xtra which I think is the actual name of the station! You can see in the logs what it has heard.
It has the following issues listening to some commands:
Wouldn’t catch this –> ‘the new screen savers’: ‘http://feeds.twit.tv/tnss.xml’,
Catches this –> ‘the new screensavers’: ‘http://feeds.twit.tv/tnss.xml’,
‘qmfm’: ‘http://www.surfmusic.de/m3u/chqm-qmfm-103-5-fm,15363.m3u’,
It cannot say qmfm, it just says q.,.,
I add one line to your radio routine to say what is is playing:
logging.info(“starting radio: ” + voice_command)
global station
try:
logging.info(“searching for: ” + voice_command)
self.say(“starting Radio ” + voice_command)
station = self.get_station(voice_command)
except KeyError:
# replace this stream with the stream for your default station
self.say(“Radio search not found. Playing BBC radio 6”)
station = ‘http://bbcmedia.ic.llnwd.net/stream/bbcmedia_6music_mf_p’
It is cool but you kind of have to memorize the commands and stations and podcast names.
Yes I had to test what it heard when I said the names and change them. It seems to consistently hear the same thing which is good.
It would be pretty easy to add a list command if you wanted to.
It would be cool add a command like “radio list” to read back the choices available because otherwise you have to memorize which ones you programmed.
Hey could recommend a good Python course, I guess online? I guess I a cut and paste programer, I understand parts of it but not all. TRS-80 Extended Basic from 1980s and Turbo Pascal from 1989 is as close to really knowing anything for sure.
I think I used O’Reilly books when I started with Python (can’t really remember!) but I am sure there must be some good online courses about now.
Thanks for this project, however I seem to be having a problem not listed above and that is everything is working fine, ask for a radio station and it detects correctly, selects the appropriate stream passes it to vlc (or at least it is calling it) but… no audio output no sound at all, sorry to say even a mouse makes more noise 🙂
Seriously
manual test of both vlc and cvlc plays audio stream so I can hear it but not when I ask the pi to play it.
Any suggestions?
What do the logs say?
I had the same problem, the player was being setup and not starting. I added a play command to the end of the run function definition and that fixed it (this would be after line 289 in action.py):
player.play()
I also had the problem of not being able to activate the trigger while playing radio stations. My solution was to detect the button and use it to pause things. This is now elegant but it works; I added this code to main.py just before the main event loop for using the google assistant (before the line that starts def process_event…. which is around line 207)
# Quick hack to pause the radio when the button is pressed (also import triggers.gpio)
off_trigger = triggers.gpio.GpioTrigger(channel=23)
off_trigger.set_callback(action.pauseActors)
off_trigger.start()
You are right about the play command being missing! It wasn’t on my local version so I’m not sure how that happened, I’ve updated it now.
Are you using the voice trigger? I tried it a couple of weeks ago and was struggling to get it working with my pause / resume methods, sounds like you’ve got a good work around.
The problem with this, I have found, is that if the volume from the radio station is too loud then Voice-recognizer cannot hear the command.
I noticed this when tuned to Radio 3 and I could still talk to the box and have it respond, as soon as I changed station to Radio 1 the unit could not longer hear the commands. I shielded the mic’s and it worked again.
Hope this is helpful
Are you using the “OK Google” trigger? I haven’t got that working on mine yet. It will pause / resume when you use the button as a trigger. Clap trigger does not work very well as it triggers itself when playing music!
Yes I am using the google assistant ‘ok google’ voice command and unless the volume is low it won’t recognize it. The workaround above works for me though if it were to go into the main source it would need to be guarded by an if statement that checks the ‘ok google’ is the active trigger.
Thank you I’ll have a look at trying it when I get chance! I too struggled to get voice commands working when the box was playing music.
Thanks for this, by adding the player.play() command fixed it.
Very greatfull as now I can proceed with with I was planning
Hi Ktinkerer, great project! I managed to get everything working but only after I removed this chunk of code:
<<<<<<>>>>>> Stashed changes
and keeping the original def do_recognition(args, recorder, recognizer, player):
I am completely new to Python, I was wondering what this section is supposed to do?
Ah I’m sorry, that’s from git not python! You did the right thing keeping the original, I’ll sort it out now.
Sorry about the delay, I’ve been on holiday.
Hi love the project can you advise me on how to change the default start volume to something like 50% thanks
The command you would need for that is
amixer -q sset Master 50%
you could insert this into the radio code using something like thissubprocess.call("amixer -q sset Master 50%", shell=True)
the only problem would be it would always be called so you wouldn’t have the option to change the volume. I’ve set up node-red and MQTT on mine and have this changing the volume so I can change it while it is playing. I’ll have to write this up as a separate blog post!Thanks for the reply I will give it a bash when I get home tonight
does this work with the most recent version of the AIY kit and OS? I’ve just set up my AIY kit which I received as few days ago (thanks Pimoroni!!) and it seems that voice-recognizer-raspi isnt referred to anymore. AIY-voice-kit-python seems to be the repository for the src folder and action.py for example is nowhere to be found… any help greatly appreciated,
p
They have totally changed it, I had a quick look at the new version this week but it didn’t seem like it recognised the “OK Google” hotword anymore? I didn’t get any further than that I’m afraid! The old version that all of the mods work with is still available on Github as the ‘master’ branch. https://github.com/google/aiyprojects-raspbian/tree/master
I replaced the VLC with MPC, mainly as I was getting some errors but also because I’d been using MPC on another porject. But this was great to have BBC radio to listen to here in the USA.
VLC media player 2.2.7 Umbrella (revision 2.2.7-0-g6e32381286)
[00869a00] pulse audio output error: PulseAudio server connection failure: Connection refused
[00855dc0] dummy interface: using the dummy interface module…
[739009b0] http access: Raw-audio server found, mp3 demuxer selected
[7370fcc0] mpgatofixed32 audio converter error: libmad error: bad main_data_begin pointer
[7370fcc0] mpgatofixed32 audio converter error: libmad error: bad main_data_begin pointer
I tried to use MPC when I first set mine up but found that I couldn’t run MPD and the voice recogniser at the same time so I gave up and moved on to VLC. I also get some pulse audio errors but it still seems to work.