Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
# =========================================
# Makers! Implement your own actions here.
# =========================================
class playRadio(object):
def __init__(self, say, keyword):
self.say = say
self.keyword = keyword
def run(self, voice_command):
logging.info("starting " + voice_command)
self.say("tuning the radio in to " + voice_command)
if voice_command == 'Radio 1':
station = "http://bbcmedia.ic.llnwd.net/stream/bbcmedia_radio1_mf_p?s=1494265262"
elif voice_command == 'Radio 2':
station = "http://bbcmedia.ic.llnwd.net/stream/bbcmedia_radio2_mf_p?s=1494265194"
elif voice_command == 'Radio 3':
station = "http://bbcmedia.ic.llnwd.net/stream/bbcmedia_radio3_mf_p?s=1494265402"
elif voice_command == 'Radio 4':
station = "http://bbcmedia.ic.llnwd.net/stream/bbcmedia_radio4fm_mf_p?s=1494265402"
elif voice_command == 'Radio 5':
station = "http://open.live.bbc.co.uk/mediaselector/5/redir/version/2.0/mediaset/http-icy-mp3-a-stream/proto/http/vpid/bbc_radio_five_live"
elif voice_command == 'Radio 6':
station = "http://bbcmedia.ic.llnwd.net/stream/bbcmedia_6music_mf_p?s=1494265223"
elif voice_command == 'Radio 1Xtra':
station = "http://bbcmedia.ic.llnwd.net/stream/bbcmedia_radio1xtra_mf_p?s=1494265403"
elif voice_command == 'Radio 4 Extra':
station = "http://bbcmedia.ic.llnwd.net/stream/bbcmedia_radio4extra_mf_q?s=1494265404"
else:
station = "http://bbcmedia.ic.llnwd.net/stream/bbcmedia_6music_mf_p?s=1494265223"
p = subprocess.Popen(["/usr/bin/cvlc",station],stdin=subprocess.PIPE,stdout=subprocess.PIPE)
p.poll()
gpio.setmode(gpio.BCM)
gpio.setup(23, gpio.IN)
while True:
if gpio.input(23):
logging.info("stopping radio")
p.kill()
break
time.sleep(0.1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.