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.0Synthesizer
interface 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.Collection
speakableListeners
Set of speakable listeners belonging to theSynthesizer
.protected VoiceList
voiceList
The 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 theDEALLOCATED
state.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description void
addSpeakableListener(SpeakableListener listener)
Adds aSpeakableListener
to thisSynthesizer
.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 forEngineProperties
object.protected BaseSynthesizerQueueItem
createQueueItem()
Factory method that creates aBaseSynthesizerQueueItem
.void
dispatchSpeechEvent(SpeechEvent event)
Dispatches aSpeechEvent
.abstract java.util.Enumeration
enumerateQueue()
Returns an enumeration of the queue.void
fireQueueEmptied(SynthesizerEvent event)
Utility function that sends aQUEUE_EMPTIED
event to allSynthesizerListeners
.void
fireQueueUpdated(SynthesizerEvent event)
Utility function that sends aQUEUE_UPDATED
event to allSynthesizerListeners
.SynthesizerProperties
getSynthesizerProperties()
Returns theSynthesizerProperties
object (a JavaBean).protected VoiceList
getVoiceList()
Returns the list of voices for thisSynthesizer
.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 generatesQUEUE_EMPTIED
event and posts it to the event queue.void
postQueueUpdated(boolean topOfQueueChanged, long oldState, long newState)
Utility function that generatesQUEUE_UPDATED
event and posts it to the event queue.void
removeSpeakableListener(SpeakableListener listener)
Removes aSpeakableListener
from thisSynthesizer
.void
speak(java.lang.String jsmlText, SpeakableListener listener)
Speaks JSML text provided as aString
.void
speak(java.net.URL jsmlURL, SpeakableListener listener)
Speaks JSML text provided as aURL
.void
speak(Speakable jsmlText, SpeakableListener listener)
Speaks JSML text provided as aSpeakable
object.void
speakPlainText(java.lang.String text, SpeakableListener listener)
Speaks a plain textString
.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
-
-
-
-
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, EngineStateError
Speaks JSML text provided as aSpeakable
object.- Parameters:
jsmlText
- the JSML text to speaklistener
- the listener to be notified as thejsmlText
is processed- Throws:
JSMLException
- if the JSML text contains errorsEngineStateError
- if thisSynthesizer
in theDEALLOCATED
orDEALLOCATING_RESOURCES
states
-
speak
public void speak(java.net.URL jsmlURL, SpeakableListener listener) throws JSMLException, java.net.MalformedURLException, java.io.IOException, EngineStateError
Speaks JSML text provided as aURL
.- Parameters:
jsmlURL
- theURL
containing JSML textlistener
- the listener to be notified as the JSML text is processed- Throws:
EngineStateError
- if thisSynthesizer
in theDEALLOCATED
orDEALLOCATING_RESOURCES
statesjava.io.IOException
- if errors are encountered with theJSMLurl
JSMLException
- 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, EngineStateError
Speaks JSML text provided as aString
.- Parameters:
jsmlText
- aString
containing JSML.listener
- the listener to be notified as the JSML text is processed- Throws:
EngineStateError
- if thisSynthesizer
in theDEALLOCATED
orDEALLOCATING_RESOURCES
statesJSMLException
- if the JSML text contains errors
-
speakPlainText
public void speakPlainText(java.lang.String text, SpeakableListener listener) throws EngineStateError
Speaks a plain textString
. No JSML parsing is performed.- Parameters:
text
- aString
containing plain text.listener
- the listener to be notified as the text is processed- Throws:
EngineStateError
- if thisSynthesizer
in theDEALLOCATED
orDEALLOCATING_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 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 EngineStateError
Optional 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 thisSynthesizer
in theDEALLOCATED
orDEALLOCATING_RESOURCES
states
-
enumerateQueue
public abstract java.util.Enumeration enumerateQueue() throws EngineStateError
Returns an enumeration of the queue.- Returns:
- an
Enumeration
of the speech output queue ornull
. - Throws:
EngineStateError
- if thisSynthesizer
in theDEALLOCATED
orDEALLOCATING_RESOURCES
states
-
cancel
public abstract void cancel() throws EngineStateError
Cancels the item at the top of the queue.- Throws:
EngineStateError
- if thisSynthesizer
in theDEALLOCATED
orDEALLOCATING_RESOURCES
states
-
cancel
public abstract void cancel(java.lang.Object source) throws java.lang.IllegalArgumentException, EngineStateError
Cancels 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 thisSynthesizer
in theDEALLOCATED
orDEALLOCATING_RESOURCES
states
-
cancelAll
public abstract void cancelAll() throws EngineStateError
Cancels all items on the output queue.- Throws:
EngineStateError
- if thisSynthesizer
in theDEALLOCATED
orDEALLOCATING_RESOURCES
states
-
getSynthesizerProperties
public SynthesizerProperties getSynthesizerProperties()
Returns theSynthesizerProperties
object (a JavaBean). The method returns exactly the same object as thegetEngineProperties
method in theEngine
interface. However, with thegetSynthesizerProperties
method, an application does not need to cast the return value.- Returns:
- the
SynthesizerProperties
object for thisSynthesizer
-
addSpeakableListener
public void addSpeakableListener(SpeakableListener listener)
Adds aSpeakableListener
to thisSynthesizer
.- Parameters:
listener
- the listener to add- See Also:
removeSpeakableListener(SpeakableListener)
-
removeSpeakableListener
public void removeSpeakableListener(SpeakableListener listener)
Removes aSpeakableListener
from thisSynthesizer
.- Parameters:
listener
- the listener to remove- See Also:
addSpeakableListener(SpeakableListener)
-
createEngineProperties
protected BaseEngineProperties createEngineProperties()
Factory constructor forEngineProperties
object. 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:
createEngineProperties
in classBaseEngine
- Returns:
- a
BaseEngineProperties
object specific to a subclass.
-
createQueueItem
protected BaseSynthesizerQueueItem createQueueItem()
Factory method that creates aBaseSynthesizerQueueItem
. Override if the synthesizer specializes theBaseSynthesizerQueueItem
class.
-
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_UPDATED
event and posts it to the event queue. EventuallyfireQueueUpdated
will be called bydispatchSpeechEvent
as a result of this action.- Parameters:
topOfQueueChanged
-true
if the top of the queue has changedoldState
- the old state of thisSynthesizer
newState
- the new state of thisSynthesizer
- See Also:
fireQueueUpdated(SynthesizerEvent)
,dispatchSpeechEvent(SpeechEvent)
-
fireQueueUpdated
public void fireQueueUpdated(SynthesizerEvent event)
Utility function that sends aQUEUE_UPDATED
event to allSynthesizerListeners
.- Parameters:
event
- theQUEUE_UPDATED
event- See Also:
postQueueUpdated(boolean, long, long)
,dispatchSpeechEvent(SpeechEvent)
-
postQueueEmptied
public void postQueueEmptied(long oldState, long newState)
Utility function that generatesQUEUE_EMPTIED
event and posts it to the event queue. EventuallyfireQueueEmptied
will be called bydispatchSpeechEvent
as a result of this action.- Parameters:
oldState
- the old state of thisSynthesizer
newState
- the new state of thisSynthesizer
- See Also:
fireQueueEmptied(SynthesizerEvent)
,dispatchSpeechEvent(SpeechEvent)
-
fireQueueEmptied
public void fireQueueEmptied(SynthesizerEvent event)
Utility function that sends aQUEUE_EMPTIED
event to allSynthesizerListeners
.- Parameters:
event
- theQUEUE_EMPTIED
event- See Also:
postQueueEmptied(long, long)
,dispatchSpeechEvent(SpeechEvent)
-
dispatchSpeechEvent
public void dispatchSpeechEvent(SpeechEvent event)
Dispatches aSpeechEvent
. The dispatcher should notify allSynthesizerListeners
from this method. TheSpeechEvent
was added via the various post methods of this class.- Specified by:
dispatchSpeechEvent
in interfaceSpeechEventDispatcher
- Overrides:
dispatchSpeechEvent
in classBaseEngine
- Parameters:
event
- theSpeechEvent
to dispatch- See Also:
postQueueUpdated(boolean, long, long)
,postQueueEmptied(long, long)
-
-