com.sun.speech.freetts.audio
Class JavaClipAudioPlayer

java.lang.Object
  extended bycom.sun.speech.freetts.audio.JavaClipAudioPlayer
All Implemented Interfaces:
AudioPlayer

public class JavaClipAudioPlayer
extends java.lang.Object
implements AudioPlayer

Provides an implementation of AudioPlayer that creates javax.sound.sampled audio clips and outputs them via the javax.sound API. The interface provides a highly reliable audio output package. Since audio is batched and not sent to the audio layer until an entire utterance has been processed, this player has higher latency (50 msecs for a typical 4 second utterance). The system property: com.sun.speech.freetts.audio.AudioPlayer.debug; if set to true will cause this class to emit debugging information (useful to a developer).


Constructor Summary
JavaClipAudioPlayer()
          Constructs a default JavaClipAudioPlayer
 
Method Summary
 void begin(int size)
          Starts the output of a set of data.
 void cancel()
          Cancels all queued audio.
 void close()
          Closes this audio player
 boolean drain()
          Waits for all queued audio to be played
 boolean end()
          Marks the end a set of data.
 javax.sound.sampled.AudioFormat getAudioFormat()
          Retrieves the audio format for this player
 long getTime()
          Returns the current position in the output stream since the last resetTime Currently not supported.
 float getVolume()
          Returns the current volume.
 void pause()
          Pauses audio output.
 void reset()
          Prepares for another batch of output.
 void resetTime()
          Resets the time for this audio stream to zero
 void resume()
          Resumes playing audio after a pause.
 void setAudioFormat(javax.sound.sampled.AudioFormat format)
          Sets the audio format for this player
 void setVolume(float volume)
          Sets the current volume.
 void showMetrics()
          Shows metrics for this audio player
 void startFirstSampleTimer()
          Starts the first sample timer
 java.lang.String toString()
          Returns the name of this audio player
 boolean write(byte[] audioData)
          Writes the given bytes to the audio stream
 boolean write(byte[] bytes, int offset, int size)
          Writes the given bytes to the audio stream
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

JavaClipAudioPlayer

public JavaClipAudioPlayer()
Constructs a default JavaClipAudioPlayer

Method Detail

setAudioFormat

public void setAudioFormat(javax.sound.sampled.AudioFormat format)
Sets the audio format for this player

Specified by:
setAudioFormat in interface AudioPlayer
Parameters:
format - the audio format
Throws:
java.lang.UnsupportedOperationException - if the line cannot be opened with the given format

getAudioFormat

public javax.sound.sampled.AudioFormat getAudioFormat()
Retrieves the audio format for this player

Specified by:
getAudioFormat in interface AudioPlayer
Returns:
format the audio format

pause

public void pause()
Pauses audio output. All audio output is stopped. Output can be resumed at the current point by calling resume. Output can be aborted by calling cancel

Specified by:
pause in interface AudioPlayer

resume

public void resume()
Resumes playing audio after a pause.

Specified by:
resume in interface AudioPlayer

cancel

public void cancel()
Cancels all queued audio. Any 'write' in process will return immediately false.

Specified by:
cancel in interface AudioPlayer

reset

public void reset()
Prepares for another batch of output. Larger groups of output (such as all output associated with a single FreeTTSSpeakable) should be grouped between a reset/drain pair.

Specified by:
reset in interface AudioPlayer

drain

public boolean drain()
Waits for all queued audio to be played

Specified by:
drain in interface AudioPlayer
Returns:
true if the write completed successfully, false if the write was cancelled.

close

public void close()
Closes this audio player

Specified by:
close in interface AudioPlayer

getVolume

public float getVolume()
Returns the current volume.

Specified by:
getVolume in interface AudioPlayer
Returns:
the current volume (between 0 and 1)

setVolume

public void setVolume(float volume)
Sets the current volume.

Specified by:
setVolume in interface AudioPlayer
Parameters:
volume - the current volume (between 0 and 1)

getTime

public long getTime()
Returns the current position in the output stream since the last resetTime Currently not supported.

Specified by:
getTime in interface AudioPlayer
Returns:
the position in the audio stream in milliseconds

resetTime

public void resetTime()
Resets the time for this audio stream to zero

Specified by:
resetTime in interface AudioPlayer

begin

public void begin(int size)
Starts the output of a set of data. Audio data for a single utterance should be grouped between begin/end pairs.

Specified by:
begin in interface AudioPlayer
Parameters:
size - the size of data between now and the end

end

public boolean end()
Marks the end a set of data. Audio data for a single utterance should be grouped between begin/end pairs.

Specified by:
end in interface AudioPlayer
Returns:
true if the audio was output properly, false if the output was cancelled or interrupted.

write

public boolean write(byte[] audioData)
Writes the given bytes to the audio stream

Specified by:
write in interface AudioPlayer
Parameters:
audioData - audio data to write to the device
Returns:
true if the write completed successfully, false if the write was cancelled.

write

public boolean write(byte[] bytes,
                     int offset,
                     int size)
Writes the given bytes to the audio stream

Specified by:
write in interface AudioPlayer
Parameters:
bytes - audio data to write to the device
offset - the offset into the buffer
size - the size into the buffer
Returns:
true if the write completed successfully, false if the write was cancelled.

toString

public java.lang.String toString()
Returns the name of this audio player

Returns:
the name of the audio player

showMetrics

public void showMetrics()
Shows metrics for this audio player

Specified by:
showMetrics in interface AudioPlayer

startFirstSampleTimer

public void startFirstSampleTimer()
Starts the first sample timer

Specified by:
startFirstSampleTimer in interface AudioPlayer