#!/bin/bash

cd $(dirname $(readlink -f $0))
SATZ_LISTE=satz-liste
p="${noise_pitch-10}"
v="${noise_lang-de}"
k="${noise_capital-0}"
a="${noise_amplitude-600}"
g="${noise_gap-1}"
RND_DELAY=3600
CACHE_DIR=/opt/ivan-cache
export CACHE_DIR
#set -x
function helpme ()
{
  cat << EOF 
  $0 [-d]
    -d   -- daemonize
    -h   -- this help file

  environment:
     USING_ESPEAK   - if set, ivan will talk with espeak
EOF
  exit 0
}

[ "${1:-}" = "-h" ] && helpme

while true
do
  aplay announce.wav
  if [ -n "${USING_ESPEAK:-}" ];then
    espeak -v $v -p $p -k $k -a $a -g $g "`shuf \"$SATZ_LISTE\" | tail -1`"
  else
    ./naturalvoices_cached.sh "Achtung, Achtung, es erfolgt eine Durchsage!"
    sleep 0.3
    ./naturalvoices_cached.sh "`shuf  \"$SATZ_LISTE\" | tail -1`"
  fi
  [ ! "${1:-}" = "-d" ] && exit 0   # break if not daemonized
  sleep $((${RANDOM}%${RND_DELAY}))
done