2008-11-30
My computer reads me the time
I just made a shell script to make my computer read the current time. I got the idea from this blog post. This script requires festival to be installed (read the blog post). This script could be useful for common reminders (like class).
#!/bin/bash
# This script is licensed under the GNU GPL version 2 or above
# Copyright 2008 Trey Hunner
# Converts a string of two digits to words according to a use number
# Arguments: (digit string, use number)
# If the use number is 0 then the number is treated normally
# If the use number is 1 then the number is treated as an hour
# If the use number is 2 then the number is treat as a minute
convert_pair()
{
str=""
a=`echo $1 | cut -c 1`
b=`echo $1 | cut -c 2`
case $a in
9) str="ninety" ;;
8) str="eighty" ;;
7) str="seventy" ;;
6) str="sixty" ;;
5) str="fifty" ;;
4) str="forty" ;;
3) str="thirty" ;;
2) str="twenty" ;;
1) case $b in
9) str="nineteen" ;;
8) str="eighteen" ;;
7) str="seventeen" ;;
6) str="sixteen" ;;
5) str="fifteen" ;;
4) str="fourteen" ;;
3) str="thirteen" ;;
2) str="twelve" ;;
1) str="eleven" ;;
0) str="ten" ;;
esac
;;
0) if [ $b -ne 0 -a $2 -eq 2 ]; then
str="oh-"
fi ;;
esac
if [ $a -gt 1 -a $b -ne 0 ] ; then
str="$str-"
fi
if [ $a -ne 1 ]; then
case $b in
9) str=$str"nine" ;;
8) str=$str"eight" ;;
7) str=$str"seven" ;;
6) str=$str"six" ;;
5) str=$str"five" ;;
4) str=$str"four" ;;
3) str=$str"three" ;;
2) str=$str"two" ;;
1) str=$str"one" ;;
0) if [ $a -eq 0 -a $2 -ne 2 ] ; then
str="zero"
fi ;;
esac
fi
echo $str
}
H=`date '+%I'`
M=`date '+%M'`
P=`date '+%p'`
hour=$(convert_pair $H 1)
minute=$(convert_pair $M 2)
echo $hour $minute $P | festival --ttsLabels: programming
Subscribe to Posts [Atom]

