#!/bin/bash

# Usage: $0 <device> <text>
MINBASE=/usr/local/minerva
VARLOG=/var/log/minerva

date +"%F %H:%M CMD $0 $*" >>$VARLOG/bearskin/`basename $0`

# get default
if [ -f $MINBASE/etc/defaults/festvox ]; then
  VOX=\(`cat $MINBASE/etc/defaults/festvox`\)
fi

# get override
SPEAKER=/usr/share/festival/voices/english/$1
if [ -d $SPEAKER ]; then
  VOX=\(voice_$1\)
fi

# 
if [ "$1" != "default" ]; then
  VOX=\($1\)
fi

DEVICE=`$MINBASE/bin/finddev say $*`
if [ $? == 0 ]; then
  echo $DEVICE
  exit 0;
fi


# Just for fun, if there's only one parameter
# use it as the only word, and hope no device
# was found earlier.
if [ $# -gt 1 ]; then
  shift
fi
echo "$VOX (SayText \"" $* "\")" | festival --pipe
 
