[ Not logged! Log in ]
Ulteo :: View topic - A speaking clock shell script using festival, date, and cron
Ulteo login (email) : Password :
Ulteo Forum Index » Scripting Stuff

Post new topic   Reply to topic
A speaking clock shell script using festival, date, and cron
View previous topic :: View next topic  
Author Message
Ulteo Newbie
Ulteo Newbie

Joined: 14 Aug 2006
Posts: 2
Location: Toledo, Ohio, USA

PostPosted: Tue Oct 17, 2006 7:33 am   A speaking clock shell script using festival, date, and cron
I present this script which I built to solve a problem. I get involved, and when I get involved I forget about the passage of time. Pop up windows are intrusive, and I forget to look at the clock in the tray. I needed something to get my attention without interruption, and remind me that time is passing. Back when I used M.S. Windows (circa 1998), I had a speaking clock program that ran in memory, and spoke the time each quarter hour, but it used a lot of resources even when it was just waiting to speak. A speaking clock for Linux was what I wanted, but I could not find one. While searching the WEB, I did find the Festival Speech Synthesis System at the University of Edinburgh. Festival is a command line tool which essentially can 'read' text from standard input (or a pipe), and 'say' it through the sound system.

To make a long story short, I decided to make a shell script to get the current system time and pass it to festival. I run my script each quarter hour with cron. The end result is much like the speaking clock I had back in Windows, but better since my clock only runs when it speaks.

You can copy and paste this script into a text editor, then save it as spktime in the location of your choice. If you want to make it available only to a single user, you can put it in that user's ~/bin directory. If you want to make it available system wide, you can save it in /usr/bin (as root). In either case, remember to make it executable with 'chmod +x ' (no quotes).

To 'speak' the system time each quarter hour where spktime is placed in ~/bin, you can add this line to your crontab:

0,15,30,45 * * * * ~/bin/spktime

or if you placed spktime in /usr/bin, use this line:

0,15,30,45 * * * * /usr/bin/spktime

Here is the script:


# third revision - version 0.3.5 - 2002,12,12
# spktime - script to use festival speech synthesis
# system to output current time to the sound system.

# Created by Ernest N. Wilcox Jr.
# I can be contacted at

# This script is released under the GPL v 2 as is.
# I accept no liability if you choose to use it.
# If you choose to improve my script, and make
# your changes public, you must do the following:
# 1. include my comments.
# 2. identify yourself,
# 3. note your changes under these comments.
# 4. provide contact information

# To speak the current time each quarter hour
# save this script as spktime in your ~/bin directory
# and add the following line in your crontab:

# 0,15,30,45 * * * * ~/bin/spktime

# This is the end of required comments.
# now to the real job Smile.

# Set up a variable to hold the current minute
# of the hour using the date command:
MIN=$(date +"%M")

# And another to hold the current Hour:
HR=$(date +"%l")

# A third to hold some introduction text so I know
# I am hearing the current time:
INTRO="The time is, "

# Use a case statement to change the minute
# number to the equivalent word, but make the
# zero minute "o'clock". Handle all sixty minutes
# of the hour so this works correctly for any time.

case $MIN in
"00") MIN="o'clock";;
"01") MIN="Oh - one";;
"02") MIN="Oh - two";;
"03") MIN="Oh - three";;
"04") MIN="Oh - four";;
"05") MIN="Oh - five";;
"06") MIN="Oh - six";;
"07") MIN="Oh - seven";;
"08") MIN="Oh - eight";;
"09") MIN="Oh - nine";;
"10") MIN="ten";;
"11") MIN="eleven";;
"12") MIN="twelve";;
"13") MIN="thirteen";;
"14") MIN="fourteen";;
"15") MIN="fifteen";;
"16") MIN="sixteen";;
"17") MIN="seventeen";;
"18") MIN="eighteen";;
"19") MIN="nineteen";;
"20") MIN="twenty";;
"21") MIN="twenty one";;
"22") MIN="twenty two";;
"23") MIN="twenty three";;
"24") MIN="twenty four";;
"25") MIN="twenty five";;
"26") MIN="twenty six";;
"27") MIN="twenty seven";;
"28") MIN="twenty eight";;
"29") MIN="twenty nine";;
"30") MIN="thirty";;
"31") MIN="thirty one";;
"32") MIN="thirty two";;
"33") MIN="thirty three";;
"34") MIN="thirty four";;
"35") MIN="thirty five";;
"36") MIN="thirty six";;
"37") MIN="thirty seven";;
"38") MIN="thirty eight";;
"39") MIN="thirty nine";;
"40") MIN="forty";;
"41") MIN="forty one";;
"42") MIN="forty two";;
"43") MIN="forty three";;
"44") MIN="forty four";;
"45") MIN="forty five";;
"46") MIN="forty six";;
"47") MIN="forty seven";;
"48") MIN="forty eight";;
"49") MIN="forty nine";;
"50") MIN="fifty";;
"51") MIN="fifty one";;
"52") MIN="fifty two";;
"53") MIN="fifty three";;
"54") MIN="fifty four";;
"55") MIN="fifty five";;
"56") MIN="fifty six";;
"57") MIN="fifty seven";;
"58") MIN="fifty eight";;
"59") MIN="fifty nine";;
*) echo "error with minute $MIN" | festival --tts;;

# Use another case statement to do the following:
# Use the echo command to assemble the output
# text for the current time statement, change the
# number for the current hour to the equivalent
# word, and pipe the result to festival.

case $HR in
" 1") echo $INTRO "one, $MIN" | festival --tts;;
" 2") echo $INTRO "two, $MIN" | festival --tts;;
" 3") echo $INTRO "three, $MIN" | festival --tts;;
" 4") echo $INTRO "four, $MIN" | festival --tts;;
" 5") echo $INTRO "five, $MIN" | festival --tts;;
" 6") echo $INTRO "six, $MIN" | festival --tts;;
" 7") echo $INTRO "seven, $MIN" | festival --tts;;
" 8") echo $INTRO "eight, $MIN" | festival --tts;;
" 9") echo $INTRO "nine, $MIN" | festival --tts;;
"10") echo $INTRO "ten, $MIN" | festival --tts;;
"11") echo $INTRO "eleven, $MIN" | festival --tts;;
"12") echo $INTRO "twelve, $MIN" | festival --tts;;
*) echo "error with hour $HR and minute $MIN" | festival --tts;;

# end
Ernie Registered Linux User 247790
ICQ 41060744
Back to top View user's profile Send private message ICQ Number Reply with quote
Ulteo Admin
Ulteo Admin

Joined: 20 May 2006
Posts: 83
Location: Iowa, USA

PostPosted: Sat Oct 21, 2006 11:03 pm  
Very cool Smile
USA Linux Users Group | BashScripts | OpenSUSE | pastebin.ulteo.us
Back to top View user's profile Send private message Visit poster's website Reply with quote
Display posts from previous:   
Post new topic   Reply to topic    Ulteo Forum Index » Scripting Stuff All times are GMT
Page 1 of 1

Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum