Skip to content

Instantly share code, notes, and snippets.

@bertm
Created March 10, 2016 18:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bertm/1647a29e61a0779cada0 to your computer and use it in GitHub Desktop.
Save bertm/1647a29e61a0779cada0 to your computer and use it in GitHub Desktop.
MP3 stream of spoken time
#!/bin/bash
# Outputs a continuous MP3 stream with spoken current time on stdout.
# Requirements: text2wave (from festival) and ffmpeg (some old version)
# Speak interval. Must be higher than the length of the spoken time.
INTERVAL=5
RATE=48000
TS=$(($(date +%s) + $INTERVAL))
BYTESPERSPEAK=$((2 * $RATE * $INTERVAL)) # S16_LE
TMP=$(tempfile)
while true
do
date -d @$TS +%-H:%M:%S | text2wave -otype raw -f $RATE > $TMP
LEN=$(wc -c < $TMP)
cat $TMP
head -c $(($BYTESPERSPEAK - $LEN)) /dev/zero
TS=$(($TS + $INTERVAL))
done | ffmpeg -v error -f s16le -ar $RATE -ac 1 -i - -f mp3 -ar 11025 -ab 8000 -
rm $TMP
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment