Package com.sun.speech.engine.synthesis.text

# Class TextSynthesizer.OutputHandler

java.lang.Object
java.lang.Thread
com.sun.speech.engine.synthesis.text.TextSynthesizer.OutputHandler

All Implemented Interfaces:
  `Runnable`

Enclosing class:
  `TextSynthesizer`

public class TextSynthesizer.OutputHandler extends Thread
The output device for a `TextSynthesizer`. Sends all text to standard out.

## Nested Class Summary

## Nested classes/interfaces inherited from class java.lang.Thread

`Thread.Builder, Thread.State, Thread.UncaughtExceptionHandler`

## Field Summary

Fields
Modifier and Type
Field
Description
`protected static final int`
`CANCEL`
`protected static final int`
`CANCEL_ALL`
`protected static final int`
`CANCEL_COMPLETE`
`protected int`
`command`
For the item at the top of the queue, the output command reflects whether item should be PAUSE, RESUME, CANCEL.
`protected Object`
`commandLock`
Object on which accesses to the command must synchronize.
`protected Object`
`currentItemLock`
Object to lock on for setting the current item.
`protected boolean`
`done`
`protected static final int`
`PAUSE`
`protected Vector`
`queue`
Internal speech output queue that will contain a set of TextSynthesizerQueueItems.
`protected static final int`
`RESUME`

### Fields inherited from class java.lang.Thread

`MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY`

## Constructor Summary

Constructors
Constructor
Description
`OutputHandler()`
Class constructor.

## Method Summary

Modifier and Type
Method
Description
`void`
`appendQueue(TextSynthesizerQueueItem item)`
Adds an item to be spoken to the output queue.
`protected void`
`cancelAllItems()`
Cancels all items.
`protected void`
`cancelItem()`
Cancels the current item.
`protected void`
`cancelItem(int cancelType)`
Cancels all or just the current item.
`protected void`
`cancelItem(Object source)`
Cancels the given item.
`Enumeration`
`enumerateQueue()`
Returns the current queue.
`protected TextSynthesizerQueueItem`
`getQueueItem()`
Returns, but does not remove, the first item on the queue.
`protected boolean`
`isCommand(String engineText, int index)`
Determines if the next thing in line is a command.
`boolean`
`isQueueEmpty()`
Determines if the queue is empty.
`protected boolean`
`isWhitespace(String engineText, int index)`
Determines if there is whitespace at the current index.
`protected int`
`outputItem(TextSynthesizerQueueItem item)`
Starts outputting the item.
`protected void`
`pauseItem()`
Pauses the output.
`protected int`
`processCommand(TextSynthesizerQueueItem item, String engineText, int index)`
Attempts to process a command starting at the next character in the synthesizer text.
`protected int`
`processNormalText(TextSynthesizerQueueItem item, 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 int`
`processWhitespace(String engineText, int index)`
Processes whitespace at the current index in the synthesizer text.
`protected void`
`resumeItem()`
Resumes the output.
`void`
`run()`
Controls output of text until terminate is called.
`void`
`terminate()`
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, isVirtual, join, join, join, join, ofPlatform, ofVirtual, onSpinWait, resume, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, sleep, sleep, start, startVirtualThread, stop, suspend, threadId, toString, yield`

### Methods inherited from class java.lang.Object

`equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

## Field Details

### done

protected boolean done

### queue

protected Vector queue
Internal speech output queue that will contain a set of TextSynthesizerQueueItems.

See Also:
  - `BaseSynthesizerQueueItem`

### currentItemLock

protected 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 Object commandLock
Object on which accesses to the command must synchronize.

## Constructor Details

### OutputHandler

public OutputHandler()
Class constructor.

## Method Details

### terminate

public void terminate()
Stops execution of the Thread.

### enumerateQueue

public Enumeration enumerateQueue()
Returns the current queue.

Returns:
  the current queue

### isQueueEmpty

public boolean isQueueEmpty()
Determines if the queue is empty.

Returns:
  `true` if 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` - `CANCEL` or `CANCEL_ALL`

### cancelItem

protected void cancelItem(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:
  `run` in interface `Runnable`
Overrides:
  `run` in class `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(String engineText, int index)
Determines if the next thing in line is a command.

Parameters:
  `engineText` - the text containing embedded commands
  `index` - the current index
Returns:
  `true` if the next thing in line is a command

### processCommand

protected int processCommand(TextSynthesizerQueueItem item, 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 item
  `engineText` - the text containing embedded commands
  `index` - the current index
Returns:
  the new index

### isWhitespace

protected boolean isWhitespace(String engineText, int index)
Determines if there is whitespace at the current index.

Parameters:
  `engineText` - the text containing embedded commands
  `index` - the current index
Returns:
  `true` if there is whitespace at the current index

### processWhitespace

protected int processWhitespace(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 commands
  `index` - the current index
Returns:
  the new index

### processNormalText

protected int processNormalText(TextSynthesizerQueueItem item, 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 item
  `engineText` - the text containing embedded commands
  `index` - the current index
Returns:
  the new index