Major changes in talking-clock, settings moved to XDG_CONFIG_HOME/talking-clock/talking-clockrc fixed a bug with numbers.
This commit is contained in:
parent
b228ffe082
commit
9b63b3da42
22
README.md
22
README.md
@ -1,5 +1,9 @@
|
||||
talking-clock
|
||||
=============
|
||||
|
||||
A highly configurable clock written in bash with soundpack and voice options.
|
||||
Written by Storm Dragon
|
||||
Released under the terms of the WTFPL: http://wtfpl.net, or see the included LICENSE file.
|
||||
|
||||
talking-clock can chime and/or announce the time when called usually by cron. It is highly configurable. It can be set to chime every hour, quarter, hour or half hour. For instructions on editing the crontab file see man crontab. Here are some suggested entries:
|
||||
#chime every hour between 10:00AM and 10:00PM
|
||||
@ -18,15 +22,12 @@ ogg123 -q
|
||||
or
|
||||
paplay
|
||||
Note that with the ogg123 command the aplay command is used for the pico voice. Aplay will not work for the rest of the commands because it does not play ogg files.
|
||||
-b --bell Set path to the sound used for hourly chimes.
|
||||
-c --nochime Turn off chimes.
|
||||
-n --nospeak turn off spoken time.
|
||||
-p --prepend Set the path to a sound that should prepend chimes.
|
||||
-q --quarterhour Set the path to the sound for quarter-hour chimes.
|
||||
-s --soundpack Set path to soundpack. Sound packs should be in ogg format and contain 1.ogg, 2.ogg, ... 11.ogg, 12.ogg and 15.ogg, 30.ogg, and 45.ogg for the quarter-hour chimes.
|
||||
-t --torify anonymously get your current temperature, used with -z --zipcode.
|
||||
-v --voice Select voice. Default is espeak other options are
|
||||
cepstral, espeak, festival, flite, flite_time pico, speech-dispatcher and custom.
|
||||
cepstral, espeak, festival, flite, flite_time googletts (requires the translate-shell package), pico, speech-dispatcher and custom.
|
||||
To set a custom voice enter the command as in:
|
||||
-v 'espeak -v en-us+klatt2'
|
||||
zipcode and flite_time are incompatable. If you have zipcode set the temperature will not be read while using flite_time.
|
||||
@ -34,15 +35,13 @@ zipcode and flite_time are incompatable. If you have zipcode set the temperature
|
||||
|
||||
talking clock can also read settings from the following files?
|
||||
/etc/talking-clockrc global settings
|
||||
~/.talking-clockrc
|
||||
XDG_CONFIG_HOME/talking-clock/talking-clockrc
|
||||
(Usually XDG_CONFIG_HOME is ~/.config)
|
||||
Settings for individual users. If both files exist the user specific settings will be used. Command line arguments are considered all powerful and will override all others.
|
||||
|
||||
Configuration files should be written as command=setting. Here is an example of a configuration file:
|
||||
bell-/home/USER/hourbell.ogg
|
||||
format=24
|
||||
quarter=/home/USER/clocksounds/quarterhour.ogg
|
||||
sound=play -q
|
||||
prepend=/home/USER/big-ben.ogg
|
||||
soundpack=/home/USER/thunderstorm
|
||||
chime=true
|
||||
speak=true
|
||||
@ -52,8 +51,9 @@ Soundpack should be the path to a directory. Do not include the trailing / talki
|
||||
voice=espeak -v en-us+klatt2 -s 300
|
||||
Be careful when using custom voice commands, if it is not valid the program will not work. You do not have to specify parameters for voice commands if you want to use the defaults. You can use voice=espeak (this is the default), voice=cepstral, voice=speech-dispatcher, voice=pico, or voice=festival.
|
||||
|
||||
Creating soundpacks is very simple. Make a directory named anything you wish, thunderstorm for example, and place files inside it. The naming scheme for soundpack files follows the hours 1 through 12 and quarter hours 15, 30, 45. Each sound file must be in .ogg format. So, your directory will contain 1.ogg, 2.ogg, ... 12.ogg, 15.ogg, 30.ogg, and 45.ogg. To download or submit soundpacks go to:
|
||||
Creating soundpacks is very simple. Make a directory named anything you wish, thunderstorm for example, and place files inside it. The naming scheme for soundpack files follows the hours 1 through 12 and quarter hours 15, 30, 45. Each sound file must be in .ogg format. So, your directory will contain 1.ogg, 2.ogg, ... 12.ogg, 15.ogg, 30.ogg, and 45.ogg. If hourly chimes sound the same, use a bell for example, just name the chime bell.ogg. If hourly chimes should be prepended with a sound, then name the sound prepend.ogg, will play at each hour, before the chimes.To download or submit soundpacks go to:
|
||||
http://www.stormdragon.us/talking-clock/
|
||||
|
||||
If you wish to contact me you can find me on Twitter as @stormdragon2976. Also don't forget to check out my blog located at:
|
||||
http://www.stormdragon.us/
|
||||
If you wish to contact me you can find me on GNU Social as @storm@social.stormdragon.tk. Also don't forget to check out my blog located at:
|
||||
http://www.stormdragon.tk/
|
||||
I can also usually be found on irc.netwirc.tk in channel #talkingarch
|
||||
|
@ -4,6 +4,30 @@
|
||||
#project first created on Wednesday, March 23, 2011
|
||||
#license WTFPL: http://wtfpl.net
|
||||
|
||||
display_help()
|
||||
{
|
||||
cat << EOF
|
||||
Talking-clock by Storm Dragon
|
||||
Talking-clock accepts the following arguments:
|
||||
--cron number:
|
||||
If you use --cron the only valid entry is a number following it. 1 will cause the clock to chime every hour, 2 every
|
||||
half-hour, 4 every quarter, and anything else will delete your existing settings if they exist.
|
||||
-a --audio Command for playing sound. The default is play -q provided from the sox package.
|
||||
-c --nochime Turn off chimes.
|
||||
-f --format: 12 or 24 hour format. Default is 12 hour time.
|
||||
-n --nospeak turn off spoken time.
|
||||
-s --soundpack Set path to soundpack. Sound packs should be in ogg format and contain 1.ogg, 2.ogg, ... 11.ogg, 12.ogg and
|
||||
15, 30, and 45.oggfor the quarter-hour chimes.
|
||||
-v --voice Select voice. Default is espeak other options are
|
||||
cepstral, espeak, festival, pico, speech-dispatcher and custom.
|
||||
To set a custom voice enter the command as in:
|
||||
-v 'espeak -v en-us+klatt2'
|
||||
-t --torify retrieve temperature anonymously using torify, used with -z --zipcode
|
||||
-z --zipcode postal code Used for current temperature, may not be available inn all areas.
|
||||
For complete information read the README located at /usr/share/talking-clock/README"
|
||||
EOF
|
||||
}
|
||||
|
||||
number_to_text()
|
||||
{
|
||||
# If the first argument is not numeric, then it is the return variable.
|
||||
@ -12,6 +36,7 @@ number_to_text()
|
||||
shift
|
||||
fi
|
||||
local number=$1
|
||||
local digit
|
||||
# Check for negative numbers.
|
||||
if [ "${number:0:1}" = "-" ]; then
|
||||
local textNumber="negative "
|
||||
@ -30,33 +55,43 @@ number_to_text()
|
||||
;;
|
||||
10)
|
||||
textNumber="${textNumber}ten"
|
||||
break
|
||||
;;
|
||||
11)
|
||||
textNumber="${textNumber}eleven"
|
||||
break
|
||||
;;
|
||||
12)
|
||||
textNumber="${textNumber}twelve"
|
||||
break
|
||||
;;
|
||||
13)
|
||||
textNumber="${textNumber}thirteen"
|
||||
break
|
||||
;;
|
||||
14)
|
||||
textNumber="${textNumber}fourteen"
|
||||
break
|
||||
;;
|
||||
15)
|
||||
textNumber="${textNumber}fifteen"
|
||||
break
|
||||
;;
|
||||
16)
|
||||
textNumber="${textNumber}sixteen"
|
||||
break
|
||||
;;
|
||||
17)
|
||||
textNumber="${textNumber}seventeen"
|
||||
break
|
||||
;;
|
||||
18)
|
||||
textNumber="${textNumber}eightteen"
|
||||
break
|
||||
;;
|
||||
19)
|
||||
textNumber="${textNumber}nineteen"
|
||||
break
|
||||
;;
|
||||
2*)
|
||||
textNumber="${textNumber}twenty"
|
||||
@ -94,11 +129,18 @@ number_to_text()
|
||||
textNumber="${textNumber}-"
|
||||
fi
|
||||
fi
|
||||
# Remove digits from the number that have already been processed.
|
||||
if [ ${#number} -eq 2 -a $number -lt 20 ]; then
|
||||
number="${number:2}"
|
||||
fi
|
||||
case ${number:0:1} in
|
||||
# Process the correct digit based on number length.
|
||||
case ${#number} in
|
||||
3)
|
||||
digit=${number:0:1}
|
||||
;;
|
||||
2)
|
||||
digit=${number:$((${#number} - 1)):1}
|
||||
;;
|
||||
1)
|
||||
digit=${number:$((${#number} - 1)):1}
|
||||
esac
|
||||
case $digit in
|
||||
1)
|
||||
textNumber="${textNumber}one"
|
||||
;;
|
||||
@ -210,92 +252,27 @@ if [ "$1" == "--cron" ] ; then
|
||||
fi
|
||||
|
||||
#initialize variables
|
||||
xdgPath="${XDG_CONFIG_HOME:-$HOME/.config}"
|
||||
#Check for settings files in order of importants
|
||||
if [ -f "$xdgPath/talking-clock/talking-clockrc" ] ; then
|
||||
#Read from local settings
|
||||
source "$xdgPath/talking-clock/talking-clockrc"
|
||||
elif [ -f "/etc/talking-clockrc" ] ; then
|
||||
#Read from global settings
|
||||
source "/etc/talking-clockrc"
|
||||
fi
|
||||
hour=$(date +'%-l')
|
||||
minute=$(date +'%-M')
|
||||
timeOfDay=$(date +'%p' | sed 's/AM/A M/')
|
||||
#Default sound to play on half hour *:30
|
||||
prependSound="/usr/share/talking-clock/prepend.ogg"
|
||||
quarterHourChime="/usr/share/talking-clock/15.ogg"
|
||||
#Default sound to play on hours
|
||||
hourChime="/usr/share/talking-clock/bell.ogg"
|
||||
#play chimes?
|
||||
chime="true"
|
||||
chime="${chime:-true}"
|
||||
#command used to play sounds
|
||||
soundCommand="play -qV0"
|
||||
soundCommand="${sound:-play -qV0}"
|
||||
#default voice for speaking time is espeak
|
||||
voice="espeak"
|
||||
voice="${voice:-espeak -v en-us -a 150}"
|
||||
#should the time be spoken?
|
||||
speakTime="true"
|
||||
|
||||
#Check for settings files in order of importants
|
||||
if [ -f "$HOME/.talking-clockrc" ] ; then
|
||||
#Read from local settings
|
||||
confFile="$HOME/.talking-clockrc"
|
||||
elif [ -f "/etc/talking-clockrc" ] ; then
|
||||
#Read from global settings
|
||||
confFile="/etc/talking-clockrc"
|
||||
fi
|
||||
|
||||
#read from configuration file if it exists
|
||||
if [ -n "$confFile" ] ; then
|
||||
#use varCheck to test if the variable is set in the file
|
||||
#if it is, set it to the correct variable, if not use the default.
|
||||
#check for 24 hour time format
|
||||
varCheck="$(grep -i '^format=24' "$confFile")"
|
||||
if [ -n "$varCheck" ] ; then
|
||||
format="24"
|
||||
fi
|
||||
#check for hour chime in file
|
||||
varCheck=$(grep -i '^bell=' "$confFile" | cut -d = -f 2)
|
||||
if [ -n "$varCheck" ] ; then
|
||||
hourChime="$varCheck"
|
||||
fi
|
||||
#check for quarter-hour chime in file
|
||||
varCheck=$(grep -i '^quarter=' "$confFile" | cut -d = -f 2)
|
||||
if [ -n "$varCheck" ] ; then
|
||||
quarterHourChime="$varCheck"
|
||||
fi
|
||||
#check for prepended sound
|
||||
varCheck=$(grep -i '^prepend=' "$confFile" | cut -d = -f 2)
|
||||
if [ -n "$varCheck" ] ; then
|
||||
prependSound="$varCheck"
|
||||
fi
|
||||
#check for command to play sounds
|
||||
varCheck=$(grep -i '^sound=' "$confFile" | cut -d = -f 2)
|
||||
if [ -n "$varCheck" ] ; then
|
||||
soundCommand="$varCheck"
|
||||
fi
|
||||
#get the voice used to speak time
|
||||
varCheck=$(grep -i '^voice=' "$confFile" | cut -d = -f 2 | tr -d "&;<>\"|\$\)\(")
|
||||
if [ -n "$varCheck" ] ; then
|
||||
voice="$varCheck"
|
||||
fi
|
||||
#check for zipcode for current temperature
|
||||
varCheck=$(grep -i '^zipcode=' "$confFile" | cut -d = -f 2)
|
||||
if [ -n "$varCheck" ] ; then
|
||||
zipcode="$varCheck"
|
||||
fi
|
||||
#check for soundpack directory
|
||||
varCheck=$(grep -i '^soundpack=' "$confFile" | cut -d = -f 2)
|
||||
if [ -n "$varCheck" ] ; then
|
||||
soundPack="$varCheck"
|
||||
fi
|
||||
#Check for tor mode
|
||||
varCheck=$(grep -i '^torify=' "$confFile" | cut -d = -f 2)
|
||||
if [ -n "$varCheck" ] ; then
|
||||
torify="$varCheck"
|
||||
fi
|
||||
#Check for no speech mode
|
||||
varCheck=$(grep -i '^speak=' "$confFile" | cut -d = -f 2)
|
||||
if [ -n "$varCheck" ] ; then
|
||||
speakTime="$varCheck"
|
||||
fi
|
||||
#Check for no chime mode
|
||||
varCheck=$(grep -i '^chime=' "$confFile" | cut -d = -f 2)
|
||||
if [ -n "$varCheck" ] ; then
|
||||
chime="$varCheck"
|
||||
fi
|
||||
fi
|
||||
speakTime="${speak:-true}"
|
||||
soundPack="${soundpack:-/usr/share/talking-clock}"
|
||||
|
||||
#Get and process commandline args which override all other settings.
|
||||
while [ $# -gt 0 ] ; do
|
||||
@ -304,24 +281,6 @@ while [ $# -gt 0 ] ; do
|
||||
shift
|
||||
soundCommand="$1"
|
||||
;;
|
||||
"-q" | "--quarterhour")
|
||||
shift
|
||||
if [ -f "$1" ] ; then
|
||||
quarterHourChime="$1"
|
||||
else
|
||||
echo "File $1 not found."
|
||||
exit 1
|
||||
fi
|
||||
;;
|
||||
"-b" | "--bell")
|
||||
shift
|
||||
if [ -f "$1" ] ; then
|
||||
hourChime="$1"
|
||||
else
|
||||
echo "File $1 not found."
|
||||
exit 1
|
||||
fi
|
||||
;;
|
||||
"-f" | "--format")
|
||||
shift
|
||||
if [ "$1" == "12" -o "$1" == "24" ] ; then
|
||||
@ -333,15 +292,6 @@ while [ $# -gt 0 ] ; do
|
||||
exit 1
|
||||
fi
|
||||
;;
|
||||
"-p" | "--prepend")
|
||||
shift
|
||||
if [ -f "$1" ] ; then
|
||||
prependSound="$1"
|
||||
else
|
||||
echo "File $1 not found."
|
||||
exit 1
|
||||
fi
|
||||
;;
|
||||
"-s" | "--soundpack")
|
||||
shift
|
||||
if [ -d "$1" ] ; then
|
||||
@ -369,7 +319,7 @@ while [ $# -gt 0 ] ; do
|
||||
zipcode="$1"
|
||||
;;
|
||||
*)
|
||||
echo -e "Talking-clock by Storm Dragon\nTalking-clock accepts the following arguments:\n--cron number:\nIf you use --cron the only valid entry is a number following it. 1 will cause the clock to chime every hour, 2 every\nhalf-hour, 4 every quarter, and anything else will delete your existing settings if they exist.\n-a --audio Command for playing sound. The default is play -q provided from the sox package.\n-b --bell Set path to the sound used for hourly chimes.\n-c --nochime Turn off chimes.\n-f --format: 12 or 24 hour format. Default is 12 hour time.\n-n --nospeak turn off spoken time.\n-p --prepend Select a sound file to be played before chiming.\n-q --quarterhour Set the path to the sound for quarter-hour chimes.\n-s --soundpack Set path to soundpack. Sound packs should be in ogg format and contain 1.ogg, 2.ogg, ... 11.ogg, 12.ogg and\nquarter.ogg for the quarter-hour chime.\n-v --voice Select voice. Default is espeak other options are\ncepstral, espeak, festival, pico, speech-dispatcher and custom.\nTo set a custom voice enter the command as in:\n-v 'espeak -v en-us+klatt2'\n-t --torify retrieve temperature anonymously using torify, used with -z --zipcode\n-z --zipcode postal code Used for current temperature, may not be available inn all areas.\nFor complete information read the README located at /usr/share/talking-clock/README"
|
||||
display_help
|
||||
exit 0
|
||||
esac
|
||||
shift
|
||||
@ -458,38 +408,34 @@ fi
|
||||
#There will be a slight gap between the prepended sound and the actual chiming.
|
||||
#This is to simulate real clocks based on my experience.
|
||||
if [ "$minute" -eq "0" ]; then
|
||||
if [ -n "$prependSound" ] ; then
|
||||
if [ -f "$soundPack/prepend.ogg" ] ; then
|
||||
$soundCommand "$prependSound"
|
||||
fi
|
||||
fi
|
||||
|
||||
#chime for quarter hour
|
||||
if [[ "$minute" -eq "15" || "$minute" -eq "30" || "$minute" -eq "45" ]] ; then
|
||||
#Play correct sound pack file if we are using sound packs
|
||||
if [ -n "$soundPack" ] ; then
|
||||
quarterHourChime="$soundPack/$minute.ogg"
|
||||
else
|
||||
quarterHourChime="/usr/share/talking-clock/$minute.ogg"
|
||||
fi
|
||||
#Play sound for half-hour
|
||||
if [ $chime != "false" ] ; then
|
||||
$soundCommand "$quarterHourChime"
|
||||
#Play correct sound pack file
|
||||
if [ -f "$soundPack/$minute.ogg" ] ; then
|
||||
if [ $chime != "false" ] ; then
|
||||
$soundCommand "$soundPack/$minute.ogg"
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
|
||||
#Chime on the hour
|
||||
if [ "$minute" -eq "0" ] ; then
|
||||
#Check if we are using a soundpack
|
||||
if [ -z "$soundPack" ] ; then
|
||||
#Check if soundpack has hour chimes or uses the bell sound.
|
||||
if ! [ -f "$soundPack/$hour.ogg" ] ; then
|
||||
if [ $chime != "false" ] ; then
|
||||
i=0
|
||||
#create chime string for sound players that can handle more than one sound argument.
|
||||
soundString=""
|
||||
while [ "$i" -lt "$hour" ] ; do
|
||||
if [[ "$soundCommand" == "play" || "$soundCommand" == "play -q" || "$soundCommand" == "ogg123" || "$soundCommand" == "ogg123 -q" ]] ; then
|
||||
soundString="$soundString $hourChime"
|
||||
soundString="$soundString $soundPack/bell.ogg"
|
||||
else
|
||||
$soundCommand "$hourChime"
|
||||
$soundCommand "$soundPack/bell.ogg"
|
||||
fi
|
||||
i=$(($i + 1))
|
||||
done
|
||||
|
Loading…
Reference in New Issue
Block a user