Package com.sun.speech.engine.synthesis
Class BaseSynthesizer
- java.lang.Object
-
- com.sun.speech.engine.BaseEngine
-
- com.sun.speech.engine.synthesis.BaseSynthesizer
-
- All Implemented Interfaces:
SpeechEventDispatcher
- Direct Known Subclasses:
FreeTTSSynthesizer,TextSynthesizer
public abstract class BaseSynthesizer extends BaseEngine implements SpeechEventDispatcher
Supports the JSAPI 1.0Synthesizerinterface that performs the core non-engine-specific functions.An actual JSAPI synthesizer implementation needs to extend or modify this implementation.
-
-
Field Summary
Fields Modifier and Type Field Description protected java.util.CollectionspeakableListenersSet of speakable listeners belonging to theSynthesizer.protected VoiceListvoiceListThe set of voices available in thisSynthesizer.-
Fields inherited from class com.sun.speech.engine.BaseEngine
audioManager, CLEAR_ALL_STATE, engineListeners, engineModeDesc, engineProperties, engineState, engineStateLock
-
-
Constructor Summary
Constructors Constructor Description BaseSynthesizer(SynthesizerModeDesc mode)Creates a new Synthesizer in theDEALLOCATEDstate.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description voidaddSpeakableListener(SpeakableListener listener)Adds aSpeakableListenerto thisSynthesizer.protected abstract voidappendQueue(BaseSynthesizerQueueItem item)Puts an item on the speaking queue and sends a queue updated event.abstract voidcancel()Cancels the item at the top of the queue.abstract voidcancel(java.lang.Object source)Cancels a specific object on the queue.abstract voidcancelAll()Cancels all items on the output queue.protected BaseEnginePropertiescreateEngineProperties()Factory constructor forEnginePropertiesobject.protected BaseSynthesizerQueueItemcreateQueueItem()Factory method that creates aBaseSynthesizerQueueItem.voiddispatchSpeechEvent(SpeechEvent event)Dispatches aSpeechEvent.abstract java.util.EnumerationenumerateQueue()Returns an enumeration of the queue.voidfireQueueEmptied(SynthesizerEvent event)Utility function that sends aQUEUE_EMPTIEDevent to allSynthesizerListeners.voidfireQueueUpdated(SynthesizerEvent event)Utility function that sends aQUEUE_UPDATEDevent to allSynthesizerListeners.SynthesizerPropertiesgetSynthesizerProperties()Returns theSynthesizerPropertiesobject (a JavaBean).protected VoiceListgetVoiceList()Returns the list of voices for thisSynthesizer.java.lang.Stringphoneme(java.lang.String text)Optional method that converts a text string to a phoneme string.voidpostQueueEmptied(long oldState, long newState)Utility function that generatesQUEUE_EMPTIEDevent and posts it to the event queue.voidpostQueueUpdated(boolean topOfQueueChanged, long oldState, long newState)Utility function that generatesQUEUE_UPDATEDevent and posts it to the event queue.voidremoveSpeakableListener(SpeakableListener listener)Removes aSpeakableListenerfrom thisSynthesizer.voidspeak(java.lang.String jsmlText, SpeakableListener listener)Speaks JSML text provided as aString.voidspeak(java.net.URL jsmlURL, SpeakableListener listener)Speaks JSML text provided as aURL.voidspeak(Speakable jsmlText, SpeakableListener listener)Speaks JSML text provided as aSpeakableobject.voidspeakPlainText(java.lang.String text, SpeakableListener listener)Speaks a plain textString.protected java.lang.StringstateToString(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
-
-
-
-
Field Detail
-
speakableListeners
protected java.util.Collection speakableListeners
Set of speakable listeners belonging to theSynthesizer. Each item on queue may have an individual listener too.- See Also:
SpeakableListener
-
voiceList
protected VoiceList voiceList
The set of voices available in thisSynthesizer. The list can be created in the constructor methods.
-
-
Method Detail
-
speak
public void speak(Speakable jsmlText, SpeakableListener listener) throws JSMLException, EngineStateErrorSpeaks JSML text provided as aSpeakableobject.- Parameters:
jsmlText- the JSML text to speaklistener- the listener to be notified as thejsmlTextis processed- Throws:
JSMLException- if the JSML text contains errorsEngineStateError- if thisSynthesizerin theDEALLOCATEDorDEALLOCATING_RESOURCESstates
-
speak
public void speak(java.net.URL jsmlURL, SpeakableListener listener) throws JSMLException, java.net.MalformedURLException, java.io.IOException, EngineStateErrorSpeaks JSML text provided as aURL.- Parameters:
jsmlURL- theURLcontaining JSML textlistener- the listener to be notified as the JSML text is processed- Throws:
EngineStateError- if thisSynthesizerin theDEALLOCATEDorDEALLOCATING_RESOURCESstatesjava.io.IOException- if errors are encountered with theJSMLurlJSMLException- if the JSML text contains errorsjava.net.MalformedURLException- if errors are encountered with theJSMLurl
-
speak
public void speak(java.lang.String jsmlText, SpeakableListener listener) throws JSMLException, EngineStateErrorSpeaks JSML text provided as aString.- Parameters:
jsmlText- aStringcontaining JSML.listener- the listener to be notified as the JSML text is processed- Throws:
EngineStateError- if thisSynthesizerin theDEALLOCATEDorDEALLOCATING_RESOURCESstatesJSMLException- if the JSML text contains errors
-
speakPlainText
public void speakPlainText(java.lang.String text, SpeakableListener listener) throws EngineStateErrorSpeaks a plain textString. No JSML parsing is performed.- Parameters:
text- aStringcontaining plain text.listener- the listener to be notified as the text is processed- Throws:
EngineStateError- if thisSynthesizerin theDEALLOCATEDorDEALLOCATING_RESOURCESstates
-
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:
stateToStringin classBaseEngine- 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 EngineStateErrorOptional method that converts a text string to a phoneme string.- Parameters:
text- plain text to be converted to phonemes- Returns:
- IPA phonemic representation of text or
null - Throws:
EngineStateError- if thisSynthesizerin theDEALLOCATEDorDEALLOCATING_RESOURCESstates
-
enumerateQueue
public abstract java.util.Enumeration enumerateQueue() throws EngineStateErrorReturns an enumeration of the queue.- Returns:
- an
Enumerationof the speech output queue ornull. - Throws:
EngineStateError- if thisSynthesizerin theDEALLOCATEDorDEALLOCATING_RESOURCESstates
-
cancel
public abstract void cancel() throws EngineStateErrorCancels the item at the top of the queue.- Throws:
EngineStateError- if thisSynthesizerin theDEALLOCATEDorDEALLOCATING_RESOURCESstates
-
cancel
public abstract void cancel(java.lang.Object source) throws java.lang.IllegalArgumentException, EngineStateErrorCancels a specific object on the queue.- 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.EngineStateError- if thisSynthesizerin theDEALLOCATEDorDEALLOCATING_RESOURCESstates
-
cancelAll
public abstract void cancelAll() throws EngineStateErrorCancels all items on the output queue.- Throws:
EngineStateError- if thisSynthesizerin theDEALLOCATEDorDEALLOCATING_RESOURCESstates
-
getSynthesizerProperties
public SynthesizerProperties getSynthesizerProperties()
Returns theSynthesizerPropertiesobject (a JavaBean). The method returns exactly the same object as thegetEnginePropertiesmethod in theEngineinterface. However, with thegetSynthesizerPropertiesmethod, an application does not need to cast the return value.- Returns:
- the
SynthesizerPropertiesobject for thisSynthesizer
-
addSpeakableListener
public void addSpeakableListener(SpeakableListener listener)
Adds aSpeakableListenerto thisSynthesizer.- Parameters:
listener- the listener to add- See Also:
removeSpeakableListener(SpeakableListener)
-
removeSpeakableListener
public void removeSpeakableListener(SpeakableListener listener)
Removes aSpeakableListenerfrom thisSynthesizer.- Parameters:
listener- the listener to remove- See Also:
addSpeakableListener(SpeakableListener)
-
createEngineProperties
protected BaseEngineProperties createEngineProperties()
Factory constructor forEnginePropertiesobject. Gets the default speaking voice from theSynthesizerModeDesc. Takes the default prosody values (pitch, range, volume, rate) from the default voice. Override to set engine-specific defaults.- Specified by:
createEnginePropertiesin classBaseEngine- Returns:
- a
BaseEnginePropertiesobject specific to a subclass.
-
createQueueItem
protected BaseSynthesizerQueueItem createQueueItem()
Factory method that creates aBaseSynthesizerQueueItem. Override if the synthesizer specializes theBaseSynthesizerQueueItemclass.
-
getVoiceList
protected VoiceList getVoiceList()
Returns the list of voices for thisSynthesizer.- Returns:
- the list of voices for this
Synthesizer.
-
postQueueUpdated
public void postQueueUpdated(boolean topOfQueueChanged, long oldState, long newState)Utility function that generatesQUEUE_UPDATEDevent and posts it to the event queue. EventuallyfireQueueUpdatedwill be called bydispatchSpeechEventas a result of this action.- Parameters:
topOfQueueChanged-trueif the top of the queue has changedoldState- the old state of thisSynthesizernewState- the new state of thisSynthesizer- See Also:
fireQueueUpdated(SynthesizerEvent),dispatchSpeechEvent(SpeechEvent)
-
fireQueueUpdated
public void fireQueueUpdated(SynthesizerEvent event)
Utility function that sends aQUEUE_UPDATEDevent to allSynthesizerListeners.- Parameters:
event- theQUEUE_UPDATEDevent- See Also:
postQueueUpdated(boolean, long, long),dispatchSpeechEvent(SpeechEvent)
-
postQueueEmptied
public void postQueueEmptied(long oldState, long newState)Utility function that generatesQUEUE_EMPTIEDevent and posts it to the event queue. EventuallyfireQueueEmptiedwill be called bydispatchSpeechEventas a result of this action.- Parameters:
oldState- the old state of thisSynthesizernewState- the new state of thisSynthesizer- See Also:
fireQueueEmptied(SynthesizerEvent),dispatchSpeechEvent(SpeechEvent)
-
fireQueueEmptied
public void fireQueueEmptied(SynthesizerEvent event)
Utility function that sends aQUEUE_EMPTIEDevent to allSynthesizerListeners.- Parameters:
event- theQUEUE_EMPTIEDevent- See Also:
postQueueEmptied(long, long),dispatchSpeechEvent(SpeechEvent)
-
dispatchSpeechEvent
public void dispatchSpeechEvent(SpeechEvent event)
Dispatches aSpeechEvent. The dispatcher should notify allSynthesizerListenersfrom this method. TheSpeechEventwas added via the various post methods of this class.- Specified by:
dispatchSpeechEventin interfaceSpeechEventDispatcher- Overrides:
dispatchSpeechEventin classBaseEngine- Parameters:
event- theSpeechEventto dispatch- See Also:
postQueueUpdated(boolean, long, long),postQueueEmptied(long, long)
-
-