⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 lextreelinguist.java

📁 It is the Speech recognition software. It is platform independent. To execute the source code,
💻 JAVA
📖 第 1 页 / 共 4 页
字号:
            return hashCode;        }        /**         * Determines if the given object is equal to this object         *          * @param o         *                the object to test         * @return <code>true</code> if the object is equal to this         */        public boolean equals(Object o) {            if (o == this) {                return true;            } else if (o instanceof LexTreeHMMState) {                LexTreeHMMState other = (LexTreeHMMState) o;                return super.equals(o) && hmmState == other.hmmState                        && parentNode == other.parentNode;            } else {                return false;            }        }        /**         * Gets the acoustic probability of entering this state         *          * @return the log probability         */        public float getAcousticProbability() {            return logAcousticProbability;        }        /**         * Gets the language probability of entering this state         *          * @return the log probability         */        public float getLanguageProbability() {            return logLanguageProbability;        }        /**         * Gets the language probability of entering this state         *          * @return the log probability         */        public float getInsertionProbability() {            return logInsertionProbability;        }        /**         * Retreives the set of successors for this state         *          * @return the list of sucessor states         */        public SearchStateArc[] getSuccessors() {            SearchStateArc[] nextStates = getCachedArcs();            if (nextStates == null) {                // if this is an exit state, we are transitioning to a                // new unit or to a word end.                if (hmmState.isExitState()) {                    if (parentNode == null) {                        nextStates = super.getSuccessors();                    } else {                        nextStates = super.getSuccessors(parentNode);                    }                } else {                    // The current hmm state is not an exit state, so we                    // just go through the next set of successors                    HMMStateArc[] arcs = hmmState.getSuccessors();                    nextStates = new SearchStateArc[arcs.length];                    for (int i = 0; i < arcs.length; i++) {                        HMMStateArc arc = arcs[i];                        if (arc.getHMMState().isEmitting()) {                            // if its a self loop and the prob. matches                            // reuse the state                            if (arc.getHMMState() == hmmState                                    && logAcousticProbability == arc                                            .getLogProbability()) {                                nextStates[i] = this;                            } else {                                nextStates[i] = new LexTreeHMMState(                                        (HMMNode) getNode(), getWordHistory(),                                        getSmearTerm(), getSmearProb(),                                         arc.getHMMState(), logOne, logOne,                                         arc.getLogProbability(), parentNode);                            }                        } else {                            nextStates[i] = new LexTreeNonEmittingHMMState(                                    (HMMNode) getNode(), getWordHistory(),                                    getSmearTerm(), getSmearProb(),                                     arc .getHMMState(),                                    arc.getLogProbability(), parentNode);                        }                    }                }                putCachedArcs(nextStates);            }            return nextStates;        }        /**         * Determines if this is an emitting state         */        public boolean isEmitting() {            return hmmState.isEmitting();        }        public String toString() {            return super.toString() + " hmm:" + hmmState;        }        public int getOrder() {            return 5;        }    }    /**     * Represents a non emitting hmm state     */    public class LexTreeNonEmittingHMMState extends LexTreeHMMState {        /**         * Constructs a NonEmittingLexTreeHMMState         *          * @param hmmState         *                the hmm state associated with this unit         *          * @param wordSequence         *                the word history         *          * @param probability         *                the probability of the transition occuring         */        LexTreeNonEmittingHMMState(HMMNode hmmNode, WordSequence wordSequence,                float smearTerm, float smearProb, HMMState hmmState,                float probability, Node parentNode) {            super(hmmNode, wordSequence, smearTerm, smearProb, hmmState,                    logOne, logOne, probability, parentNode);        }        public int getOrder() {            return 0;        }    }    /**     * Represents a word state in the search space     */    public class LexTreeWordState extends LexTreeState            implements                WordSearchState {        private HMMNode lastNode;        private float logLanguageProbability;        /**         * Constructs a LexTreeWordState         *          * @param wordNode         *                the word node         *          * @param wordSequence         *                the sequence of words triphone context         *          * @param logProbability         *                the probability of this word occuring         *           */        LexTreeWordState(WordNode wordNode, HMMNode lastNode,                WordSequence wordSequence, float smearTerm, float smearProb,                float logProbability) {            super(wordNode, wordSequence, smearTerm, smearProb);            // System.out.println("LTWS " + wordSequence);            this.lastNode = lastNode;            this.logLanguageProbability = logProbability;        }        /**         * Gets the word pronunciation for this state         *          * @return the pronunciation for this word         */        public Pronunciation getPronunciation() {            return ((WordNode) getNode()).getPronunciation();        }        /**         * Determines if this is a final state         *          * @return <code>true</code> if this is an final state.         */        public boolean isFinal() {            return getPronunciation().getWord().equals(sentenceEndWord);        }        /**         * Generate a hashcode for an object         *          * @return the hashcode         */        public int hashCode() {            return super.hashCode() * 41 + lastNode.hashCode();        }        /**         * Gets the unique signature for this state. The signature building         * code is slow and should only be used for non-time-critical tasks         * such as plotting states.         *          * @return the signature         */        public String getSignature() {            return super.getSignature() + "-ln-" + lastNode.hashCode();        }        /**         * Determines if the given object is equal to this object         *          * @param o         *                the object to test         * @return <code>true</code> if the object is equal to this         */        public boolean equals(Object o) {            if (o == this) {                return true;            } else if (o instanceof LexTreeWordState) {                LexTreeWordState other = (LexTreeWordState) o;                return super.equals(o) && lastNode == other.lastNode;            } else {                return false;            }        }        /**         * Gets the language probability of entering this state         *          * @return the log probability         */        public float getLanguageProbability() {            return logLanguageProbability;        }        /**         * Returns the list of successors to this state         *          * @return a list of SearchState objects         */        public SearchStateArc[] getSuccessors() {            SearchStateArc[] arcs = getCachedArcs();            if (arcs == null) {                arcs = EMPTY_ARC;                WordNode wordNode = (WordNode) getNode();                if (wordNode.getWord() != sentenceEndWord) {                    int index = 0;                    List list = new ArrayList();                    Unit[] rc = lastNode.getRC();                    Unit left = wordNode.getLastUnit();                    for (int i = 0; i < rc.length; i++) {                        Collection epList = hmmTree.getEntryPoint(left, rc[i]);                        list.addAll(epList);                    }                    // add a link to every possible entry point as well                    // as link to the </s> node                    arcs = new SearchStateArc[list.size() + 1];                    for (Iterator i = list.iterator(); i.hasNext();) {                        HMMNode node = (HMMNode) i.next();                        arcs[index++] = createUnitStateArc(node, this);                    }                    // now add the link to the end of sentence arc:                    arcs[index++] = createWordStateArc(hmmTree                            .getSentenceEndWordNode(), lastNode, this);                }                putCachedArcs(arcs);            }            return arcs;        }        public int getOrder() {            return 1;        }        /**         * Returns true if this LexTreeWordState indicates the start of a word.         * Returns false if this LexTreeWordState indicates the end of a word.         *         * @return true if this LexTreeWordState indicates the start of a word,         *         false if this LexTreeWordState indicates the end of a word         */        public boolean isWordStart() {            return false;        }            }    /**     * Represents the final end of utterance word     */    public class LexTreeEndWordState extends LexTreeWordState            implements                WordSearchState {        /**         * Constructs a LexTreeWordState         *          * @param wordNode         *                the word node         *          * @param lastNode         *                the previous word node         *          * @param wordSequence         *                the sequence of words triphone context         *          * @param logProbability         *                the probability of this word occuring         *           */        LexTreeEndWordState(WordNode wordNode, HMMNode lastNode,                WordSequence wordSequence, float smearTerm, float smearProb,                float logProbability) {            super(wordNode, lastNode, wordSequence, smearTerm, smearProb,                    logProbability);        }        public int getOrder() {            return 2;        }    }    /**     * Determines the insertion probability for the given unit lex node     *      * @param unitNode     *                the unit lex node     *      * @return the insertion probability     */    private float calculateInsertionProbability(UnitNode unitNode) {        int type =  unitNode.getType();        if (type == UnitNode.SIMPLE_UNIT) {            return logUnitInsertionProbability;        } else if (type == UnitNode.WORD_BEGINNING_UNIT) {            return logUnitInsertionProbability + logWordInsertionProbability;        } else if (type == UnitNode.SILENCE_UNIT) {            return logSilenceInsertionProbability;        } else { // must be filler            return logFillerInsertionProbability;        }    }    /**     * Retrieves the unigram smear from the given node     *      * @return the unigram smear     */    private float getUnigramSmear(Node node) {        float prob;        if (wantUnigramSmear) {            prob = node.getUnigramProbability() * unigramSmearWeight;        } else {            prob = logOne;        }        return prob;    }    /**     * Returns the smear term for the given word sequence     *      * @param ws     *                the word sequence     * @return the smear term for the word sequence     */    private float getSmearTermFromLanguageModel(WordSequence ws) {        return languageModel.getSmear(ws);    }    /**     * Gets the set of hmm nodes associated with the given end node     *      * @param endNode     *                the end node     *      * @return an array of associated hmm nodes     */    private HMMNode[] getHMMNodes(EndNode endNode) {        return hmmTree.getHMMNodes(endNode);    }    class ArcCache extends LinkedHashMap {        protected boolean removeEldestEntry(Map.Entry eldest) {            return size() > maxArcCacheSize;        }    }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -