Class TextSynthesizer.OutputHandler
- java.lang.Object
-
- java.lang.Thread
-
- com.sun.speech.engine.synthesis.text.TextSynthesizer.OutputHandler
-
- All Implemented Interfaces:
java.lang.Runnable
- Enclosing class:
- TextSynthesizer
public class TextSynthesizer.OutputHandler extends java.lang.ThreadThe output device for aTextSynthesizer. Sends all text to standard out.
-
-
Field Summary
Fields Modifier and Type Field Description protected static intCANCELprotected static intCANCEL_ALLprotected static intCANCEL_COMPLETEprotected intcommandFor the item at the top of the queue, the output command reflects whether item should be PAUSE, RESUME, CANCEL.protected java.lang.ObjectcommandLockObject on which accesses to the command must synchronize.protected java.lang.ObjectcurrentItemLockObject to lock on for setting the current item.protected booleandoneprotected static intPAUSEprotected java.util.VectorqueueInternal speech output queue that will contain a set of TextSynthesizerQueueItems.protected static intRESUME
-
Constructor Summary
Constructors Constructor Description OutputHandler()Class constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidappendQueue(TextSynthesizerQueueItem item)Adds an item to be spoken to the output queue.protected voidcancelAllItems()Cancels all items.protected voidcancelItem()Cancels the current item.protected voidcancelItem(int cancelType)Cancels all or just the current item.protected voidcancelItem(java.lang.Object source)Cancels the given item.java.util.EnumerationenumerateQueue()Returns the current queue.protected TextSynthesizerQueueItemgetQueueItem()Returns, but does not remove, the first item on the queue.protected booleanisCommand(java.lang.String engineText, int index)Determines if the next thing in line is a command.booleanisQueueEmpty()Determines if the queue is empty.protected booleanisWhitespace(java.lang.String engineText, int index)Determines if there is whitespace at the current index.protected intoutputItem(TextSynthesizerQueueItem item)Starts outputting the item.protected voidpauseItem()Pauses the output.protected intprocessCommand(TextSynthesizerQueueItem item, java.lang.String engineText, int index)Attempts to process a command starting at the next character in the synthesizer text.protected intprocessNormalText(TextSynthesizerQueueItem item, java.lang.String engineText, int index)Processes next set of characters in output up to whitespace or next '/' that could indicate the start of a command.protected intprocessWhitespace(java.lang.String engineText, int index)Processes whitespace at the current index in the synthesizer text.protected voidresumeItem()Resumes the output.voidrun()Controls output of text until terminate is called.voidterminate()Stops execution of the Thread.-
Methods inherited from class java.lang.Thread
activeCount, checkAccess, clone, countStackFrames, currentThread, dumpStack, enumerate, getAllStackTraces, getContextClassLoader, getDefaultUncaughtExceptionHandler, getId, getName, getPriority, getStackTrace, getState, getThreadGroup, getUncaughtExceptionHandler, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, onSpinWait, resume, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, sleep, start, stop, suspend, toString, yield
-
-
-
-
Field Detail
-
done
protected boolean done
-
queue
protected java.util.Vector queue
Internal speech output queue that will contain a set of TextSynthesizerQueueItems.- See Also:
BaseSynthesizerQueueItem
-
currentItemLock
protected java.lang.Object currentItemLock
Object to lock on for setting the current item.
-
command
protected int command
For the item at the top of the queue, the output command reflects whether item should be PAUSE, RESUME, CANCEL.
-
PAUSE
protected static final int PAUSE
- See Also:
- Constant Field Values
-
RESUME
protected static final int RESUME
- See Also:
- Constant Field Values
-
CANCEL
protected static final int CANCEL
- See Also:
- Constant Field Values
-
CANCEL_ALL
protected static final int CANCEL_ALL
- See Also:
- Constant Field Values
-
CANCEL_COMPLETE
protected static final int CANCEL_COMPLETE
- See Also:
- Constant Field Values
-
commandLock
protected java.lang.Object commandLock
Object on which accesses to the command must synchronize.
-
-
Method Detail
-
terminate
public void terminate()
Stops execution of the Thread.
-
enumerateQueue
public java.util.Enumeration enumerateQueue()
Returns the current queue.- Returns:
- the current queue
-
isQueueEmpty
public boolean isQueueEmpty()
Determines if the queue is empty.- Returns:
trueif the queue is empty
-
appendQueue
public void appendQueue(TextSynthesizerQueueItem item)
Adds an item to be spoken to the output queue.- Parameters:
item- the item to be added
-
cancelItem
protected void cancelItem()
Cancels the current item.
-
cancelAllItems
protected void cancelAllItems()
Cancels all items.
-
cancelItem
protected void cancelItem(int cancelType)
Cancels all or just the current item.- Parameters:
cancelType-CANCELorCANCEL_ALL
-
cancelItem
protected void cancelItem(java.lang.Object source)
Cancels the given item.- Parameters:
source- the item to cancel
-
pauseItem
protected void pauseItem()
Pauses the output.
-
resumeItem
protected void resumeItem()
Resumes the output.
-
run
public void run()
Controls output of text until terminate is called.- Specified by:
runin interfacejava.lang.Runnable- Overrides:
runin classjava.lang.Thread- See Also:
terminate()
-
getQueueItem
protected TextSynthesizerQueueItem getQueueItem()
Returns, but does not remove, the first item on the queue.- Returns:
- the first item on the queue
-
outputItem
protected int outputItem(TextSynthesizerQueueItem item)
Starts outputting the item. Returns the current command.- Parameters:
item- to be output- Returns:
- the current command
-
isCommand
protected boolean isCommand(java.lang.String engineText, int index)Determines if the next thing in line is a command.- Parameters:
engineText- the text containing embedded commandsindex- the current index- Returns:
trueif the next thing in line is a command
-
processCommand
protected int processCommand(TextSynthesizerQueueItem item, java.lang.String engineText, int index)
Attempts to process a command starting at the next character in the synthesizer text. Returns the new index.- Parameters:
item- the current queue itemengineText- the text containing embedded commandsindex- the current index- Returns:
- the new index
-
isWhitespace
protected boolean isWhitespace(java.lang.String engineText, int index)Determines if there is whitespace at the current index.- Parameters:
engineText- the text containing embedded commandsindex- the current index- Returns:
trueif there is whitespace at the current index
-
processWhitespace
protected int processWhitespace(java.lang.String engineText, int index)Processes whitespace at the current index in the synthesizer text. If next character is not whitespace, does nothing. If next character is whitespace, displays it and pauses briefly to simulate the speaking rate.- Parameters:
engineText- the text containing embedded commandsindex- the current index- Returns:
- the new index
-
processNormalText
protected int processNormalText(TextSynthesizerQueueItem item, java.lang.String engineText, int index)
Processes next set of characters in output up to whitespace or next '/' that could indicate the start of a command.- Parameters:
item- the current queue itemengineText- the text containing embedded commandsindex- the current index- Returns:
- the new index
-
-