#!/bin/bash
# The filename fest-input.txt is hard coded in the phonemize.scm for now.  Hence some of the shenannigans below.
if [ ! -f "`which festival`" ] ; then
    echo "`basename $0`: The text to speech program 'festival' is not installed.  Perhaps try: sudo apt-get install festival" >&2
    echo
    exit 1
fi
DIR="`dirname $(realpath \"$0\")`"
pushd $DIR > /dev/null 2>&1
make > /dev/null 2>&1
umask 077   # create temp area with only owner access
mkdir -p /tmp/`whoami`-$$
cd /tmp/`whoami`-$$
rm -f fest-input.txt
touch fest-input.txt
while [ "X$1" != "X" ]; do
    echo \"$1\" >> fest-input.txt
    shift
done
umask 000   # restore default permissions
export SPEAKJET_SYM=1
# (it was easier just to include the text editor code I use than to work out how to do that with sed ;-) )
festival -b ${DIR}/phonemize.scm|${DIR}/plisp|${DIR}/lexconvert.py --phones2phones  festival-cmu speakjet | sed 's/[^[:space:]]\+/\\&/g'
# was: | ecce - - --command "i.\. (t. .i.\.)0;%c" 2> /dev/null
rm -f fest-input.txt
popd > /dev/null 2>&1
rm -rf /tmp/`whoami`-$$
