utterance.java

来自「这是java 开发的的免费语音播放插件,很值得学习参考!!!!!!!!!!!!1」· Java 代码 · 共 531 行 · 第 1/2 页

JAVA
531
字号
	    return getVoice().getFeatures().getFloat(name);	} else {	    return features.getFloat(name);	}    }    /**     * Returns the named feature as an object.     * If the named feature is not present in the utterance, then this     * attempts to retrieve it from the voice.     *     * @param name the name of the feature     *     * @return the value associated with the name or null if the value     *   is not found     */    public Object getObject(String name) {	if (!features.isPresent(name)) {	    return getVoice().getFeatures().getObject(name);	} else {	    return features.getObject(name);	}    }    /**     * Convenience method that sets the named feature as an int.     *     * @param name the name of the feature     * @param value the value of the feature     */    public void setInt(String name, int value) {	features.setInt(name, value);    }    /**     * Convenience method that sets the named feature as a float.     *     * @param name the name of the feature     * @param value the value of the feature     */    public void setFloat(String name, float value) {	features.setFloat(name, value);    }    /**     * Convenience method that sets the named feature as a String.     *     * @param name the name of the feature     * @param value the value of the feature     */    public void setString(String name, String value) {	features.setString(name, value);    }    /**     * Sets the named feature.     *     * @param name the name of the feature     * @param value the value of the feature     */    public void setObject(String name, Object value) {	features.setObject(name, value);    }    /**     * Returns the Item in the given Relation associated with the given time.     *     * @param relation the name of the relation     * @param time the time     *     * @throws IllegalStateException if the Segment durations     *   have not been calculated in the Utterance or if the     *   given relation is not present in the Utterance     */    public Item getItem(String relation, float time) {                Relation segmentRelation = null;                if ((segmentRelation = getRelation(Relation.SEGMENT)) == null) {            throw new IllegalStateException                ("Utterance has no Segment relation");        }                String pathName = null;        if (relation.equals(Relation.SEGMENT)) {            // do nothing        } else if (relation.equals(Relation.SYLLABLE)) {            pathName = "R:SylStructure.parent.R:Syllable";        } else if (relation.equals(Relation.SYLLABLE_STRUCTURE)) {            pathName = "R:SylStructure.parent.parent";        } else if (relation.equals(Relation.WORD)) {            pathName = "R:SylStructure.parent.parent.R:Word";        } else if (relation.equals(Relation.TOKEN)) {	     pathName = "R:SylStructure.parent.parent.R:Token.parent";        } else if (relation.equals(Relation.PHRASE)) {            pathName = "R:SylStructure.parent.parent.R:Phrase.parent";        } else {            throw new IllegalArgumentException                ("Utterance.getItem(): relation cannot be " + relation);        }                PathExtractor path = new PathExtractorImpl(pathName, false);	         // get the Item in the Segment Relation with the given time        Item segmentItem = SegmentRelationUtils.getItem            (segmentRelation, time);                if (relation.equals(Relation.SEGMENT)) {            return segmentItem;        } else if (segmentItem != null) {            return path.findItem(segmentItem);        } else {            return null;        }    }    /**     * Returns the duration of this Utterance in seconds. It does this     * by looking at last Item in the following Relations, in this order:     * Segment, Target. If none of these Relations exist, or if these     * Relations contain no Items, an IllegalStateException will be thrown.     *     * @return the duration of this Utterance in seconds     */    public float getDuration() {	float duration = -1;	if ((duration = getLastFloat(Relation.SEGMENT, "end")) == -1) {	    if ((duration = getLastFloat(Relation.TARGET, "pos")) == -1) {		throw new IllegalStateException		    ("Utterance: Error finding duration");	    }	}	return duration;    }    /**     * Returns the float feature of the last Item in the named     * Relation.     *     * @return the float feature of the last Item in the named Relation,     * or -1 otherwise     */    private float getLastFloat(String relationName, String feature) {	float duration = -1;	Relation relation;	if ((relation = getRelation(relationName)) != null) {	    Item lastItem = relation.getTail();	    if (lastItem != null) {		duration = lastItem.getFeatures().getFloat(feature);	    }	}	return duration;    }    /**     * Sets the token list for this utterance. Note that this could be     * optimized by turning the token list directly into the token     * relation.      *     * <p>[[[ TODO: future optimization, turn this into a token     *    relation directly ]]]     *     * @param tokenList the tokenList     */    /*    private void setTokenList(List tokenList) {	StringBuffer sb = new StringBuffer();	for (Iterator i = tokenList.iterator(); i.hasNext(); ) {	    sb.append(i.next().toString());	}	setString("input_text", sb.toString());    }    */    /**     * Sets the input text for this utterance     *      * @param tokenList the set of tokens for this utterance     *     */    private void setInputText(List tokenList) {	StringBuffer sb = new StringBuffer();	for (Iterator i = tokenList.iterator(); i.hasNext(); ) {	    sb.append(i.next().toString());	}	setString("input_text", sb.toString());    }    /**     * Sets the token list for this utterance. Note that this could be     * optimized by turning the token list directly into the token     * relation.      *     * @param tokenList the tokenList     *     */    private void setTokenList(List tokenList) {	setInputText(tokenList);	Relation relation = createRelation(Relation.TOKEN);	for (Iterator i = tokenList.iterator(); i.hasNext(); ) {	    Token token = (Token) i.next();	    String tokenWord = token.getWord();	    	    if (tokenWord != null && tokenWord.length() > 0) {		Item item = relation.appendItem();				FeatureSet featureSet = item.getFeatures();		featureSet.setString("name", tokenWord);		featureSet.setString("whitespace", token.getWhitespace());		featureSet.setString("prepunctuation", 			token.getPrepunctuation());		featureSet.setString("punc", token.getPostpunctuation());		featureSet.setString("file_pos", 			String.valueOf(token.getPosition()));		featureSet.setString("line_number", 			String.valueOf(token.getLineNumber()));			    }	}    }    /**     * Returns true if this utterance is the first is a series of     * utterances.     *     * @return true if this is the first utterance in a series of     *     connected utterances.     */    public boolean isFirst() {	return first;    }    /**     * Sets this utterance as the first in a series.     *     * @param first if true, the item is the first in a series     */    public void setFirst(boolean first) {	this.first = first;    }    /**     * Returns true if this utterance is the last is a series of     * utterances.     *     * @return true if this is the last utterance in a series of     *     connected utterances.     */    public boolean isLast() {	return last;    }    /**     * Sets this utterance as the last in a series.     *     * @param last if true, the item is the last in a series     */    public void setLast(boolean last) {	this.last = last;    }}

⌨️ 快捷键说明

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