#!/bin/bash

# lessbasic.sh - a talking clock using voice samples (less basic version)
# more information available at http://www.jumpstation.co.uk/scripts/talkingclock/

# no processing required
function sayHours() {
  wavplay $1.wav
}

# no processing required
function sayAMPM() {
  wavplay $1.wav
}

# have to split the number and deal with 00-09,10-19, then 20-59
function sayMins() {
  tens=${1:0:1}
  units=${1:1:1}
  # check length
  if [ ${#units} = 0   ]; then
    units=$tens
    tens="0"
  fi
  if [ $tens -lt 1 ]; then
    wavplay $tens.wav
    wavplay $units.wav
  elif [ $tens -lt 2 ]; then
    wavplay $1.wav
  else
    tens=$tens"0"
    wavplay $tens.wav
    if [ $units -gt 0 ]; then
      wavplay $units.wav
    fi
  fi
}

# use the sox play command to reproduce sound
function wavplay() {
  play $1
}

hours=`date +"%-l"`
sayHours $hours
mins=`date +"%-M"` 
sayMins $mins
ampm=`date +"%-P"` 
sayAMPM $ampm
