Bay 12 Games Forum

Please login or register.

Login with username, password and session length
Advanced search  

Author Topic: (linux) espeak sound output  (Read 683 times)

roggenschrotbrot

  • Escaped Lunatic
    • View Profile
(linux) espeak sound output
« on: March 29, 2011, 03:36:47 pm »

hi there. while clearly not a mod i wanted to share my rather unoptimized bash script for gamelog display and espeak audio output. while runing it prints out new lines added to your gamelog and, after checking them against a blacklist, voices them using espeak (which you may have to install depending on your distribution).

Code: [Select]
#!/bin/sh
#input paths. the blacklist file is used to forbid certain log entrys from sound output and contains the words you want to check for.  if the message contains a blacklisted word it will be displayed but not spoken
GAMELOG=~/Spiele/dwarffortress/df_linux/gamelog.txt
BLACKLIST=~/Spiele/dwarffortress/df_linux/dwarfspeak-blacklist
clear
#set our workfiles to the current log file so we don't get spamed with old messages
cp $GAMELOG $GAMELOG.tmp
cp $GAMELOG.tmp $GAMELOG.diff

while true; do
cp $GAMELOG $GAMELOG.tmp
TEXT=$(diff $GAMELOG.diff $GAMELOG.tmp | grep ">")
cp $GAMELOG.tmp $GAMELOG.diff
#did the gamelog change?
if [ -n "$TEXT" ]; then
#if it changed print a timestamp
echo "==="$(date +%H:%M:%S)"==="
#print the changed lines
echo $TEXT | sed -e "s/> //" -e "s/> /\n/g"
#remove the lines containing blacklisted words
for X in $(cat $BLACKLIST)
do
TEXT=$(echo $TEXT | egrep -v $X)
done
#send everything to espeak. the option "--stdout | aplay -q" fixes some playback issues with pulseaudio and could be redundant on your system
echo $TEXT | sed -e "s/> /\n/g" -e "s/\*//g" -e "s/x[0-9]+//g" | espeak -v en --stdout | aplay -q
else
#if there are no new messages we can wait some time before checking again
sleep 10
fi

done

example blacklist:
Code: [Select]
masterpiece
has.become

edit: fixed a regexp
« Last Edit: March 29, 2011, 04:48:00 pm by roggenschrotbrot »
Logged