Beispiel #1
0
 private void loadModelFiles(string text)
 {
     this.logger.config(new StringBuilder().append("Loading HTK acoustic model: ").append(text).toString());
     this.logger.config(new StringBuilder().append("    Path      : ").append(this.location).toString());
     this.logger.config(new StringBuilder().append("    modellName: ").append(this.model).toString());
     this.logger.config(new StringBuilder().append("    dataDir   : ").append(this.dataDir).toString());
     HTKLoader.HTKStruct htkstruct = new HTKLoader.HTKStruct(this);
     htkstruct.load(text);
     this.meansPool      = htkstruct.htkMeans(text);
     this.variancePool   = htkstruct.htkVars(text, this.varianceFloor);
     this.mixtureWeights = htkstruct.htkWeights(text, this.mixtureWeightFloor);
     this.matrixPool     = htkstruct.htkTrans(text);
     this.senonePool     = this.createSenonePool(this.distFloor, this.varianceFloor);
     this.loadHMMPool(this.useCDUnits, htkstruct, new StringBuilder().append(this.location).append(File.separator).append(this.model).toString());
 }
Beispiel #2
0
        protected internal virtual void loadHMMPool(bool useCDUnits, HTKLoader.HTKStruct htkModels, string path)
        {
            if (!this.tie1ph)
            {
                Iterator iterator = htkModels.hmmsHTK.get1phIt();
                while (iterator.hasNext())
                {
                    SingleHMM singleHMM = (SingleHMM)iterator.next();
                    if (singleHMM == null)
                    {
                        break;
                    }
                    string baseName = singleHMM.getName();
                    string text;
                    if (String.instancehelper_equals(baseName, "sil") || String.instancehelper_equals(baseName, "sp") || String.instancehelper_equals(baseName, "bb") || String.instancehelper_equals(baseName, "xx") || String.instancehelper_equals(baseName, "hh"))
                    {
                        text = "filler";
                    }
                    else
                    {
                        text = "nofiller";
                    }
                    int   trIdx   = singleHMM.trIdx;
                    int   nstates = singleHMM.getNstates();
                    int[] array   = new int[singleHMM.getNbEmittingStates()];
                    int   num     = 0;
                    for (int i = 0; i < nstates; i++)
                    {
                        if (singleHMM.isEmitting(i))
                        {
                            HTK.HMMState state = singleHMM.getState(i);
                            array[num] = htkModels.hmmsHTK.getStateIdx(state);
                            num++;
                        }
                    }
                    Unit unit = this.unitManager.getUnit(baseName, String.instancehelper_equals(text, "filler"));
                    this.contextIndependentUnits.put(unit.getName(), unit);
                    if (this.logger.isLoggable(Level.FINE))
                    {
                        this.logger.fine(new StringBuilder().append("Loaded ").append(unit).toString());
                    }
                    if (unit.isFiller() && String.instancehelper_equals(unit.getName(), "SIL"))
                    {
                        unit = UnitManager.__SILENCE;
                    }
                    float[][]      transitionMatrix = (float[][])this.matrixPool.get(trIdx);
                    SenoneSequence senoneSequence   = this.getSenoneSequence(array);
                    SenoneHMM      hmm = new SenoneHMM(unit, senoneSequence, transitionMatrix, HMMPosition.lookup("-"));
                    this.hmmManager.put(hmm);
                }
            }
            else
            {
                for (int j = 0; j < htkModels.hmmsHTK.getNhmms(); j++)
                {
                    SingleHMM singleHMM = htkModels.hmmsHTK.getHMM(j);
                    if (singleHMM == null)
                    {
                        break;
                    }
                    string baseName = singleHMM.getBaseName();
                    if (!this.contextIndependentUnits.containsKey(baseName))
                    {
                        string text;
                        if (String.instancehelper_equals(baseName, "SIL") || String.instancehelper_equals(baseName, "SP") || String.instancehelper_equals(baseName, "BB") || String.instancehelper_equals(baseName, "XX") || String.instancehelper_equals(baseName, "HH"))
                        {
                            text = "filler";
                        }
                        else
                        {
                            text = "nofiller";
                        }
                        int   trIdx   = singleHMM.trIdx;
                        int   nstates = singleHMM.getNstates();
                        int[] array   = new int[singleHMM.getNbEmittingStates()];
                        int   num     = 0;
                        for (int i = 0; i < nstates; i++)
                        {
                            if (singleHMM.isEmitting(i))
                            {
                                HTK.HMMState state = singleHMM.getState(i);
                                array[num] = htkModels.hmmsHTK.getStateIdx(state);
                                num++;
                            }
                        }
                        Unit unit = this.unitManager.getUnit(baseName, String.instancehelper_equals(text, "filler"));
                        this.contextIndependentUnits.put(unit.getName(), unit);
                        if (this.logger.isLoggable(Level.FINE))
                        {
                            this.logger.fine(new StringBuilder().append("Loaded ").append(unit).toString());
                        }
                        if (unit.isFiller() && String.instancehelper_equals(unit.getName(), "SIL"))
                        {
                            unit = UnitManager.__SILENCE;
                        }
                        float[][]      transitionMatrix = (float[][])this.matrixPool.get(trIdx);
                        SenoneSequence senoneSequence   = this.getSenoneSequence(array);
                        SenoneHMM      hmm = new SenoneHMM(unit, senoneSequence, transitionMatrix, HMMPosition.lookup("-"));
                        this.hmmManager.put(hmm);
                    }
                }
            }
            string text2 = "";
            Unit   unit2 = null;

            int[]          ssid            = null;
            SenoneSequence senoneSequence2 = null;
            ArrayList      arrayList       = new ArrayList();
            Iterator       iterator2       = htkModels.hmmsHTK.get3phIt();

            while (iterator2.hasNext())
            {
                SingleHMM singleHMM2 = (SingleHMM)iterator2.next();
                if (singleHMM2 == null)
                {
                    break;
                }
                string baseName2 = singleHMM2.getBaseName();
                string text3     = singleHMM2.getLeft();
                string text4     = singleHMM2.getRight();
                if (String.instancehelper_equals(text3, "-"))
                {
                    text3 = "SIL";
                }
                if (String.instancehelper_equals(text4, "-"))
                {
                    text4 = "SIL";
                }
                string text5 = new StringBuilder().append(text3).append(' ').append(baseName2).append(' ').append(text4).toString();
                if (!arrayList.contains(text5))
                {
                    arrayList.add(text5);
                    text5 = "i";
                    int   trIdx2  = singleHMM2.trIdx;
                    int   nstates = singleHMM2.getNstates();
                    int[] array2  = new int[singleHMM2.getNbEmittingStates()];
                    int   num2    = 0;
                    for (int k = 0; k < nstates; k++)
                    {
                        if (singleHMM2.isEmitting(k))
                        {
                            HTK.HMMState state2 = singleHMM2.getState(k);
                            array2[num2] = htkModels.hmmsHTK.getStateIdx(state2);
                            num2++;
                        }
                    }
                    if (useCDUnits)
                    {
                        string text6 = new StringBuilder().append(baseName2).append(' ').append(text3).append(' ').append(text4).toString();
                        Unit   unit3;
                        if (String.instancehelper_equals(text6, text2))
                        {
                            unit3 = unit2;
                        }
                        else
                        {
                            LeftRightContext context = LeftRightContext.get(new Unit[]
                            {
                                (Unit)this.contextIndependentUnits.get(text3)
                            }, new Unit[]
                            {
                                (Unit)this.contextIndependentUnits.get(text4)
                            });
                            unit3 = this.unitManager.getUnit(baseName2, false, context);
                        }
                        text2 = text6;
                        unit2 = unit3;
                        if (this.logger.isLoggable(Level.FINE))
                        {
                            this.logger.fine(new StringBuilder().append("Loaded ").append(unit3).toString());
                        }
                        float[][]      transitionMatrix2 = (float[][])this.matrixPool.get(trIdx2);
                        SenoneSequence senoneSequence3   = senoneSequence2;
                        if (senoneSequence3 == null || !this.sameSenoneSequence(array2, ssid))
                        {
                            senoneSequence3 = this.getSenoneSequence(array2);
                        }
                        senoneSequence2 = senoneSequence3;
                        ssid            = array2;
                        SenoneHMM hmm2 = new SenoneHMM(unit3, senoneSequence3, transitionMatrix2, HMMPosition.lookup(text5));
                        this.hmmManager.put(hmm2);
                    }
                }
            }
        }