Skip to content

Instantly share code, notes, and snippets.

@mschuerig
Last active August 29, 2015 14:02
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 mschuerig/7e1628f03ec6e6f6441d to your computer and use it in GitHub Desktop.
Save mschuerig/7e1628f03ec6e6f6441d to your computer and use it in GitHub Desktop.
Announce (speak) the song currently playing in MPD
#! /bin/sh -e
# Requires https://github.com/profh/romanic
# gem install romanic
device="default:CARD=X20"
lock="/run/lock/mpd-announce"
dotlockfile -r 0 -p "$lock" || exit 0
trap "dotlockfile -p -u \"$lock\"" EXIT TERM INT
current=$( mpc "$@" current )
test -n "$current" || exit 0
#current=$( \
# echo "$current" | \
# sed -e 's/op\. \?\([0-9][0-9]*\)/Opus \1/ig' \
# -e 's/no\. \?\([0-9][0-9]*\)/Number \1/ig;s/-//g' \
#)
current=$( \
echo "$current" | \
ruby -rromanic -p \
-e '$_.gsub!(/op\.\s?(\d)+/i, "Opus \\1")' \
-e '$_.gsub!(/no\.\s?(\d)+/i, "Number \\1")' \
-e '$_.gsub!(/\b[ivxlc]+\b/i) { |n| n.from_roman || n }' \
)
echo "$current" | \
espeak -s 140 -v en --stdout | \
aplay -q -D"$device" -
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment