Exemplo n.º 1
0
        /** Constructs a phone loop search graph. */
        public PhoneLoopSearchGraph(SentenceHMMState initState, AcousticModel model, float logPhoneInsertionProbability)
        {
            this.inititalState = initState;
            this.model         = model;
            this.logPhoneInsertionProbability = logPhoneInsertionProbability;
            existingStates = new Dictionary <string, SearchState>();
            firstState     = new UnknownWordState();
            SentenceHMMState branchState = new BranchOutState(firstState);

            attachState(firstState, branchState, logOne, logOne);

            SentenceHMMState lastState = new LoopBackState(firstState);

            //lastState.setFinalState(true);
            //attachState(lastState, branchState, LogMath.getLogZero(),
            //		LogMath.getLogZero());
            attachState(lastState, inititalState, logOne, logOne);

            for (java.util.Iterator i = model.getContextIndependentUnitIterator(); i.hasNext();)
            {
                Unit      unit      = (Unit)i.next();
                UnitState unitState = new UnitState(unit, HMMPosition.UNDEFINED);

                // attach unit state to the branch out state
                attachState(branchState, unitState, logOne, logPhoneInsertionProbability);

                HMM hmm = model.lookupNearestHMM
                              (unitState.getUnit(), unitState.getPosition(), false);
                HMMState      initialState = hmm.getInitialState();
                HMMStateState hmmTree      = new HMMStateState(unitState, initialState);
                addStateToCache(hmmTree);

                // attach first HMM state to the unit state
                attachState(unitState, hmmTree, logOne, logOne);

                // expand the HMM tree
                HMMStateState finalState = expandHMMTree(unitState, hmmTree);

                // attach final state of HMM tree to the loopback state
                attachState(finalState, lastState, logOne, logOne);
            }
        }
Exemplo n.º 2
0
        public HMMPool(AcousticModel model, Logger logger, UnitManager unitManager)
        {
            this.logger = logger;
            int num = 0;

            this.model       = model;
            this.unitManager = unitManager;
            if (model.getLeftContextSize() != 1)
            {
                string text = "LexTreeLinguist: Unsupported left context size";

                throw new Error(text);
            }
            if (model.getRightContextSize() != 1)
            {
                string text2 = "LexTreeLinguist: Unsupported right context size";

                throw new Error(text2);
            }
            Iterator iterator = model.getContextIndependentUnitIterator();

            while (iterator.hasNext())
            {
                Unit unit = (Unit)iterator.next();
                logger.fine(new StringBuilder().append("CI unit ").append(unit).toString());
                if (unit.getBaseID() > num)
                {
                    num = unit.getBaseID();
                }
            }
            this.numCIUnits = num + 1;
            this.unitTable  = new Unit[this.numCIUnits * this.numCIUnits * this.numCIUnits];
            iterator        = model.getHMMIterator();
            while (iterator.hasNext())
            {
                HMM  hmm   = (HMM)iterator.next();
                Unit unit2 = hmm.getUnit();
                int  id    = this.getID(unit2);
                this.unitTable[id] = unit2;
                if (logger.isLoggable(Level.FINER))
                {
                    logger.finer(new StringBuilder().append("Unit ").append(unit2).append(" id ").append(id).toString());
                }
            }
            this.hmmTable = new EnumMap(ClassLiteral <HMMPosition> .Value);
            HMMPosition[] array = HMMPosition.values();
            int           num2  = array.Length;

            for (int i = 0; i < num2; i++)
            {
                HMMPosition hmmposition = array[i];
                HMM[]       array2      = new HMM[this.unitTable.Length];
                this.hmmTable.put(hmmposition, array2);
                for (int j = 1; j < this.unitTable.Length; j++)
                {
                    Unit unit3 = this.unitTable[j];
                    if (unit3 == null)
                    {
                        unit3 = this.synthesizeUnit(j);
                    }
                    if (unit3 != null)
                    {
                        array2[j] = model.lookupNearestHMM(unit3, hmmposition, false);
                        if (!HMMPool.assertionsDisabled && array2[j] == null)
                        {
                            throw new AssertionError();
                        }
                    }
                }
            }
        }