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

📄 result.java

📁 It is the Speech recognition software. It is platform independent. To execute the source code,
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
     */    public FrameStatistics[] getFrameStatistics() {        return null;	// [[[ TBD:  write me ]]]    }    /**     * Gets the starting frame number for the result     *     * @return the starting frame number for the result     */    public int getStartFrame() {        return 0;    }    /**     * Gets the ending frame number for the result     *     * @return the ending frame number for the result     */    public int getEndFrame() {        return 0;	// [[[ TBD: write me ]]]    }    /**     * Gets the feature frames associated with this result     *     * @return the set of feature frames associated with this result,     *    or null if     * the frames are not available.     */    public Data[] getDataFrames() {        Data[] features = null;        // find the best token, and then trace back for all the features        Token token = getBestToken();        if (token != null) {            List featureList = new LinkedList();            do {                Data feature = token.getData();                featureList.add(0, feature);                token = token.getPredecessor();            } while (token != null);            features = new Data[featureList.size()];            featureList.toArray(features);        }        return features;    }    /**     * Returns the string of the best result, removing any filler words.     * This method first attempts to return the best final result, that is,     * the result that has reached the final state of the search space.      * If there are no best final results, then the best non-final result,     * that is, the one that did not reach the final state, is returned.     *     * @return the string of the best result, removing any filler     * words     */    public String getBestResultNoFiller() {        Token token = getBestToken();        if (token == null) {            return "";        } else {            return token.getWordPathNoFiller();        }    }    /**     * Returns the string of the best final result, removing any filler words.     * A final result is a path that has reached the final state.     * A Result object can also contain paths that did not reach the     * final state, and those paths are not returned by this method.     *     * @return the string of the best result, removing any filler     * words, or null if there are no best results     */    public String getBestFinalResultNoFiller() {        Token token = getBestFinalToken();        if (token == null) {            return "";        } else {            return token.getWordPathNoFiller();        }    }    /**     * Returns the string of words (with timestamp) for this token.     *     * @param wantFiller true if we want filler words included, false otherwise     * @param wordTokenFirst true if the word tokens come before other types     *     of tokens     *     * @return the string of words     */    public String getTimedBestResult(boolean wantFiller,                                     boolean wordTokenFirst) {        Token token = getBestToken();        if (token == null) {            return "";        } else {            if (wordTokenFirst) {                return getTimedWordPath(token, wantFiller);            } else {                return getTimedWordTokenLastPath(token, wantFiller);            }        }    }    /**     * Returns the string of words (with timestamp) for this token.     * This method assumes that the word tokens come before other types     * of token.     *     * @param wantFiller true if we want filler words, false otherwise     *     * @return the string of words     */    private String getTimedWordPath(Token token, boolean wantFiller) {        StringBuffer sb = new StringBuffer();        // get to the first emitting token        while (token != null && !token.isEmitting()) {            token = token.getPredecessor();        }        if (token != null) {            Data lastWordFirstFeature = token.getData();            Data lastFeature = lastWordFirstFeature;            token = token.getPredecessor();            while (token != null) {                if (token.isWord()) {                    Word word = token.getWord();                    if (wantFiller || !word.isFiller()) {                        addWord(sb, word,                                 (FloatData) lastFeature,                                (FloatData) lastWordFirstFeature);                    }                    lastWordFirstFeature = lastFeature;                }                Data feature = token.getData();                if (feature != null) {                    lastFeature = feature;                }                token = token.getPredecessor();            }        }        return sb.toString();    }    /**     * Returns the string of words for this token, each with the starting     * sample number as the timestamp. This method assumes that the word     * tokens come after the unit and hmm tokens.     *     * @return the string of words, each with the starting sample number     */    private String getTimedWordTokenLastPath(Token token, boolean wantFiller) {        StringBuffer sb = new StringBuffer();        Word word = null;        Data lastFeature = null;        Data lastWordFirstFeature = null;        while (token != null) {            if (token.isWord()) {                if (word != null) {                    if (wantFiller || !word.isFiller()) {                        addWord(sb, word,                                (FloatData) lastFeature,                                (FloatData) lastWordFirstFeature);                    }                    word = token.getWord();                    lastWordFirstFeature = lastFeature;                }            }            Data feature = token.getData();            if (feature != null) {                lastFeature = feature;                if (lastWordFirstFeature == null) {                    lastWordFirstFeature = lastFeature;                }            }            token = token.getPredecessor();        }        return sb.toString();    }    /**     * Adds the given word into the given string buffer with the start and     * end times from the given features.     *     * @param sb the StringBuffer into which the word is added     * @param word the word to add     * @param startFeature the starting feature     * @param endFeature tne ending feature     */    private void addWord(StringBuffer sb, Word word,                         FloatData startFeature, FloatData endFeature) {        float startTime = ((float) startFeature.getFirstSampleNumber()/			   startFeature.getSampleRate());        float endTime = ((float) endFeature.getFirstSampleNumber()/			 endFeature.getSampleRate());        if (sb.length() > 0) {            sb.insert(0, " ");        }        sb.insert(0, (word.getSpelling() + "(" + startTime + "," +                       endTime + ")"));    }    /**     * Returns a string representation of this object     */    public String toString() {        Token token = getBestToken();        if (token == null) {            return "";        } else {            return token.getWordPath();        }    }    /**     * Sets the results as a final result     *     * @param finalResult if true, the result should be made final     */    void setFinal(boolean finalResult) {        this.isFinal = finalResult;    }    /**     * Determines if the Result is valid. This is used for testing and     * debugging     *     * @return true if the result is properly formed.     *     */    public boolean validate() {        boolean valid = true;        for (Iterator i = activeList.iterator(); i.hasNext();) {            Token token = (Token) i.next();            if (!token.validate()) {                valid = false;                token.dumpTokenPath();            }        }        return valid;    }        /**     * Sets the reference text     * @param ref the reference text     */    public void setReferenceText(String ref) {        reference = ref;    }            /**     * Retrieves the reference text. The reference text is a transcript of     * the text that was spoken.     *      * @return the reference text or null if no reference text exists.     */    public String getReferenceText() {        return reference;    }}

⌨️ 快捷键说明

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