com.sun.speech.engine.synthesis
Class BaseSynthesizer

java.lang.Object
  extended bycom.sun.speech.engine.BaseEngine
      extended bycom.sun.speech.engine.synthesis.BaseSynthesizer
All Implemented Interfaces:
javax.speech.Engine, SpeechEventDispatcher, javax.speech.synthesis.Synthesizer
Direct Known Subclasses:
FreeTTSSynthesizer, TextSynthesizer

public abstract class BaseSynthesizer
extends BaseEngine
implements javax.speech.synthesis.Synthesizer, SpeechEventDispatcher

Supports the JSAPI 1.0 Synthesizer interface that performs the core non-engine-specific functions.

An actual JSAPI synthesizer implementation needs to extend or modify this implementation.


Field Summary
protected  java.util.Vector speakableListeners
          Set of speakable listeners belonging to the Synthesizer.
protected  VoiceList voiceList
          The set of voices available in this Synthesizer.
 
Fields inherited from class com.sun.speech.engine.BaseEngine
audioManager, CLEAR_ALL_STATE, engineListeners, engineModeDesc, engineProperties, engineState, engineStateLock
 
Fields inherited from interface javax.speech.synthesis.Synthesizer
QUEUE_EMPTY, QUEUE_NOT_EMPTY
 
Fields inherited from interface javax.speech.Engine
ALLOCATED, ALLOCATING_RESOURCES, DEALLOCATED, DEALLOCATING_RESOURCES, PAUSED, RESUMED
 
Constructor Summary
BaseSynthesizer(javax.speech.synthesis.SynthesizerModeDesc mode)
          Creates a new Synthesizer in the DEALLOCATED state.
 
Method Summary
 void addSpeakableListener(javax.speech.synthesis.SpeakableListener listener)
          Adds a SpeakableListener to this Synthesizer.
protected abstract  void appendQueue(BaseSynthesizerQueueItem item)
          Puts an item on the speaking queue and sends a queue updated event.
abstract  void cancel()
          Cancels the item at the top of the queue.
abstract  void cancel(java.lang.Object source)
          Cancels a specific object on the queue.
abstract  void cancelAll()
          Cancels all items on the output queue.
protected  BaseEngineProperties createEngineProperties()
          Factory constructor for EngineProperties object.
protected  BaseSynthesizerQueueItem createQueueItem()
          Factory method that creates a BaseSynthesizerQueueItem.
 void dispatchSpeechEvent(javax.speech.SpeechEvent event)
          Dispatches a SpeechEvent.
abstract  java.util.Enumeration enumerateQueue()
          Returns an enumeration of the queue.
 void fireQueueEmptied(javax.speech.synthesis.SynthesizerEvent event)
          Utility function that sends a QUEUE_EMPTIED event to all SynthesizerListeners.
 void fireQueueUpdated(javax.speech.synthesis.SynthesizerEvent event)
          Utility function that sends a QUEUE_UPDATED event to all SynthesizerListeners.
 javax.speech.synthesis.SynthesizerProperties getSynthesizerProperties()
          Returns the SynthesizerProperties object (a JavaBean).
protected  VoiceList getVoiceList()
          Returns the list of voices for this Synthesizer.
 java.lang.String phoneme(java.lang.String text)
          Optional method that converts a text string to a phoneme string.
 void postQueueEmptied(long oldState, long newState)
          Utility function that generates QUEUE_EMPTIED event and posts it to the event queue.
 void postQueueUpdated(boolean topOfQueueChanged, long oldState, long newState)
          Utility function that generates QUEUE_UPDATED event and posts it to the event queue.
 void removeSpeakableListener(javax.speech.synthesis.SpeakableListener listener)
          Removes a SpeakableListener from this Synthesizer.
 void speak(javax.speech.synthesis.Speakable jsmlText, javax.speech.synthesis.SpeakableListener listener)
          Speaks JSML text provided as a Speakable object.
 void speak(java.lang.String jsmlText, javax.speech.synthesis.SpeakableListener listener)
          Speaks JSML text provided as a String.
 void speak(java.net.URL jsmlURL, javax.speech.synthesis.SpeakableListener listener)
          Speaks JSML text provided as a URL.
 void speakPlainText(java.lang.String text, javax.speech.synthesis.SpeakableListener listener)
          Speaks a plain text String.
protected  java.lang.String stateToString(long state)
          Returns a String of the names of all the states implied in the given bit pattern.
 
Methods inherited from class com.sun.speech.engine.BaseEngine
addEngineListener, allocate, checkEngineState, deallocate, fireEngineAllocated, fireEngineAllocatingResources, fireEngineDeallocated, fireEngineDeallocatingResources, fireEnginePaused, fireEngineResumed, getAudioManager, getEngineModeDesc, getEngineProperties, getEngineState, getVocabManager, handleAllocate, handleDeallocate, handlePause, handleResume, pause, postEngineAllocated, postEngineAllocatingResources, postEngineDeallocated, postEngineDeallocatingResources, postEnginePaused, postEngineResumed, removeEngineListener, resume, setEngineModeDesc, setEngineState, testEngineState, toString, waitEngineState
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface javax.speech.Engine
addEngineListener, allocate, deallocate, getAudioManager, getEngineModeDesc, getEngineProperties, getEngineState, getVocabManager, pause, removeEngineListener, resume, testEngineState, waitEngineState
 

Field Detail

speakableListeners

protected java.util.Vector speakableListeners
Set of speakable listeners belonging to the Synthesizer. Each item on queue may have an individual listener too.

See Also:
SpeakableListener

voiceList

protected VoiceList voiceList
The set of voices available in this Synthesizer. The list can be created in the constructor methods.

Constructor Detail

BaseSynthesizer

public BaseSynthesizer(javax.speech.synthesis.SynthesizerModeDesc mode)
Creates a new Synthesizer in the DEALLOCATED state.

Parameters:
mode - the operating mode of this Synthesizer
Method Detail

speak

public void speak(javax.speech.synthesis.Speakable jsmlText,
                  javax.speech.synthesis.SpeakableListener listener)
           throws javax.speech.synthesis.JSMLException,
                  javax.speech.EngineStateError
Speaks JSML text provided as a Speakable object.

Specified by:
speak in interface javax.speech.synthesis.Synthesizer
Parameters:
jsmlText - the JSML text to speak
listener - the listener to be notified as the jsmlText is processed
Throws:
javax.speech.synthesis.JSMLException - if the JSML text contains errors
javax.speech.EngineStateError - if this Synthesizer in the DEALLOCATED or DEALLOCATING_RESOURCES states

speak

public void speak(java.net.URL jsmlURL,
                  javax.speech.synthesis.SpeakableListener listener)
           throws javax.speech.synthesis.JSMLException,
                  java.net.MalformedURLException,
                  java.io.IOException,
                  javax.speech.EngineStateError
Speaks JSML text provided as a URL.

Specified by:
speak in interface javax.speech.synthesis.Synthesizer
Parameters:
jsmlURL - the URL containing JSML text
listener - the listener to be notified as the JSML text is processed
Throws:
javax.speech.EngineStateError - if this Synthesizer in the DEALLOCATED or DEALLOCATING_RESOURCES states
java.io.IOException - if errors are encountered with the JSMLurl
javax.speech.synthesis.JSMLException - if the JSML text contains errors
java.net.MalformedURLException - if errors are encountered with the JSMLurl

speak

public void speak(java.lang.String jsmlText,
                  javax.speech.synthesis.SpeakableListener listener)
           throws javax.speech.synthesis.JSMLException,
                  javax.speech.EngineStateError
Speaks JSML text provided as a String.

Specified by:
speak in interface javax.speech.synthesis.Synthesizer
Parameters:
jsmlText - a String containing JSML.
listener - the listener to be notified as the JSML text is processed
Throws:
javax.speech.EngineStateError - if this Synthesizer in the DEALLOCATED or DEALLOCATING_RESOURCES states
javax.speech.synthesis.JSMLException - if the JSML text contains errors

speakPlainText

public void speakPlainText(java.lang.String text,
                           javax.speech.synthesis.SpeakableListener listener)
                    throws javax.speech.EngineStateError
Speaks a plain text String. No JSML parsing is performed.

Specified by:
speakPlainText in interface javax.speech.synthesis.Synthesizer
Parameters:
text - a String containing plain text.
listener - the listener to be notified as the text is processed
Throws:
javax.speech.EngineStateError - if this Synthesizer in the DEALLOCATED or DEALLOCATING_RESOURCES states

stateToString

protected java.lang.String stateToString(long state)
Returns a String of the names of all the states implied in the given bit pattern.

Overrides:
stateToString in class BaseEngine
Parameters:
state - the bit pattern of states
Returns:
a String of the names of all the states implied in the given bit pattern.

appendQueue

protected abstract void appendQueue(BaseSynthesizerQueueItem item)
Puts an item on the speaking queue and sends a queue updated event.

Parameters:
item - the item to add to the queue

phoneme

public java.lang.String phoneme(java.lang.String text)
                         throws javax.speech.EngineStateError
Optional method that converts a text string to a phoneme string.

Specified by:
phoneme in interface javax.speech.synthesis.Synthesizer
Parameters:
text - plain text to be converted to phonemes
Returns:
IPA phonemic representation of text or null
Throws:
javax.speech.EngineStateError - if this Synthesizer in the DEALLOCATED or DEALLOCATING_RESOURCES states

enumerateQueue

public abstract java.util.Enumeration enumerateQueue()
                                              throws javax.speech.EngineStateError
Returns an enumeration of the queue.

Specified by:
enumerateQueue in interface javax.speech.synthesis.Synthesizer
Returns:
an Enumeration of the speech output queue or null.
Throws:
javax.speech.EngineStateError - if this Synthesizer in the DEALLOCATED or DEALLOCATING_RESOURCES states

cancel

public abstract void cancel()
                     throws javax.speech.EngineStateError
Cancels the item at the top of the queue.

Specified by:
cancel in interface javax.speech.synthesis.Synthesizer
Throws:
javax.speech.EngineStateError - if this Synthesizer in the DEALLOCATED or DEALLOCATING_RESOURCES states

cancel

public abstract void cancel(java.lang.Object source)
                     throws java.lang.IllegalArgumentException,
                            javax.speech.EngineStateError
Cancels a specific object on the queue.

Specified by:
cancel in interface javax.speech.synthesis.Synthesizer
Parameters:
source - object to be removed from the speech output queue
Throws:
java.lang.IllegalArgumentException - if the source object is not found in the speech output queue.
javax.speech.EngineStateError - if this Synthesizer in the DEALLOCATED or DEALLOCATING_RESOURCES states

cancelAll

public abstract void cancelAll()
                        throws javax.speech.EngineStateError
Cancels all items on the output queue.

Specified by:
cancelAll in interface javax.speech.synthesis.Synthesizer
Throws:
javax.speech.EngineStateError - if this Synthesizer in the DEALLOCATED or DEALLOCATING_RESOURCES states

getSynthesizerProperties

public javax.speech.synthesis.SynthesizerProperties getSynthesizerProperties()
Returns the SynthesizerProperties object (a JavaBean). The method returns exactly the same object as the getEngineProperties method in the Engine interface. However, with the getSynthesizerProperties method, an application does not need to cast the return value.

Specified by:
getSynthesizerProperties in interface javax.speech.synthesis.Synthesizer
Returns:
the SynthesizerProperties object for this Synthesizer

addSpeakableListener

public void addSpeakableListener(javax.speech.synthesis.SpeakableListener listener)
Adds a SpeakableListener to this Synthesizer.

Specified by:
addSpeakableListener in interface javax.speech.synthesis.Synthesizer
Parameters:
listener - the listener to add
See Also:
removeSpeakableListener(javax.speech.synthesis.SpeakableListener)

removeSpeakableListener

public void removeSpeakableListener(javax.speech.synthesis.SpeakableListener listener)
Removes a SpeakableListener from this Synthesizer.

Specified by:
removeSpeakableListener in interface javax.speech.synthesis.Synthesizer
Parameters:
listener - the listener to remove
See Also:
addSpeakableListener(javax.speech.synthesis.SpeakableListener)

createEngineProperties

protected BaseEngineProperties createEngineProperties()
Factory constructor for EngineProperties object. Gets the default speaking voice from the SynthesizerModeDesc. Takes the default prosody values (pitch, range, volume, rate) from the default voice. Override to set engine-specific defaults.

Specified by:
createEngineProperties in class BaseEngine
Returns:
a BaseEngineProperties object specific to a subclass.

createQueueItem

protected BaseSynthesizerQueueItem createQueueItem()
Factory method that creates a BaseSynthesizerQueueItem. Override if the synthesizer specializes the BaseSynthesizerQueueItem class.


getVoiceList

protected VoiceList getVoiceList()
Returns the list of voices for this Synthesizer.

Returns:
the list of voices for this Synthesizer.

postQueueUpdated

public void postQueueUpdated(boolean topOfQueueChanged,
                             long oldState,
                             long newState)
Utility function that generates QUEUE_UPDATED event and posts it to the event queue. Eventually fireQueueUpdated will be called by dispatchSpeechEvent as a result of this action.

Parameters:
topOfQueueChanged - true if the top of the queue has changed
oldState - the old state of this Synthesizer
newState - the new state of this Synthesizer
See Also:
fireQueueUpdated(javax.speech.synthesis.SynthesizerEvent), dispatchSpeechEvent(javax.speech.SpeechEvent)

fireQueueUpdated

public void fireQueueUpdated(javax.speech.synthesis.SynthesizerEvent event)
Utility function that sends a QUEUE_UPDATED event to all SynthesizerListeners.

Parameters:
event - the QUEUE_UPDATED event
See Also:
postQueueUpdated(boolean, long, long), dispatchSpeechEvent(javax.speech.SpeechEvent)

postQueueEmptied

public void postQueueEmptied(long oldState,
                             long newState)
Utility function that generates QUEUE_EMPTIED event and posts it to the event queue. Eventually fireQueueEmptied will be called by dispatchSpeechEvent as a result of this action.

Parameters:
oldState - the old state of this Synthesizer
newState - the new state of this Synthesizer
See Also:
fireQueueEmptied(javax.speech.synthesis.SynthesizerEvent), dispatchSpeechEvent(javax.speech.SpeechEvent)

fireQueueEmptied

public void fireQueueEmptied(javax.speech.synthesis.SynthesizerEvent event)
Utility function that sends a QUEUE_EMPTIED event to all SynthesizerListeners.

Parameters:
event - the QUEUE_EMPTIED event
See Also:
postQueueEmptied(long, long), dispatchSpeechEvent(javax.speech.SpeechEvent)

dispatchSpeechEvent

public void dispatchSpeechEvent(javax.speech.SpeechEvent event)
Dispatches a SpeechEvent. The dispatcher should notify all SynthesizerListeners from this method. The SpeechEvent was added via the various post methods of this class.

Specified by:
dispatchSpeechEvent in interface SpeechEventDispatcher
Overrides:
dispatchSpeechEvent in class BaseEngine
Parameters:
event - the SpeechEvent to dispatch
See Also:
postQueueUpdated(boolean, long, long), postQueueEmptied(long, long)