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

📄 voice.java

📁 FreeTTS is a speech synthesis system written entirely in the Java programming language. It is based
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
                audioPlayer.close();                audioPlayer = null;            }        }        	if (!externalOutputQueue) {	    outputQueue.close();	}    }    /**     * Sets the baseline pitch.     *     * @param hertz the baseline pitch in hertz     */    public void setPitch(float hertz) {	this.pitch = hertz;    }    /**     * Retreives the baseline pitch.     *     * @return  the baseline pitch in hertz     */    public float getPitch() {	return pitch;    }    /**     * Sets the pitch range.     *     * @param range the range in hertz     */    public void setPitchRange(float range) {	this.range = range;    }    /**     * Gets the pitch range.     *     * @return the range in hertz     */    public float getPitchRange() {	return range;    }    /**     * Sets the pitch shift     *     * @param shift the pitch shift (1.0 is no shift)     */    public void setPitchShift(float shift) {	this.pitchShift = shift;    }    /**     * Gets the pitch shift.     *     * @return the pitch shift     */    public float getPitchShift() {	return pitchShift;    }    /**     * Sets the duration  stretch     *     * @param stretch the duration stretch (1.0 is no stretch)     */    public void setDurationStretch(float stretch) {	this.durationStretch = stretch;    }    /**     * Gets the duration Stretch     *     * @return the duration stretch     */    public float getDurationStretch() {	return durationStretch;    }    /**     * Sets the rate of speech.     *     * @param wpm words per minute     */    public void setRate(float wpm) {	if (wpm > 0 && wpm < 1000) {	    setDurationStretch(nominalRate / wpm);	}    }    /**     * Gets the rate of speech.     *     * @return words per minute     */    public float getRate() {	return durationStretch * nominalRate;    }    /**     * Sets the volume.     *     * @param vol the volume (0 to 1.0)     */    public void setVolume(float vol) {	volume = vol;    }    /**     * Gets the volume.     *     * @return the volume (0 to 1.0)     */    public float getVolume() {	return volume;    }    /**     * Gets the lexicon for this voice.     *     * @return the lexicon (or null if there is no lexicon)     */    public Lexicon getLexicon() {	return lexicon;    }    /**     * Sets the lexicon to be used by this voice.     *     * @param lexicon the lexicon to use     */    public void setLexicon(Lexicon lexicon) {	this.lexicon = lexicon;    }    /**     * Sets the dumpfile for this voice.     *     * @param waveDumpFile the dumpfile     */    public void setWaveDumpFile(String waveDumpFile) {	this.waveDumpFile = waveDumpFile;    }    /**     * Gets the dumpfile for this voice.     *     * @return the dumpfile     */    public String  getWaveDumpFile() {	return waveDumpFile;    }    private void traceStack() {	new Throwable().printStackTrace();    }    /**     * Sets the audio player associated with this voice. The caller is     * responsible for closing this player.     *     * @param player the audio player     */    public void setAudioPlayer(AudioPlayer player) {	audioPlayer = player;        externalAudioPlayer = true;    }    /**     * Gets the default audio player for this voice.  The return     * value will be non-null only if the DEFAULT_AUDIO_PLAYER     * system property has been set to the name of an AudioPlayer     * class, and that class is able to be instantiated via a     * no arg constructor.  getAudioPlayer will automatically set     * the audio player for this voice to the default audio player     * if the audio player has not yet been set.     *     * @see #DEFAULT_AUDIO_PLAYER     * @see #getAudioPlayer     * @return the default AudioPlayer     */    public AudioPlayer getDefaultAudioPlayer() throws InstantiationException {        if (defaultAudioPlayer != null) {            return defaultAudioPlayer;        }                String className = Utilities.getProperty(            DEFAULT_AUDIO_PLAYER, DEFAULT_AUDIO_PLAYER_DEFAULT);        try {            Class cls = Class.forName(className);            defaultAudioPlayer = (AudioPlayer) cls.newInstance();            return defaultAudioPlayer;        } catch (ClassNotFoundException e) {            throw new InstantiationException("Can't find class " + className);        } catch (IllegalAccessException e) {            throw new InstantiationException("Can't find class " + className);        } catch (ClassCastException e) {            throw new InstantiationException(className + " cannot be cast "                                             + "to AudioPlayer");        }    }        /**     * Gets the audio player associated with this voice.  If the     * audio player has not yet been set, the value will default     * to the return value of getDefaultAudioPlayer.     *     * @see #getDefaultAudioPlayer     * @return the audio player     */    public AudioPlayer getAudioPlayer() {        if (audioPlayer == null) {            try {                audioPlayer = getDefaultAudioPlayer();            } catch (InstantiationException e) {                e.printStackTrace();            }        }	return audioPlayer;    }    /**     * Get a resource for this voice.     * By default, the voice is searched for in the package     * to which the voice class belongs. Subclasses are free to     * override this behaviour.     */    protected URL getResource(String resource) {        return this.getClass().getResource(resource);    }    /**     * Set the name of this voice.     * [[[TODO: any standard format to the name?]]]     *     * @param name the name to assign this voice     */    protected void setName(String name) {        this.name = name;    }    /**     * Get the name of this voice.     *     * @return the name     */    public String getName() {        return name;    }    /**     * Returns the name of this Voice.     *     * @return the name of this Voice     */    public String toString() {        return getName();    }    /**     * Set the gender of this voice.     *     * @param gender the gender to assign     */    protected void setGender(Gender gender) {        this.gender = gender;    }    /**     * Get the gender of this voice.     *     * @return the gender of this voice     */    public Gender getGender() {        return gender;    }    /**     * Set the age of this voice.     *     * @param age the age to assign     */    protected void setAge(Age age) {        this.age = age;    }    /**     * Get the age of this voice.     *     * @return the age of this voice     */    public Age getAge() {        return age;    }    /**     * Set the description of this voice.     *     * @param description the human readable description to assign     */    protected void setDescription(String description) {        this.description = description;    }    /**     * Get the description of this voice.     *     * @return the human readable description of this voice     */    public String getDescription() {        return description;    }    /**     * Set the locale of this voice.     *     * @param locale the locale of this voice.     */    protected void setLocale(Locale locale) {        this.locale = locale;    }    /**     * Get the locale of this voice.     *     * @return the locale of this voice.     */    public Locale getLocale() {        return locale;    }    /**     * Set the domain of this voice.     *     * @param domain the domain of this voice.  For example,     * &quot;general&quot;, &quot;time&quot;, or     * &quot;weather&quot;.     */    protected void setDomain(String domain) {        this.domain = domain;    }    /**     * Get the domain of this voice.     *      * @return the domain of this voice.  For example,     * &quot;general&quot;, &quot;time&quot;, or     * &quot;weather&quot;.     */    public String getDomain() {        return domain;    }    /**     * Sets the voice style. This parameter is designed for human     * interpretation. Values might include "business", "casual",     * "robotic", "breathy"     *     * @param style the stile of this voice.     */    public void setStyle(String style) {        this.style = style;    }    /**     * Gets the voice style. This parameter is designed for human     * interpretation. Values might include "business", "casual",     * "robotic", "breathy".     */    public String getStyle() {        return style;    }    /**     * Sets the organization which created this voice.  For example     * "cmu", "sun", ...     *     * @param organization the name of the organization     */    protected void setOrganization(String organization) {        this.organization = organization;    }    /**     * Gets the organization which created this voice.  For example     * "cmu", "sun", ...     *     * @return the name of the organization     */    public String getOrganization() {        return organization;    }    /**     * Returns the AudioOutput processor to be used by this voice.     * Derived voices typically override this to customize behaviors.     *      * @return the audio output processor     *      * @throws IOException if an IO error occurs while getting     *     processor     */    protected abstract UtteranceProcessor getAudioOutput() throws IOException ;    /**     * Tokenizes a FreeTTSSpeakable     */    private class FreeTTSSpeakableTokenizer  {	FreeTTSSpeakable speakable;	Tokenizer tok = getTokenizer();	/**	 * Constructor.         *	 * @param speakable the queue item to be pretokenized	 */    	public FreeTTSSpeakableTokenizer(FreeTTSSpeakable speakable) {	    this.speakable = speakable;	    if (speakable.isPlainText()) {		tok.setInputText(speakable.getText());	    } else if (speakable.isStream()) {		Reader reader = new BufferedReader(		    new InputStreamReader(speakable.getInputStream()));		tok.setInputReader(reader);	    } else if (speakable.isDocument()) {		tok.setInputText(documentToString(speakable.getDocument()));	    }	}	    	/**	 * Returns an iterator for this text item.	 */	public Iterator iterator() {	    return new Iterator() {		boolean first = true;		Token savedToken = null;		/**		 * Determines if there are more utterances		 *		 * @return true if there are more tokens		 */		public boolean hasNext() {		    return savedToken != null || tok.hasMoreTokens();		}		/**		 * Returns the next utterance.                 *		 * @return the next utterance (as an object) or		 *    null if there is are no utterances left		 */		public Object next() {		    ArrayList tokenList = new ArrayList();		    Utterance utterance = null;		    if (savedToken != null) {			tokenList.add(savedToken);			savedToken = null;		    }		    while (tok.hasMoreTokens()) {			Token token = tok.getNextToken();			if ((token.getWord().length() == 0) ||			    (tokenList.size() > 500) ||			    tok.isBreak()) {			    savedToken = token;			    break;			}			tokenList.add(token);		    }		    utterance =  new Utterance(Voice.this, tokenList);		    utterance.setSpeakable(speakable);		    utterance.setFirst(first);		    first = false;                    boolean isLast =                         (!tok.hasMoreTokens() &&                          (savedToken == null ||                           savedToken.getWord().length() == 0));		    utterance.setLast(isLast);		    return utterance;		}		public void remove() {                    throw new UnsupportedOperationException("remove");  		}	    };	}    }}  

⌨️ 快捷键说明

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