[FeatureSet fs]             setDesc   @../step2/featDesc
            fs              setAccess @../step2/featAccess
[CodebookSet cbs fs]              read ../step2/codebookSet
[DistribSet  dss cbs]             read ../step2/distribSet
[PhonesSet ps]                    read ../step2/phonesSet
[Tags tags]                       read ../step2/tags
[Tree dst ps:phones ps tags dss]  read ../step2/distribTree
SenoneSet sns [DistribStream str dss dst]
[TmSet tms]                       read ../step2/transitionModels
[TopoSet tps sns tms]             read ../step2/topologies
[Tree tpt ps:phones ps tags tps]  read ../step2/topologyTree
[Dictionary dict ps:phones tags]  read ../step1/convertedDict
[DBase db]                        open ../step1/db.dat ../step1/db.idx -mode r
AModelSet amo tpt ROOT
HMM hmm dict amo
Path path

proc forcedAlignment {utt {method viterbi}} {
  set uttInfo [db get $utt]
  makeArray arr $uttInfo
  hmm make $arr(text) -optWord SIL
  path $method hmm -eval $uttInfo
}

cbs load ../step3/codebookWeights
cbs createAccus
dss createAccus

foreach utt [db] {
  puts "$utt [forcedAlignment $utt]"
# puts "$utt [forcedAlignment $utt fwdBwd]"
  sns accu path
}

cbs saveAccus codebookAccus
dss saveAccus distribAccus

sns update

cbs save codebookWeights
dss save distribWeights

exit