Class BaseEngine
- All Implemented Interfaces:
SpeechEventDispatcher
- Direct Known Subclasses:
BaseSynthesizer
Engine interface.
Actual JSAPI implementations might want to extend or modify this
implementation.-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected AudioManagerTheAudioManagerfor thisEngine.protected static final longUtility state for clearing theengineState.protected CollectionList ofEngineListenersregistered forEngineEventson thisEngine.protected EngineModeDescTheEngineModeDescfor thisEngine.protected EnginePropertiesTheEnginePropertiesfor thisEngine.protected longA bitmask holding the current state of thisEngine.protected ObjectAnObjectused for synchronizing access toengineState. -
Constructor Summary
ConstructorsConstructorDescriptionCreates a newEnginein theDEALLOCATEDstate.BaseEngine(EngineModeDesc desc) Creates a newEnginein theDEALLOCATEDstate. -
Method Summary
Modifier and TypeMethodDescriptionvoidaddEngineListener(EngineListener listener) Requests notification ofEngineEventsfrom thisEngine.voidallocate()Allocates the resources required for thisEngineand puts it into theALLOCATEDstate.protected voidcheckEngineState(long state) Convenience method that throws anEngineStateErrorif any of the bits in the passed state are set in thestate.protected abstract BaseEnginePropertiesFactory constructor for EngineProperties object.voidFrees the resources of thisEnginethat were acquired during allocation and during operation and return thisEngineto theDEALLOCATED.voiddispatchSpeechEvent(SpeechEvent event) Dispatches aSpeechEvent.voidfireEngineAllocated(EngineEvent event) Utility function that sends anENGINE_ALLOCATEDevent to allEngineListenersregistered with thisEngine.voidfireEngineAllocatingResources(EngineEvent event) Utility function that sends anENGINE_ALLOCATING_RESOURCESevent to allEngineListenersregistered with thisEngine.voidfireEngineDeallocated(EngineEvent event) Utility function that sends anENGINE_DEALLOCATEDevent to allEngineListenersregistered with thisEngine.voidfireEngineDeallocatingResources(EngineEvent event) Utility function that sends aENGINE_DEALLOCATING_RESOURCESevent to allEngineListenersregistered with thisEngine.voidfireEnginePaused(EngineEvent event) Utility function that sends anENGINE_PAUSEDevent to allEngineListenersregistered with thisEngine.voidfireEngineResumed(EngineEvent event) Utility function that sends anENGINE_RESUMEDevent to allEngineListenersregistered with thisEngine.AudioManagerReturns an object that provides management of the audio input or output of thisEngine.EngineModeDescGets the current operating properties and mode of thisEngine.EnginePropertiesGets theEnginePropertiesof thisEngine.longReturns a or'ed set of flags indicating the current state of thisEngine.VocabManagerReturns an object that provides management of the vocabulary for thisEngine.protected abstract voidCalled from theallocatemethod.protected abstract voidCalled from thedeallocatemethod.protected abstract voidCalled from thepausemethod.protected abstract voidCalled from theresumemethod.voidpause()Pauses the audio stream for thisEngineand put thisEngineinto thePAUSEDstate.protected voidpostEngineAllocated(long oldState, long newState) Utility function that generates anENGINE_ALLOCATEDevent and posts it to the event queue.protected voidpostEngineAllocatingResources(long oldState, long newState) Utility function that generates anENGINE_ALLOCATING_RESOURCESevent and posts it to the event queue.protected voidpostEngineDeallocated(long oldState, long newState) Utility function that generates anENGINE_DEALLOCATEDevent and posts it to the event queue.protected voidpostEngineDeallocatingResources(long oldState, long newState) Utility function that generatesENGINE_DEALLOCATING_RESOURCESevent and posts it to the event queue.protected voidpostEnginePaused(long oldState, long newState) Utility function that generates anENGINE_PAUSEDevent and posts it to the event queue.protected voidpostEngineResumed(long oldState, long newState) Utility function that generates anENGINE_RESUMEDevent and posts it to the event queue.voidremoveEngineListener(EngineListener listener) Removes anEngineListenerfrom the list ofEngineListeners.voidresume()Resumes the audio stream for thisEngineand put thisEngineinto theRESUMEDstate.protected voidsetEngineModeDesc(EngineModeDesc desc) Sets the current operating properties and mode of thisEngine.protected long[]setEngineState(long clear, long set) Updates thisEnginestate by clearing defined bits, then setting other specified bits.protected StringstateToString(long state) Returns aStringof the names of all theEnginestates in the givenEnginestate.booleantestEngineState(long state) Returnstrueif this state of thisEnginematches the specified state.toString()Returns the engine name and mode for debug purposes.voidwaitEngineState(long state) Blocks the calling thread until thisEngineis in a specified state.
-
Field Details
-
engineState
protected long engineStateA bitmask holding the current state of thisEngine. -
engineStateLock
AnObjectused for synchronizing access toengineState.- See Also:
-
engineListeners
List ofEngineListenersregistered forEngineEventson thisEngine. -
audioManager
protected AudioManager audioManagerTheAudioManagerfor thisEngine. -
engineModeDesc
protected EngineModeDesc engineModeDescTheEngineModeDescfor thisEngine. -
engineProperties
protected EngineProperties enginePropertiesTheEnginePropertiesfor thisEngine. -
CLEAR_ALL_STATE
protected static final long CLEAR_ALL_STATEUtility state for clearing theengineState.- See Also:
-
-
Constructor Details
-
BaseEngine
public BaseEngine()Creates a newEnginein theDEALLOCATEDstate. -
BaseEngine
public BaseEngine(EngineModeDesc desc) Creates a newEnginein theDEALLOCATEDstate.- Parameters:
desc- the operating mode of thisEngine
-
-
Method Details
-
getEngineState
public long getEngineState()Returns a or'ed set of flags indicating the current state of thisEngine.An
EngineEventis issued each time thisEnginechanges state.The
getEngineStatemethod can be called successfully in anyEnginestate.- Returns:
- the current state of this
Engine - See Also:
-
waitEngineState
Blocks the calling thread until thisEngineis in a specified state.All state bits specified in the
stateparameter must be set in order for the method to return, as defined for thetestEngineStatemethod. If thestateparameter defines an unreachable state (e.g.PAUSED | RESUMED) an exception is thrown.The
waitEngineStatemethod can be called successfully in anyEnginestate.- Parameters:
state- a bitmask of the state to wait for- Throws:
InterruptedException- if another thread has interrupted this thread.IllegalArgumentException- if the specified state is unreachable- See Also:
-
testEngineState
Returnstrueif this state of thisEnginematches the specified state.The test performed is not an exact match to the current state. Only the specified states are tested. For example the following returns true only if the
Synthesizerqueue is empty, irrespective of the pause/resume and allocation states.if (synth.testEngineState(Synthesizer.QUEUE_EMPTY)) ...The
testEngineStatemethod is equivalent to:if ((engine.getEngineState() invalid input: '&' state) == state)The
testEngineStatemethod can be called successfully in anyEnginestate.- Parameters:
state- a bitmask of the states to test for- Returns:
trueif thisEnginematchesstate; otherwisefalse- Throws:
IllegalArgumentException- if the specified state is unreachable
-
setEngineState
protected long[] setEngineState(long clear, long set) Updates thisEnginestate by clearing defined bits, then setting other specified bits.- Returns:
- a length-2 array with old and new state values.
-
allocate
public void allocate() throws EngineException, EngineStateErrorAllocates the resources required for thisEngineand puts it into theALLOCATEDstate. When this method returns successfully theALLOCATEDbit of thisEnginestate is set, and thetestEngineState(Engine.ALLOCATED)method returnstrue.During the processing of the method, this
Engineis temporarily in theALLOCATING_RESOURCESstate.- See Also:
-
handleAllocate
protected abstract void handleAllocate() throws EngineExceptionCalled from theallocatemethod. Override this in subclasses.- See Also:
-
deallocate
public void deallocate() throws EngineException, EngineStateErrorFrees the resources of thisEnginethat were acquired during allocation and during operation and return thisEngineto theDEALLOCATED. When this method returns theDEALLOCATEDbit of thisEnginestate is set so thetestEngineState(Engine.DEALLOCATED)method returnstrue.During the processing of the method, this
Engineis temporarily in theDEALLOCATING_RESOURCESstate.A deallocated engine can be re-started with a subsequent call to
allocate.- See Also:
-
handleDeallocate
protected abstract void handleDeallocate() throws EngineExceptionCalled from thedeallocatemethod. Override this in subclasses. -
pause
public void pause() throws EngineStateErrorPauses the audio stream for thisEngineand put thisEngineinto thePAUSEDstate. -
handlePause
protected abstract void handlePause()Called from thepausemethod. Override this in subclasses. -
resume
public void resume() throws AudioException, EngineStateErrorResumes the audio stream for thisEngineand put thisEngineinto theRESUMEDstate. -
handleResume
protected abstract void handleResume()Called from theresumemethod. Override in subclasses. -
getAudioManager
public AudioManager getAudioManager()Returns an object that provides management of the audio input or output of thisEngine.- Returns:
- the audio manader for this
Engine
-
getVocabManager
public VocabManager getVocabManager() throws EngineStateErrorReturns an object that provides management of the vocabulary for thisEngine. Returnsnullif thisEnginedoes not support vocabulary management.- Returns:
- the vocabulary manager of this
Engine
-
getEngineProperties
public EngineProperties getEngineProperties()Gets theEnginePropertiesof thisEngine. Must be set in subclasses.- Returns:
- the
EnginePropertiesof thisEngine.
-
getEngineModeDesc
Gets the current operating properties and mode of thisEngine.- Returns:
- the operating mode of this
Engine - Throws:
SecurityException
-
setEngineModeDesc
protected void setEngineModeDesc(EngineModeDesc desc) Sets the current operating properties and mode of thisEngine.- Parameters:
desc- the new operating mode of thisEngine
-
addEngineListener
public void addEngineListener(EngineListener listener) Requests notification ofEngineEventsfrom thisEngine.- Parameters:
listener- the listener to add.
-
removeEngineListener
public void removeEngineListener(EngineListener listener) Removes anEngineListenerfrom the list ofEngineListeners.- Parameters:
listener- the listener to remove.
-
postEngineAllocated
protected void postEngineAllocated(long oldState, long newState) Utility function that generates anENGINE_ALLOCATEDevent and posts it to the event queue. EventuallyfireEngineAllocatedwill be called by thedispatchSpeechEventas a result of this action.- Parameters:
oldState- the old state of thisEnginenewState- the new state of thisEngine- See Also:
-
fireEngineAllocated
public void fireEngineAllocated(EngineEvent event) Utility function that sends anENGINE_ALLOCATEDevent to allEngineListenersregistered with thisEngine. Called bydispatchSpeechEvent.- Parameters:
event- theENGINE_ALLOCATEDevent- See Also:
-
postEngineAllocatingResources
protected void postEngineAllocatingResources(long oldState, long newState) Utility function that generates anENGINE_ALLOCATING_RESOURCESevent and posts it to the event queue. EventuallyfireEngineAllocatingResourceswill be called bydispatchSpeechEventas a result of this action.- Parameters:
oldState- the old state of thisEnginenewState- the new state of thisEngine- See Also:
-
fireEngineAllocatingResources
public void fireEngineAllocatingResources(EngineEvent event) Utility function that sends anENGINE_ALLOCATING_RESOURCESevent to allEngineListenersregistered with thisEngine. Called bydispatchSpeechEvent.- Parameters:
event- theENGINE_ALLOCATING_RESOURCESevent- See Also:
-
postEngineDeallocated
protected void postEngineDeallocated(long oldState, long newState) Utility function that generates anENGINE_DEALLOCATEDevent and posts it to the event queue. EventuallyfireEngineDeallocatedwill be called bydispatchSpeechEventas a result of this action.- Parameters:
oldState- the old state of thisEnginenewState- the new state of thisEngine- See Also:
-
fireEngineDeallocated
public void fireEngineDeallocated(EngineEvent event) Utility function that sends anENGINE_DEALLOCATEDevent to allEngineListenersregistered with thisEngine. Called bydispatchSpeechEvent.- Parameters:
event- theENGINE_DEALLOCATEDevent- See Also:
-
postEngineDeallocatingResources
protected void postEngineDeallocatingResources(long oldState, long newState) Utility function that generatesENGINE_DEALLOCATING_RESOURCESevent and posts it to the event queue. EventuallyfireEngineAllocatingResourceswill be called bydispatchSpeechEventas a result of this action.- Parameters:
oldState- the old state of thisEnginenewState- the new state of thisEngine- See Also:
-
fireEngineDeallocatingResources
public void fireEngineDeallocatingResources(EngineEvent event) Utility function that sends aENGINE_DEALLOCATING_RESOURCESevent to allEngineListenersregistered with thisEngine. Called bydispatchSpeechEvent.- Parameters:
event- theENGINE_DEALLOCATING_RESOURCESevent- See Also:
-
postEnginePaused
protected void postEnginePaused(long oldState, long newState) Utility function that generates anENGINE_PAUSEDevent and posts it to the event queue. EventuallyfireEnginePausedwill be called bydispatchSpeechEventas a result of this action.- Parameters:
oldState- the old state of thisEnginenewState- the new state of thisEngine- See Also:
-
fireEnginePaused
public void fireEnginePaused(EngineEvent event) Utility function that sends anENGINE_PAUSEDevent to allEngineListenersregistered with thisEngine. Called bydispatchSpeechEvent.- Parameters:
event- theENGINE_PAUSEDevent- See Also:
-
postEngineResumed
protected void postEngineResumed(long oldState, long newState) Utility function that generates anENGINE_RESUMEDevent and posts it to the event queue. EventuallyfireEngineResumedwill be called bydispatchSpeechEventas a result of this action.- Parameters:
oldState- the old state of thisEnginenewState- the new state of thisEngine- See Also:
-
fireEngineResumed
public void fireEngineResumed(EngineEvent event) Utility function that sends anENGINE_RESUMEDevent to allEngineListenersregistered with thisEngine. Called bydispatchSpeechEvent.- Parameters:
event- theENGINE_RESUMEDevent- See Also:
-
createEngineProperties
Factory constructor for EngineProperties object.- Returns:
- a
BaseEnginePropertiesobject specific to a subclass.
-
checkEngineState
protected void checkEngineState(long state) throws EngineStateError Convenience method that throws anEngineStateErrorif any of the bits in the passed state are set in thestate.- Parameters:
state- theEnginestate to check
-
stateToString
Returns aStringof the names of all theEnginestates in the givenEnginestate.- Parameters:
state- the bitmask of states- Returns:
- a
Stringcontaining the names of all the states set instate
-
dispatchSpeechEvent
public void dispatchSpeechEvent(SpeechEvent event) Dispatches aSpeechEvent. The dispatcher should notify allEngineListenersfrom this method. TheSpeechEventwas added via the various post methods of this class.- Specified by:
dispatchSpeechEventin interfaceSpeechEventDispatcher- Parameters:
event- theSpeechEventto dispatch- See Also:
-
toString
Returns the engine name and mode for debug purposes.
-