Using Python to Interrupt Media with Preset Instructions

The 'What'

This script can play back a piece of audio or video, and will pause its playback to say out loud (and if a video, show) an instruction to follow.

The 'Why'

I was doing 30 minute audio lessons learning a foreign language, and wanted to do some muscle stretching during these sessions. Thinking up/reading which stretch to do next was too distracting to do concurrently with the material, so I glued together a few functionalities with this script to pause media playback and tell me which stretch to do and when.

The 'How'

A Python3 script using python-vlc and pyttsx3 (which may require eSpeak). Since VLC is the media player being used, almost any audio or video file can be used as the underlying media being played. User supplies an input file with the instructions to be used, in a rudimentary format of

<time (in seconds) of instruction> <instruction to be read>
on each line. The script will play a command-line supplied media file, and at the times dictated, pause playback, and speak out loud the instruction. For video playback, it will also display the instruction super imposed on the video, and display a time counter in the corner between instructions.

The Output

Below you can see some screenshots of when this script is used with video media, both paysed during an instruction and in normal playback.

instruction overlaying video  timestamp overlaying the video

The Code

Click here to view the script.

Assumptions and Known Shortcomings

There are lots of settings and options/configurations that are hardcoded into this script that could be command line options or in a settings file. From properties of the voice speed and volume in the pyttsx3 portion, to playback display and speed and more in VLC, to whether or not to display subtitles, and so on.

Possible Expansion

Could add Spotify as a supported playback platform using something like Spotipy. Could also make this script or a variant of it work with YouTube or NetFlix. As it stands, however, this script fulfills my needs so its doubtful I will be upgrading it.