#!/bin/bash
# Shell wrapper for Open JTalk.

VOICE_DIR=@voice_dir@
DIC_DIR=@dic_dir@

CMDNAME=`basename $0`

case $1 in
    -h) echo "Usage: $CMDNAME [-h] [-i infile]" 1>&2 ; exit 0 ;;
    -i) shift ;;
    *)  set -- /dev/stdin ;;
esac

WAVFILE="/tmp/$CMDNAME-$$.wav"

while read LINE
do
    echo $LINE | iconv -t EUC-JP | open_jtalk \
        -td $VOICE_DIR/tree-dur.inf \
        -tf $VOICE_DIR/tree-lf0.inf \
        -tm $VOICE_DIR/tree-mgc.inf \
        -md $VOICE_DIR/dur.pdf \
        -mf $VOICE_DIR/lf0.pdf \
        -mm $VOICE_DIR/mgc.pdf \
        -df $VOICE_DIR/lf0.win1 \
        -df $VOICE_DIR/lf0.win2 \
        -df $VOICE_DIR/lf0.win3 \
        -dm $VOICE_DIR/mgc.win1 \
        -dm $VOICE_DIR/mgc.win2 \
        -dm $VOICE_DIR/mgc.win3 \
        -cf $VOICE_DIR/gv-lf0.pdf \
        -cm $VOICE_DIR/gv-mgc.pdf \
        -ef $VOICE_DIR/tree-gv-lf0.inf \
        -em $VOICE_DIR/tree-gv-mgc.inf \
        -k  $VOICE_DIR/gv-switch.inf \
        -x  $DIC_DIR \
        -ow $WAVFILE && afplay $WAVFILE
done < "$1"

rm -f $WAVFILE
exit 0
