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

📄 basesynthesizer.java

📁 这是java 开发的的免费语音播放插件,很值得学习参考!!!!!!!!!!!!111
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/** * Copyright 1998-2001 Sun Microsystems, Inc. *  * 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.engine.synthesis;import java.net.URL;import java.net.MalformedURLException;import java.io.IOException;import java.util.Vector;import java.util.Enumeration;import javax.speech.EngineListener;import javax.speech.EngineStateError;import javax.speech.SpeechEvent;import javax.speech.SpeechError;import javax.speech.synthesis.JSMLException;import javax.speech.synthesis.Synthesizer;import javax.speech.synthesis.SynthesizerListener;import javax.speech.synthesis.SynthesizerEvent;import javax.speech.synthesis.SynthesizerModeDesc;import javax.speech.synthesis.SynthesizerProperties;import javax.speech.synthesis.Speakable;import javax.speech.synthesis.SpeakableListener;import com.sun.speech.engine.BaseEngine;import com.sun.speech.engine.BaseEngineProperties;import com.sun.speech.engine.SpeechEventUtilities;import com.sun.speech.engine.SpeechEventDispatcher;/** * Supports the JSAPI 1.0 <code>Synthesizer</code> interface that * performs the core non-engine-specific functions. *  * <p>An actual JSAPI synthesizer implementation needs to extend or * modify this implementation. */abstract public class BaseSynthesizer extends BaseEngine    implements Synthesizer, SpeechEventDispatcher {    /**     * Set of speakable listeners belonging to the <code>Synthesizer</code>.     * Each item on queue may have an individual listener too.     *     * @see SpeakableListener     */    protected Vector speakableListeners;    /**     * The set of voices available in this <code>Synthesizer</code>.     * The list can be created in the constructor methods.     */    protected VoiceList voiceList;        /**     * Creates a new Synthesizer in the <code>DEALLOCATED</code> state.     *     * @param mode the operating mode of this <code>Synthesizer</code>     */    public BaseSynthesizer(SynthesizerModeDesc mode) {        super(mode);        speakableListeners = new Vector();        voiceList = new VoiceList(mode);    }    /**     * Speaks JSML text provided as a <code>Speakable</code> object.     *     * @param jsmlText the JSML text to speak     * @param listener the listener to be notified as the     *   <code>jsmlText</code> is processed     *     * @throws JSMLException if the JSML text contains errors     * @throws EngineStateError      *   if this <code>Synthesizer</code> in the <code>DEALLOCATED</code> or      *   <code>DEALLOCATING_RESOURCES</code> states     */    public void speak(Speakable jsmlText, SpeakableListener listener)        throws JSMLException, EngineStateError {        checkEngineState(DEALLOCATED | DEALLOCATING_RESOURCES);        BaseSynthesizerQueueItem item = createQueueItem();        item.setData(this, jsmlText, listener);        appendQueue(item);    }    /**     * Speaks JSML text provided as a <code>URL</code>.     *     * @param jsmlURL the <code>URL</code> containing JSML text     * @param listener the listener to be notified as the     *   JSML text is processed     *     * @throws EngineStateError      *   if this <code>Synthesizer</code> in the <code>DEALLOCATED</code> or      *   <code>DEALLOCATING_RESOURCES</code> states     * @throws IOException     *    if errors are encountered with the <code>JSMLurl</code>     * @throws JSMLException if the JSML text contains errors     * @throws MalformedURLException     *    if errors are encountered with the <code>JSMLurl</code>     */    public void speak(URL jsmlURL, SpeakableListener listener)        throws JSMLException, MalformedURLException,        IOException, EngineStateError {        checkEngineState(DEALLOCATED | DEALLOCATING_RESOURCES);        BaseSynthesizerQueueItem item = createQueueItem();        item.setData(this, jsmlURL, listener);        appendQueue(item);    }    /**     * Speaks JSML text provided as a <code>String</code>.     *     * @param jsmlText a <code>String</code> containing JSML.     * @param listener the listener to be notified as the     *   JSML text is processed     *     * @throws EngineStateError      *   if this <code>Synthesizer</code> in the <code>DEALLOCATED</code> or      *   <code>DEALLOCATING_RESOURCES</code> states     * @throws JSMLException if the JSML text contains errors     */    public void speak(String jsmlText, SpeakableListener listener)        throws JSMLException, EngineStateError {        checkEngineState(DEALLOCATED | DEALLOCATING_RESOURCES);        BaseSynthesizerQueueItem item = createQueueItem();        item.setData(this, jsmlText, false, listener);        appendQueue(item);    }    /**     * Speaks a plain text <code>String</code>.  No JSML parsing is     * performed.     *     * @param text a <code>String</code> containing plain text.     * @param listener the listener to be notified as the     *   text is processed     *     * @throws EngineStateError      *   if this <code>Synthesizer</code> in the <code>DEALLOCATED</code> or      *   <code>DEALLOCATING_RESOURCES</code> states     */    public void speakPlainText(String text, SpeakableListener listener)        throws EngineStateError {        checkEngineState(DEALLOCATED | DEALLOCATING_RESOURCES);        try {            BaseSynthesizerQueueItem item = createQueueItem();            item.setData(this, text, true, listener);            appendQueue(item);        } catch (JSMLException e) {            throw new RuntimeException("JSMLException should never occur");        }    }    /**     * Returns a String of the names of all the states implied     * in the given bit pattern.     *     * @param state the bit pattern of states     *     * @return a String of the names of all the states implied     *   in the given bit pattern.     */    protected String stateToString(long state) {	StringBuffer buf = new StringBuffer();        if ((state & Synthesizer.QUEUE_EMPTY) != 0)            buf.append(" QUEUE_EMPTY ");        if ((state & Synthesizer.QUEUE_NOT_EMPTY) != 0)            buf.append(" QUEUE_NOT_EMPTY ");	return super.stateToString(state) + buf.toString();    }    /**     * Puts an item on the speaking queue and sends a queue updated     * event.     *     * @param item the item to add to the queue     *     */    abstract protected void appendQueue(BaseSynthesizerQueueItem item);    /**     * Optional method that converts a text string to a phoneme string.     *     * @param text     *   plain text to be converted to phonemes     *     * @return     *   IPA phonemic representation of text or <code>null</code>     *     * @throws EngineStateError      *   if this <code>Synthesizer</code> in the <code>DEALLOCATED</code> or      *   <code>DEALLOCATING_RESOURCES</code> states     */    public String phoneme(String text) throws EngineStateError {        checkEngineState(DEALLOCATED | DEALLOCATING_RESOURCES);                // BaseSynthesizer does not implement phoneme.  The sub-class        // should override this method if it supports text to phoneme        // conversion.  Returning null is legal behavior.        //        return null;    }    /**     * Returns an enumeration of the queue.     *     * @return     *   an <code>Enumeration</code> of the speech output queue or     *   <code>null</code>.     *     * @throws EngineStateError      *   if this <code>Synthesizer</code> in the <code>DEALLOCATED</code> or      *   <code>DEALLOCATING_RESOURCES</code> states     */    abstract public Enumeration enumerateQueue() throws EngineStateError;    /**     * Cancels the item at the top of the queue.     *     * @throws EngineStateError      *   if this <code>Synthesizer</code> in the <code>DEALLOCATED</code> or      *   <code>DEALLOCATING_RESOURCES</code> states     */    abstract public void cancel() throws EngineStateError;

⌨️ 快捷键说明

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