forked from EtiennePerot/misc-scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
announce-current-song.sh
executable file
·38 lines (36 loc) · 1.13 KB
/
announce-current-song.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#!/usr/bin/env bash
set -euxo pipefail
lastTrack=''
fifo='/tmp/announce-current-song.fifo.wav'
rm -f "$fifo" || true
mkfifo "$fifo"
while true; do
sleep 10
# Get title and artist of currently-playing track.
meta="$(qdbus org.kde.amarok /Player org.freedesktop.MediaPlayer.GetMetadata || true)"
if ! echo "$meta" | grep -qP '^artist:'; then
lastTrack=''
continue # Most likely not playing audio right now.
fi
artist="$(echo "$meta" | grep -P '^artist:' | cut -d' ' -f2-)"
title="$(echo "$meta" | grep -P '^title:' | cut -d' ' -f2-)"
currentTrack="$title by $artist"
if [ "$currentTrack" == "$lastTrack" ]; then
continue # Already announced.
fi
# Fade out current music volume so that the track name can be announced.
for i in $(seq 100 -5 30); do
qdbus org.kde.amarok /Player VolumeSet "$i"
sleep 0.075
done
# Write text-to-speech data to FIFO.
pico2wave --wave="$fifo" "Current track is $currentTrack." &
# Play text-to-speech data from FIFO to speakers.
paplay "$fifo"
# Raise music volume back up.
for i in $(seq 30 5 100); do
qdbus org.kde.amarok /Player VolumeSet "$i"
sleep 0.075
done
lastTrack="$currentTrack"
done