utterance.java

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

JAVA
531
字号
/** * Portions Copyright 2001 Sun Microsystems, Inc. * Portions Copyright 1999-2001 Language Technologies Institute,  * Carnegie Mellon University. * All Rights Reserved.  Use is subject to license terms. *  * See the file "license.terms" for information on usage and * redistribution of this file, and for a DISCLAIMER OF ALL  * WARRANTIES. */package com.sun.speech.freetts;import com.sun.speech.freetts.util.SegmentRelationUtils;import java.io.PrintWriter;import java.util.List;import java.util.Iterator;import java.util.Vector;import java.io.Serializable;import java.util.StringTokenizer;/** * Holds all the data for an utterance to be spoken. * It is incrementally modified by various UtteranceProcessor * implementations.  An utterance contains a set of Features (essential * a set of properties) and a set of Relations. A Relation is an * ordered set of Item graphs. The utterance contains a set of * features and implements FeatureSet so that applications can set/get * features directly from the utterance. If a feature query is not * found in the utterance feature set, the query is forwarded to the * FeatureSet of the voice associated with the utterance. */public class Utterance implements FeatureSet, Serializable {    private Voice voice;    private FeatureSetImpl features;    private FeatureSetImpl relations;    private Vector listeners = null;    private boolean first;	// first in a connected series    private boolean last;	// last in a connected series    private FreeTTSSpeakable speakable;    /**     * Creates a new, empty utterance.     *     * @param voice the voice associated with the utterance     */    public Utterance(Voice voice) {	this.voice = voice;	listeners = new Vector();	features = new FeatureSetImpl();	relations = new FeatureSetImpl();    }    /**     * Creates an utterance with the given set of tokenized text.     *     * @param voice the voice associated with the utterance     * @param tokenList the list of tokens for this utterance     */    public Utterance(Voice voice, List tokenList) {	this(voice);	setTokenList(tokenList);    }    /**     * Sets the speakable item for this utterance.     *     * @param speakable the speakable item for this utterance     */    public void setSpeakable(FreeTTSSpeakable speakable) {	this.speakable = speakable;    }    /**     * Returns the queueitem associated with this utterance.     *     * @return the queue item     */    public FreeTTSSpeakable getSpeakable() {	return speakable;    }    /**     * Creates a new relation with the given name and adds it to this     * utterance.     *     * @param name the name of the new relation     *     * @return the newly created relation     */    public Relation createRelation(String name) {	Relation relation = new Relation(name, this);	relations.setObject(name, relation);	return relation;    }    /**     * Retrieves a relation from this utterance.     *     * @param name the name of the Relation     *     * @return the relation or null if the relation is not found     */    public Relation getRelation(String name) {	return (Relation) relations.getObject(name);    }    /**     * Determines if this utterance contains a relation with the given     * name.     *     * @param name the name of the relation of interest.     */    public boolean hasRelation(String name) {	return relations.isPresent(name);    }    /**     * Retrieves the Voice associated with this Utterance.     *     * @return the voice associated with this utterance.     */    public Voice getVoice() {	return voice;    }    /**     * Dumps this utterance in textual form.     *     * @param output where to send the formatted output     * @param pad the initial padding     * @param title the title to print when dumping out the utterance     * @param justRelations if true don't print voice features     */    public void dump(PrintWriter output, int pad, String title,	    	boolean justRelations) {	output.println(" ============ " + title + " ========== ");	if (!justRelations) {	    voice.dump(output, pad + 4, "Voice");	    features.dump(output, pad + 4, "Features");	}	relations.dump(output, pad + 4, "Relations");	output.flush();    }    /**     * Dumps this utterance in textual form.     *     * @param output where to send the formatted output     * @param pad the initial padding     * @param title the title to print when dumping out the utterance     */    public void dump(PrintWriter output, int pad, String title) {	dump(output, pad, title, false);    }    /**     * Dumps this utterance in textual form.     *     * @param output where to send the formatted output     * @param title the title to print when dumping out the utterance     */    public void dump(PrintWriter output, String title) {	dump(output, 0, title, false);    }    /**     * Dumps this utterance in textual form.     *     * @param title the title to print when dumping out the utterance     */    public void dump(String title) {	dump(new PrintWriter(System.out), 0, title, false);    }    /**     * Dumps the utterance in textual form     * @param title the title to print when dumping out the utterance     */    public void dumpRelations(String title) {	dump(new PrintWriter(System.out), 0, title, true);    }    /**     * Determines if the given feature is present. If the feature is     * not present in the utterance, the feature set of the voice is     * checked.     *     * @param name the name of the feature of interest     * @return true if the named feature is present     */    public boolean isPresent(String name) {	if (!features.isPresent(name)) {	    return getVoice().getFeatures().isPresent(name);	} else {	    return true;	}    }    /**     * Removes the named feature from this set of features.     *     * @param name the name of the feature of interest     */    public void remove(String name) {	features.remove(name);    }    /**     * Convenience method that returns the named feature as a string.     * 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     *     * @throws ClassCastException if theassociated value is not a     *   String     */    public String getString(String name) {	if (!features.isPresent(name)) {	    return getVoice().getFeatures().getString(name);	} else {	    return features.getString(name);	}    }    /**     * Convenience method that returns the named feature as a int.     * 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     *     * @throws ClassCastException if the associated value is not an     *   int     */    public int getInt(String name) {	if (!features.isPresent(name)) {	    return getVoice().getFeatures().getInt(name);	} else {	    return features.getInt(name);	}    }    /**     * Convenience method that returns the named feature as a float.     * 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     *     * @throws ClassCastException if the associated value is not a     *   float     */    public float getFloat(String name) {	if (!features.isPresent(name)) {

⌨️ 快捷键说明

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