#! /bin/bash

set -e -u -o pipefail

mkdir -p asr/{mika-fred-1,mika-fred-2,fisher-benoit-1,fisher-fred-1}

# get local models
#scp -r frontend:~benoit.favre/work/kaldi/kaldi-trunk/egs/fisher_english/s5/lm/mika-model1/* asr/mika-fred-1
#scp -r frontend:~benoit.favre/work/kaldi/kaldi-trunk/egs/fisher_english/s5/lm/model-fred/* asr/fisher-fred-1
git clone git@gitlab.lif.univ-mrs.fr:mickael.rouvier/asr-model-rocio.git asr/asr-model-rocio
(cd asr/mika-fred-1/ && ln -s ../asr-model-rocio/mika_fred_1/* .)
(cd asr/mika-fred-2/ && ln -s ../asr-model-rocio/mika_fred_2/* .)
scp -r frontend:~benoit.favre/work/kaldi/kaldi-trunk/egs/fisher_english/s5/lm/model2/* asr/fisher-benoit-1

# get fisher acoustic model
BASE_URL=http://kaldi-asr.org/downloads/build/2/sandbox/online/egs/fisher_english/s5
MODEL=exp/nnet2_online/nnet_a_gpu_online
GRAPH=exp/tri5a

mkdir -p asr/fisher/ivector_extractor asr/fisher/conf

(cd asr/fisher && wget -N $BASE_URL/$MODEL/final.mdl)
(cd asr/fisher/ivector_extractor && wget -N $BASE_URL/$MODEL/ivector_extractor/{final.ie,final.dubm,final.mat,global_cmvn.stats})
(cd asr/fisher/conf && wget -N $BASE_URL/$MODEL/conf/{ivector_extractor.conf,online_nnet2_decoding.conf,mfcc.conf,online_cmvn.conf,splice.conf})
#(cd asr/fisher && wget -N $BASE_URL/$GRAPH/graph/{HCLG.fst,words.txt})

# link to fisher acoustic model
(cd asr/fisher-fred-1 && ln -s ../fisher/* .)
(cd asr/fisher-benoit-1 && ln -s ../fisher/* .)

# fix ivector extraction paths
for model in mika-fred-1 mika-fred-2 fisher-fred-1 fisher-benoit-1
do
    cat asr/$model/conf/ivector_extractor.conf | perl -npe 's/=.*nnet_a_gpu_online\//=asr\/'$model'\//' > asr/$model/conf/ivector_extractor.fixed.conf
done
