private HMM getCompositeHMM(Unit unit, HMMPosition position)
        {
            Unit           unit2 = this.unitManager.getUnit(unit.getName(), unit.isFiller(), Context.__EMPTY_CONTEXT);
            SenoneSequence compositeSenoneSequence = this.getCompositeSenoneSequence(unit, position);
            SenoneHMM      senoneHMM = (SenoneHMM)this.lookupNearestHMM(unit2, HMMPosition.__UNDEFINED, true);

            float[][] transitionMatrix = senoneHMM.getTransitionMatrix();
            return(new SenoneHMM(unit, compositeSenoneSequence, transitionMatrix, position));
        }
Esempio n. 2
0
 public override bool equals(object o)
 {
     if (this == o)
     {
         return(true);
     }
     if (o is SenoneHMM)
     {
         SenoneHMM senoneHMM = (SenoneHMM)o;
         return(this.getSenoneSequence().equals(senoneHMM.getSenoneSequence()));
     }
     return(false);
 }
 internal SenoneHMMState(SenoneHMM senoneHMM, int num)
 {
     this.hmm         = senoneHMM;
     this.state       = num;
     this._isEmitting = (senoneHMM.getTransitionMatrix().Length - 1 != this.state);
     if (this._isEmitting)
     {
         SenoneSequence senoneSequence = senoneHMM.getSenoneSequence();
         this.senone = senoneSequence.getSenones()[this.state];
     }
     Utilities.objectTracker("HMMState", SenoneHMMState.objectCount++);
     this._hashCode = senoneHMM.hashCode() + 37 * this.state;
 }
        private SenoneHMM getHMMAtAnyPosition(Unit unit)
        {
            HMMManager hmmmanager = this.loader.getHMMManager();

            HMMPosition[] array = HMMPosition.values();
            int           num   = array.Length;

            for (int i = 0; i < num; i++)
            {
                HMMPosition position  = array[i];
                SenoneHMM   senoneHMM = (SenoneHMM)hmmmanager.get(position, unit);
                if (senoneHMM != null)
                {
                    return(senoneHMM);
                }
            }
            return(null);
        }
Esempio n. 5
0
        public override HMM get(HMMPosition position, Unit unit)
        {
            HMM hmm = base.get(position, unit);

            if (null != hmm)
            {
                return(hmm);
            }
            int[] array = new int[3];
            array[1] = ((Integer)this.symbolTable.get(unit.getName())).intValue();
            if (unit.isContextDependent())
            {
                LeftRightContext leftRightContext = (LeftRightContext)unit.getContext();
                Unit             unit2            = leftRightContext.getLeftContext()[0];
                Unit             unit3            = leftRightContext.getRightContext()[0];
                array[0] = ((Integer)this.symbolTable.get(unit2.getName())).intValue();
                array[2] = ((Integer)this.symbolTable.get(unit3.getName())).intValue();
            }
            else
            {
                array[0] = ((Integer)this.symbolTable.get("SIL")).intValue();
                array[2] = ((Integer)this.symbolTable.get("SIL")).intValue();
            }
            int[] array2 = new int[]
            {
                this.eventMap.map(0, array),
                this.eventMap.map(1, array),
                this.eventMap.map(2, array)
            };
            SenoneSequence senoneSequence = new SenoneSequence(new Senone[]
            {
                (Senone)this.senonePool.get(array2[0]),
                (Senone)this.senonePool.get(array2[1]),
                (Senone)this.senonePool.get(array2[2])
            });

            float[][] transitionMatrix = this.transitionModel.getTransitionMatrix(array[1], array2);
            SenoneHMM senoneHMM        = new SenoneHMM(unit, senoneSequence, transitionMatrix, position);

            this.put(senoneHMM);
            return(senoneHMM);
        }
        private SenoneHMM getHMMInSilenceContext(Unit unit, HMMPosition position)
        {
            SenoneHMM  senoneHMM  = null;
            HMMManager hmmmanager = this.loader.getHMMManager();
            Context    context    = unit.getContext();

            if (context is LeftRightContext)
            {
                LeftRightContext leftRightContext = (LeftRightContext)context;
                Unit[]           leftContext      = leftRightContext.getLeftContext();
                Unit[]           rightContext     = leftRightContext.getRightContext();
                Unit[]           array;
                if (this.hasNonSilenceFiller(leftContext))
                {
                    array = this.replaceNonSilenceFillerWithSilence(leftContext);
                }
                else
                {
                    array = leftContext;
                }
                Unit[] array2;
                if (this.hasNonSilenceFiller(rightContext))
                {
                    array2 = this.replaceNonSilenceFillerWithSilence(rightContext);
                }
                else
                {
                    array2 = rightContext;
                }
                if (array != leftContext || array2 != rightContext)
                {
                    LeftRightContext context2 = LeftRightContext.get(array, array2);
                    Unit             unit2    = this.unitManager.getUnit(unit.getName(), unit.isFiller(), context2);
                    senoneHMM = (SenoneHMM)hmmmanager.get(position, unit2);
                    if (senoneHMM == null)
                    {
                        senoneHMM = this.getHMMAtAnyPosition(unit2);
                    }
                }
            }
            return(senoneHMM);
        }
Esempio n. 7
0
        protected internal virtual void loadHMMPool(bool useCDUnits, InputStream inputStream)
        {
            ExtendedStreamTokenizer extendedStreamTokenizer = new ExtendedStreamTokenizer(inputStream, 35, false);

            this.logger.fine(new StringBuilder().append("Loading HMM file from: ").append(this.location).toString());
            extendedStreamTokenizer.expectString("0.3");
            int @int = extendedStreamTokenizer.getInt("numBase");

            extendedStreamTokenizer.expectString("n_base");
            int int2 = extendedStreamTokenizer.getInt("numTri");

            extendedStreamTokenizer.expectString("n_tri");
            int int3 = extendedStreamTokenizer.getInt("numStateMap");

            extendedStreamTokenizer.expectString("n_state_map");
            int int4 = extendedStreamTokenizer.getInt("numTiedState");

            extendedStreamTokenizer.expectString("n_tied_state");
            int int5 = extendedStreamTokenizer.getInt("numContextIndependentTiedState");

            extendedStreamTokenizer.expectString("n_tied_ci_state");
            int int6 = extendedStreamTokenizer.getInt("numTiedTransitionMatrices");

            extendedStreamTokenizer.expectString("n_tied_tmat");
            int num  = int3;
            int num2 = int2 + @int;
            int num3 = (num2 != -1) ? (num / num2) : (-num);

            if (!Sphinx3Loader.assertionsDisabled && int4 != this.mixtureWeights.getStatesNum())
            {
                throw new AssertionError();
            }
            if (!Sphinx3Loader.assertionsDisabled && int6 != this.transitionsPool.size())
            {
                throw new AssertionError();
            }
            for (int i = 0; i < @int; i++)
            {
                string @string = extendedStreamTokenizer.getString();
                string string2 = extendedStreamTokenizer.getString();
                string string3 = extendedStreamTokenizer.getString();
                string string4 = extendedStreamTokenizer.getString();
                string string5 = extendedStreamTokenizer.getString();
                int    int7    = extendedStreamTokenizer.getInt("tmat");
                int[]  array   = new int[num3 - 1];
                for (int j = 0; j < num3 - 1; j++)
                {
                    array[j] = extendedStreamTokenizer.getInt("j");
                    if (!Sphinx3Loader.assertionsDisabled && (array[j] < 0 || array[j] >= int5))
                    {
                        throw new AssertionError();
                    }
                }
                extendedStreamTokenizer.expectString("N");
                if (!Sphinx3Loader.assertionsDisabled && !String.instancehelper_equals(string2, "-"))
                {
                    throw new AssertionError();
                }
                if (!Sphinx3Loader.assertionsDisabled && !String.instancehelper_equals(string3, "-"))
                {
                    throw new AssertionError();
                }
                if (!Sphinx3Loader.assertionsDisabled && !String.instancehelper_equals(string4, "-"))
                {
                    throw new AssertionError();
                }
                if (!Sphinx3Loader.assertionsDisabled && int7 >= int6)
                {
                    throw new AssertionError();
                }
                Unit unit = this.unitManager.getUnit(@string, String.instancehelper_equals(string5, "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.transitionsPool.get(int7);
                SenoneSequence senoneSequence   = this.getSenoneSequence(array);
                SenoneHMM      hmm = new SenoneHMM(unit, senoneSequence, transitionMatrix, HMMPosition.lookup(string4));
                this.hmmManager.put(hmm);
            }
            if (this.hmmManager.get(HMMPosition.__UNDEFINED, UnitManager.__SILENCE) == null)
            {
                string text = "Could not find SIL unit in acoustic model";

                throw new IOException(text);
            }
            string text2 = "";
            Unit   unit2 = null;

            int[]          ssid            = null;
            SenoneSequence senoneSequence2 = null;

            for (int k = 0; k < int2; k++)
            {
                string string5 = extendedStreamTokenizer.getString();
                string string6 = extendedStreamTokenizer.getString();
                string string7 = extendedStreamTokenizer.getString();
                string string8 = extendedStreamTokenizer.getString();
                string string9 = extendedStreamTokenizer.getString();
                int    int8    = extendedStreamTokenizer.getInt("tmat");
                int[]  array2  = new int[num3 - 1];
                for (int l = 0; l < num3 - 1; l++)
                {
                    array2[l] = extendedStreamTokenizer.getInt("j");
                    if (!Sphinx3Loader.assertionsDisabled && (array2[l] < int5 || array2[l] >= int4))
                    {
                        throw new AssertionError();
                    }
                }
                extendedStreamTokenizer.expectString("N");
                if (!Sphinx3Loader.assertionsDisabled && String.instancehelper_equals(string6, "-"))
                {
                    throw new AssertionError();
                }
                if (!Sphinx3Loader.assertionsDisabled && String.instancehelper_equals(string7, "-"))
                {
                    throw new AssertionError();
                }
                if (!Sphinx3Loader.assertionsDisabled && String.instancehelper_equals(string8, "-"))
                {
                    throw new AssertionError();
                }
                if (!Sphinx3Loader.assertionsDisabled && !String.instancehelper_equals(string9, "n/a"))
                {
                    throw new AssertionError();
                }
                if (!Sphinx3Loader.assertionsDisabled && int8 >= int6)
                {
                    throw new AssertionError();
                }
                if (useCDUnits)
                {
                    string text3 = new StringBuilder().append(string5).append(' ').append(string6).append(' ').append(string7).toString();
                    Unit   unit3;
                    if (String.instancehelper_equals(text3, text2))
                    {
                        unit3 = unit2;
                    }
                    else
                    {
                        LeftRightContext context = LeftRightContext.get(new Unit[]
                        {
                            (Unit)this.contextIndependentUnits.get(string6)
                        }, new Unit[]
                        {
                            (Unit)this.contextIndependentUnits.get(string7)
                        });
                        unit3 = this.unitManager.getUnit(string5, false, context);
                    }
                    text2 = text3;
                    unit2 = unit3;
                    if (this.logger.isLoggable(Level.FINE))
                    {
                        this.logger.fine(new StringBuilder().append("Loaded ").append(unit3).toString());
                    }
                    float[][]      transitionMatrix2 = (float[][])this.transitionsPool.get(int8);
                    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(string8));
                    this.hmmManager.put(hmm2);
                }
            }
            extendedStreamTokenizer.close();
        }
Esempio n. 8
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);
                    }
                }
            }
        }
        public virtual SenoneSequence getCompositeSenoneSequence(Unit unit, HMMPosition position)
        {
            string         text           = unit.toString();
            SenoneSequence senoneSequence = (SenoneSequence)this.compositeSenoneSequenceCache.get(text);

            if (this.logger.isLoggable(Level.FINE))
            {
                this.logger.fine((new StringBuilder().append("getCompositeSenoneSequence: ").append(unit).append(senoneSequence).toString() != null) ? "Cached" : "");
            }
            if (senoneSequence != null)
            {
                return(senoneSequence);
            }
            Context   context     = unit.getContext();
            ArrayList arrayList   = new ArrayList();
            Iterator  hmmiterator = this.getHMMIterator();

            while (hmmiterator.hasNext())
            {
                SenoneHMM senoneHMM = (SenoneHMM)hmmiterator.next();
                if (senoneHMM.getPosition() == position)
                {
                    Unit unit2 = senoneHMM.getUnit();
                    if (unit2.isPartialMatch(unit.getName(), context))
                    {
                        if (this.logger.isLoggable(Level.FINE))
                        {
                            this.logger.fine(new StringBuilder().append("collected: ").append(senoneHMM.getUnit()).toString());
                        }
                        arrayList.add(senoneHMM.getSenoneSequence());
                    }
                }
            }
            if (arrayList.isEmpty())
            {
                Unit      unit3     = this.unitManager.getUnit(unit.getName(), unit.isFiller());
                SenoneHMM senoneHMM = this.lookupHMM(unit3, HMMPosition.__UNDEFINED);
                arrayList.add(senoneHMM.getSenoneSequence());
            }
            int      num      = 0;
            Iterator iterator = arrayList.iterator();

            while (iterator.hasNext())
            {
                SenoneSequence senoneSequence2 = (SenoneSequence)iterator.next();
                if (senoneSequence2.getSenones().Length > num)
                {
                    num = senoneSequence2.getSenones().Length;
                }
            }
            ArrayList arrayList2 = new ArrayList();
            float     weight     = 0f;

            for (int i = 0; i < num; i++)
            {
                HashSet  hashSet   = new HashSet();
                Iterator iterator2 = arrayList.iterator();
                while (iterator2.hasNext())
                {
                    SenoneSequence senoneSequence3 = (SenoneSequence)iterator2.next();
                    if (i < senoneSequence3.getSenones().Length)
                    {
                        Senone senone = senoneSequence3.getSenones()[i];
                        hashSet.add(senone);
                    }
                }
                arrayList2.add(CompositeSenone.create(hashSet, weight));
            }
            senoneSequence = SenoneSequence.create(arrayList2);
            this.compositeSenoneSequenceCache.put(unit.toString(), senoneSequence);
            if (this.logger.isLoggable(Level.FINE))
            {
                this.logger.fine(new StringBuilder().append(unit).append(" consists of ").append(arrayList2.size()).append(" composite senones").toString());
                if (this.logger.isLoggable(Level.FINEST))
                {
                    senoneSequence.dump("am");
                }
            }
            return(senoneSequence);
        }