org.alchar.jdtk.jsapi
Class DTKSynthesizer

java.lang.Object
  extended by org.alchar.jdtk.jsapi.DTKSynthesizer
All Implemented Interfaces:
Engine, Synthesizer

public class DTKSynthesizer
extends Object
implements Synthesizer

This class implements a JSAPI 1.0 synthesizer for the DECtalk software speech synthesizer.


Field Summary
 
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
DTKSynthesizer()
          Create a new DTKSynthesizer object.
DTKSynthesizer(DTKSynthesizerModeDesc modeDesc)
          Create a new DTKSynthesizer object with the given synthesizer mode.
 
Method Summary
 void addEngineListener(EngineListener listener)
          Add an EngineListener to the listener list of this object.
 void addSpeakableListener(SpeakableListener listener)
          Add a SpeakableListener to the listener list of this object.
 void allocate()
          Allocate resources for the synthesizer.
 void cancel()
          Remove the top-most item from the speech output queue.
 void cancel(Object obj)
          Remove the given item from the speech output queue.
 void cancelAll()
          Remove all items from the speech output queue, and terminate any item that is currently being spoken (if any).
 void deallocate()
          Deallocate resources for the synthesizer.
 String describeState(long state)
          Return a string representation for the given engine state.
 Enumeration enumerateQueue()
          Return an enumeration of the items that are currently on the speech output queue.
 AudioManager getAudioManager()
          Return the object that is responsible for managing the audio.
 EngineModeDesc getEngineModeDesc()
          Return the mode description for the engine.
 EngineProperties getEngineProperties()
          Return the engine properties object for this synthesizer.
 long getEngineState()
          Return the engine state.
 SynthesizerProperties getSynthesizerProperties()
          Return the synthesizer properties object for this synthesizer.
 VocabManager getVocabManager()
          Return the object that is responsible for managing the vocabulary.
 void pause()
          Pause the engine.
 String phoneme(String text)
          Render the given plain text into a phoneme string.
 void removeEngineListener(EngineListener listener)
          Remove an EngineListener from the listener list of this object.
 void removeSpeakableListener(SpeakableListener listener)
          Remove a SpeakableListener from the listener list of this object.
 void resume()
          Resume after previously pausing the engine.
 void sendAllocated(EngineEvent ev)
          Send an engine allocated event.
 void sendAllocated(long[] states)
          Send an engine allocated event.
 void sendAllocatingResources(EngineEvent ev)
          Send an engine allocating resources event.
 void sendAllocatingResources(long[] states)
          Send an engine allocating resources event.
 void sendDeallocated(EngineEvent ev)
          Send an engine deallocated event.
 void sendDeallocated(long[] states)
          Send an engine deallocated event.
 void sendDeallocatingResources(EngineEvent ev)
          Send an engine deallocating resources event.
 void sendDeallocatingResources(long[] states)
          Send an engine deallocating resources event.
 void sendPaused(EngineEvent ev)
          Send an engine paused event.
 void sendPaused(long[] states)
          Send an engine paused event.
 void sendQueueEmptied(boolean queueTopDiff, long[] states)
          Send a synthesizer queue emptied event.
 void sendQueueEmptied(SynthesizerEvent ev)
          Send a synthesizer queue emptied event.
 void sendQueueUpdated(boolean queueTopDiff, long[] states)
          Send a synthesizer queue updated event.
 void sendQueueUpdated(SynthesizerEvent ev)
          Send a synthesizer queue updated event.
 void sendResumed(EngineEvent ev)
          Send an engine resumed event.
 void sendResumed(long[] states)
          Send an engine resumed event.
 void speak(Speakable jsmlObj, SpeakableListener listener)
          Render the JSML text provided by the given Speakable object into speech.
 void speak(String jsmlText, SpeakableListener listener)
          Render the given JSML text into speech.
 void speak(URL jsmlURL, SpeakableListener listener)
          Render the JSML text found at the given URL into speech.
 void speakPlainText(String text, SpeakableListener listener)
          Render the given plain text into speech.
 boolean testEngineState(long state)
          Return whether the current engine state matches the given state.
 void waitEngineState(long state)
          Wait until the engine is in the specified state.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DTKSynthesizer

public DTKSynthesizer()
Create a new DTKSynthesizer object.


DTKSynthesizer

public DTKSynthesizer(DTKSynthesizerModeDesc modeDesc)
Create a new DTKSynthesizer object with the given synthesizer mode.

Parameters:
modeDesc - Synthesizer mode description
Method Detail

getAudioManager

public AudioManager getAudioManager()
Return the object that is responsible for managing the audio.

Specified by:
getAudioManager in interface Engine
Returns:
Audio manager object

getEngineModeDesc

public EngineModeDesc getEngineModeDesc()
Return the mode description for the engine.

Specified by:
getEngineModeDesc in interface Engine
Returns:
Engine mode description
Throws:
SecurityException - If not allowed

getEngineState

public long getEngineState()
Return the engine state.

Specified by:
getEngineState in interface Engine
Returns:
Engine state

getVocabManager

public VocabManager getVocabManager()
                             throws EngineStateError
Return the object that is responsible for managing the vocabulary.

Specified by:
getVocabManager in interface Engine
Returns:
Vocabulary manager object
Throws:
EngineStateError - If deallocated or deallocating

addEngineListener

public void addEngineListener(EngineListener listener)
Add an EngineListener to the listener list of this object.

Specified by:
addEngineListener in interface Engine
Parameters:
listener - Engine listener

removeEngineListener

public void removeEngineListener(EngineListener listener)
Remove an EngineListener from the listener list of this object.

Specified by:
removeEngineListener in interface Engine
Parameters:
listener - Engine listener

addSpeakableListener

public void addSpeakableListener(SpeakableListener listener)
Add a SpeakableListener to the listener list of this object.

Specified by:
addSpeakableListener in interface Synthesizer
Parameters:
listener - Speakable listener

removeSpeakableListener

public void removeSpeakableListener(SpeakableListener listener)
Remove a SpeakableListener from the listener list of this object.

Specified by:
removeSpeakableListener in interface Synthesizer
Parameters:
listener - Speakable listener

allocate

public void allocate()
              throws EngineException,
                     EngineStateError
Allocate resources for the synthesizer. This method will post an ALLOCATING_RESOURCES event prior to making an attempt to allocate the resources. If it succeeds, it will post an ALLOCATED event, and the method will return. If it fails, it will post a DEALLOCATED event, and the method will return.

An EngineStateError will be thrown if the engine is in the DEALLOCATING_RESOURCES state.

An EngineException will be thrown if the allocation fails.

Specified by:
allocate in interface Engine
Throws:
EngineException - If error
EngineStateError - If deallocating

deallocate

public void deallocate()
                throws EngineException,
                       EngineStateError
Deallocate resources for the synthesizer. This method will post a DEALLOCATING_RESOURCES event prior to making an attempt to deallocate the resources. After the deallocation completes, a DEALLOCATED event will be posted.

An EngineException will be thrown if the deallocation fails.

Specified by:
deallocate in interface Engine
Throws:
EngineException - If error
EngineStateError - If allocating

pause

public void pause()
           throws EngineStateError
Pause the engine.
FIXME: This method should use waitEngineState if the current state is ALLOCATING_RESOURCES. However, it needs to handle failures to allocate in that case as well.

Specified by:
pause in interface Engine
Throws:
EngineStateError - If deallocated or deallocating

resume

public void resume()
            throws EngineStateError
Resume after previously pausing the engine.

Specified by:
resume in interface Engine
Throws:
EngineStateError - If deallocated or deallocating

describeState

public String describeState(long state)
Return a string representation for the given engine state.

Parameters:
state - Engine state
Returns:
String representation

testEngineState

public boolean testEngineState(long state)
                        throws IllegalArgumentException
Return whether the current engine state matches the given state.

Specified by:
testEngineState in interface Engine
Parameters:
state - Engine state
Returns:
True if engine state matches
Throws:
IllegalArgumentException - If wrong argument

waitEngineState

public void waitEngineState(long state)
                     throws InterruptedException,
                            IllegalArgumentException
Wait until the engine is in the specified state. Note that this method will block the calling thread until the condition is met.
FIXME: This method should ensure that the given state is legal.

Specified by:
waitEngineState in interface Engine
Parameters:
state - Engine state
Throws:
InterruptedException - If interrupted
IllegalArgumentException - If state is unreachable

cancelAll

public void cancelAll()
               throws EngineStateError
Remove all items from the speech output queue, and terminate any item that is currently being spoken (if any).
FIXME: This needs to cause the synthesizer to stop talking.

Specified by:
cancelAll in interface Synthesizer
Throws:
EngineStateError - If deallocated or deallocating

cancel

public void cancel()
            throws EngineStateError
Remove the top-most item from the speech output queue.

Specified by:
cancel in interface Synthesizer
Throws:
EngineStateError - If deallocated or deallocating

cancel

public void cancel(Object obj)
            throws EngineStateError
Remove the given item from the speech output queue.

Specified by:
cancel in interface Synthesizer
Parameters:
obj - Item to remove
Throws:
EngineStateError - If deallocated or deallocating

enumerateQueue

public Enumeration enumerateQueue()
                           throws EngineStateError
Return an enumeration of the items that are currently on the speech output queue.

Specified by:
enumerateQueue in interface Synthesizer
Returns:
Enumeration of speech output items
Throws:
EngineStateError - If deallocated or deallocating

getEngineProperties

public EngineProperties getEngineProperties()
Return the engine properties object for this synthesizer.

Specified by:
getEngineProperties in interface Engine
Returns:
EngineProperties object

getSynthesizerProperties

public SynthesizerProperties getSynthesizerProperties()
Return the synthesizer properties object for this synthesizer.

Specified by:
getSynthesizerProperties in interface Synthesizer
Returns:
SynthesizerProperties object

phoneme

public String phoneme(String text)
               throws EngineStateError
Render the given plain text into a phoneme string. This is not currently supported on the DECtalk software speech synthesizer.

Specified by:
phoneme in interface Synthesizer
Parameters:
text - Plain text
Returns:
Phoneme string
Throws:
EngineStateError - If deallocated or deallocating

speakPlainText

public void speakPlainText(String text,
                           SpeakableListener listener)
                    throws EngineStateError
Render the given plain text into speech.

Specified by:
speakPlainText in interface Synthesizer
Parameters:
text - Plain text
listener - Speakable listener
Throws:
EngineStateError - If deallocated or deallocating

speak

public void speak(Speakable jsmlObj,
                  SpeakableListener listener)
           throws JSMLException,
                  EngineStateError
Render the JSML text provided by the given Speakable object into speech.

Specified by:
speak in interface Synthesizer
Parameters:
jsmlObj - Speakable object
listener - Speakable listener
Throws:
JSMLException - If JSML syntax errors
EngineStateError - If deallocated or deallocating

speak

public void speak(URL jsmlURL,
                  SpeakableListener listener)
           throws JSMLException,
                  MalformedURLException,
                  IOException,
                  EngineStateError
Render the JSML text found at the given URL into speech.

Specified by:
speak in interface Synthesizer
Parameters:
jsmlURL - URL for JSML text
listener - Speakable listener
Throws:
JSMLException - If JSML syntax errors
MalformedURLException - If URL syntax errors
IOException - If I/O errors
EngineStateError - If deallocated or deallocating

speak

public void speak(String jsmlText,
                  SpeakableListener listener)
           throws JSMLException,
                  EngineStateError
Render the given JSML text into speech.

Specified by:
speak in interface Synthesizer
Parameters:
jsmlText - JSML text
listener - Speakable listener
Throws:
JSMLException - If JSML syntax errors
EngineStateError - If deallocated or deallocating

sendAllocated

public void sendAllocated(EngineEvent ev)
Send an engine allocated event.

Parameters:
ev - Engine event

sendAllocated

public void sendAllocated(long[] states)
Send an engine allocated event.

Parameters:
states - Array with old and new state

sendAllocatingResources

public void sendAllocatingResources(EngineEvent ev)
Send an engine allocating resources event.

Parameters:
ev - Engine event

sendAllocatingResources

public void sendAllocatingResources(long[] states)
Send an engine allocating resources event.

Parameters:
states - Array with old and new state

sendDeallocated

public void sendDeallocated(EngineEvent ev)
Send an engine deallocated event.

Parameters:
ev - Engine event

sendDeallocated

public void sendDeallocated(long[] states)
Send an engine deallocated event.

Parameters:
states - Array with old and new state

sendDeallocatingResources

public void sendDeallocatingResources(EngineEvent ev)
Send an engine deallocating resources event.

Parameters:
ev - Engine event

sendDeallocatingResources

public void sendDeallocatingResources(long[] states)
Send an engine deallocating resources event.

Parameters:
states - Array with old and new state

sendPaused

public void sendPaused(EngineEvent ev)
Send an engine paused event.

Parameters:
ev - Engine event

sendPaused

public void sendPaused(long[] states)
Send an engine paused event.

Parameters:
states - Array with old and new state

sendResumed

public void sendResumed(EngineEvent ev)
Send an engine resumed event.

Parameters:
ev - Engine event

sendResumed

public void sendResumed(long[] states)
Send an engine resumed event.

Parameters:
states - Array with old and new state

sendQueueEmptied

public void sendQueueEmptied(SynthesizerEvent ev)
Send a synthesizer queue emptied event.

Parameters:
ev - Synthesizer event

sendQueueEmptied

public void sendQueueEmptied(boolean queueTopDiff,
                             long[] states)
Send a synthesizer queue emptied event.

Parameters:
queueTopDiff - True if queue top changed
states - Array with old and new state

sendQueueUpdated

public void sendQueueUpdated(SynthesizerEvent ev)
Send a synthesizer queue updated event.

Parameters:
ev - Synthesizer event

sendQueueUpdated

public void sendQueueUpdated(boolean queueTopDiff,
                             long[] states)
Send a synthesizer queue updated event.

Parameters:
queueTopDiff - True if queue top changed
states - Array with old and new state


Copyright © 2007-2009 Kris Van Hees. All Rights Reserved.