Talking Clock in Ubuntu

19Sep10

I got envious of Fefi’s Macbook which hourly reads the time out loud. “It’s eleven o’clock”, his laptop calls out during meetings. I wanted to be periodically reminded of the time as well, so I searched for a suitable software for Ubuntu.

I didn’t find a talking clock package, sadly. But I found several alternative alarm clocks (Alarm Clock, saytime, Amarok/Rhythmbox plugin, etc.) which can play out a custom sound. Some people in ubuntuforums.org recommended using espeak (voice sounded too mechanical) or festival (large install) to read out the time, but there were always some problems. I was too lazy to program myself, so I was looking for a quick install, but searching for one is eating up my time more than if I just did the scripting myself. So I decided to make use of cron instead, and some bash scripting to get the job done. Now, I have a “lady” reminding me of the time every hour!

So, here’s what you need to do:
Disclaimer: Scripts done for my personal use. Use at your own risk. :P

  1. Download the voice files. I found mine (I used AT&T Audrey) from Steve’s Talking Clock.
  2. Concatenate the files to form your alarms. I used sox to concatenate its.wav {time}.wav and {am/pm}.wav. So mine says “It’s 9PM.” You can use and modify the generate_voice.sh if you want a different alarm format. The files will be stored in .clockvoices by default, if not specified during the call.

    #!/bin/bash

    voicepath=${HOME}/.clockvoice
    command="sox its.wav"

    if [ $# -ne 0 ]; then
      if [ $1="--help" ]; then
        echo "Usage: generate_voice.sh "
        echo "Make sure to run this while in the directory of voice files."
        exit
      else
        voicepath=$1
      fi
    fi

    echo Saving in ${voicepath}...

    for j in 0 1; do
      for i in `seq 1 12`; do
        period="am"
        if [ $j -eq 1 ]; then
          period="pm"
        fi

        fname=$((i%12+j*12))
        if [ $fname -lt 10 ]; then
          fname=0$fname
        fi
        `$command $i.wav $period.wav ${voicepath}/${fname}00.wav`
      done
    done

  3. Write the bash script to play out the proper file according to the time. See readtime.sh. This will be the script that cron will execute hourly.

    #!/bin/bash
    # readtime.sh

    voicepath=${HOME}/.clockvoice
    hour=`date +%H`

    if [ $# -ne 0 ]; then
      voicepath=$1
    fi

    play ${voicepath}/${hour}00.wav

  4. Set your cron’s schedule by typing crontab -e Add an entry like so: 0 * * * * {absolute_location_of_readtime.sh}

That’s about it! Enjoy! :D

Advertisement


No Responses Yet to “Talking Clock in Ubuntu”

  1. Leave a Comment

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s


Follow

Get every new post delivered to your Inbox.