#!/bin/bash

if [ $# != 1 ]
then
    echo "usage: $0 <xml-filename>" >&2
    exit 1
fi

set -e -u -o pipefail

xml=$1

name=`basename $xml .xml`
dirname=`dirname $0`

cat > $dirname/../models/$name.cfg <<EOF
dir = asr/models/$name
name = $name

xml_filename = \$dir/${name}.xml
slu_prefix = \$dir/automate/${name}_%s
slu_actions = \$dir/${name}.action

fst = \$dir/HCLG.fst
model = \$dir/final.mdl
word-syms = \$dir/words.txt
feature-type = mfcc
mfcc-config = \$dir/conf/mfcc.conf
ivector-extraction-config = \$dir/conf/ivector_extractor.fixed.conf
max-active = 7000
beam = 11.0
lattice-beam = 6.0
do-endpointing = True
endpoint-silence-phones = `cat $dirname/base/phones/silence.int | tr "\n" ":" | sed 's/:$/\n/'`
EOF

echo "config saved in `readlink -f $dirname/../models/$name.cfg`"
