Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Motivational Speech Alarm Clock with Raspberry Pi
# Edit this file to introduce tasks to be run by cron.
#
# Each task to run has to be defined through a single line
# indicating with different fields when the task will be run
# and what command to run for the task
#
# To define the time you can provide concrete values for
# minute (m), hour (h), day of month (dom), month (mon),
# and day of week (dow) or use '*' in these fields (for 'any').#
# Notice that tasks will be started based on the cron's system
# daemon's notion of time and timezones.
#
# Output of the crontab jobs (including errors) is sent through
# email to the user the crontab file belongs to (unless redirected).
#
# For example, you can run a backup of all your user accounts
# at 5 a.m every week with:
# 0 5 * * 1 tar -zcf /var/backups/home.tgz /home/
#
# For more information see the manual pages of crontab(5) and cron(8)
#
# m h dom mon dow command
30 6 * * 1,2,3,4,5,6 /home/kirsle/playlist.sh
#!/bin/bash
echo Wait an hour to kill omxplayer
sleep 3600
/usr/bin/killall playlist.sh
/usr/bin/killall omxplayer
/usr/bin/killall omxplayer.bin

Motivational Speech Alarm Clock

This is the code I used to make an alarm clock out of a Raspberry Pi (model 1 B+, 512MB RAM) that plays motivational speeches at 6:30 in the morning to get my ass out of bed.

At first I was using a CLI YouTube client, but it would hang after a while due to not running on an interactive console (being launched by crond), and the audio support on Pi's have always been somewhat flaky.

I ended up using youtube-dl to pre-download a playlist and using omxplayer for its hardware-accelerated decoding support. Works pretty well, except omxplayer has no support for things like "playlists" or "shuffling" so I needed some bash scripts to help me out.

Download a Playlist

Example:

$ youtube-dl --ignore-errors 'https://www.youtube.com/watch?v=v13H1vVzW0U&list=PL_jAJinh0XEdy53PBxGTTo-9nGxfkzSS9'

Then I moved all the *.mkv files to a flash drive attached to the Pi.

#!/bin/bash
# Configure this to your folder full of speeches.
VIDEOPATH="/mnt/cruzer/speeches"
# This makes the alarm clock stop after 1 hour, could probably
# have been defined as a bash function, but is a separate script
# here. The path would have to change for your $HOME.
/home/kirsle/killall.sh &
# Shuffle the file list and run them in series with omxplayer
IFS=$(echo -en "\n\b")
for file in $(ls -1 $VIDEOPATH/* | sort -R); do
/usr/bin/omxplayer --no-keys "$file"
done
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.