marytts.util.data.audio
Class ByteArrayAudioPlayer

java.lang.Object
  extended by marytts.util.data.audio.ByteArrayAudioPlayer
All Implemented Interfaces:
com.sun.speech.freetts.audio.AudioPlayer

public class ByteArrayAudioPlayer
extends java.lang.Object
implements com.sun.speech.freetts.audio.AudioPlayer

Provides an implementation of AudioPlayer that sends all audio data to the bit bucket. The ByteArrayAudioPlayer is a helper, targeted at obtaining a byte array from the audio stream.


Constructor Summary
ByteArrayAudioPlayer()
          Constructs a ByteArrayAudioPlayer
 
Method Summary
 void begin(int size)
          Starts the output of a set of data
 void cancel()
          Cancels all queued output.
 void close()
          Waits for all audio playback to stop, and closes this AudioPlayer.
 boolean drain()
          Waits for all queued audio to be played
 boolean end()
          Marks the end of a set of data
 javax.sound.sampled.AudioFormat getAudioFormat()
          Retrieves the audio format for this player
 javax.sound.sampled.AudioInputStream getAudioInputStream()
          Provide the audio data that has been written to this AudioPlayer since the last call to begin() as a byte array.
 byte[] getByteArray()
          Provide the audio data that has been written to this AudioPlayer since the last call to begin() as a byte array.
 long getTime()
          Gets the amount of played since the last resetTime Currently not supported.
 float getVolume()
          Returns the current volume.
 void pause()
          Pauses the audio output
 void reset()
          Prepares for another batch of output.
 void resetTime()
          Resets the audio clock
 void resume()
          Resumes audio output
 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
 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, toString, wait, wait, wait
 

Constructor Detail

ByteArrayAudioPlayer

public ByteArrayAudioPlayer()
Constructs a ByteArrayAudioPlayer

Method Detail

setAudioFormat

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

Specified by:
setAudioFormat in interface com.sun.speech.freetts.audio.AudioPlayer
Parameters:
format - the audio format

getAudioFormat

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

Specified by:
getAudioFormat in interface com.sun.speech.freetts.audio.AudioPlayer
Returns:
the current audio format.

cancel

public void cancel()
Cancels all queued output. Current 'write' call will return false

Specified by:
cancel in interface com.sun.speech.freetts.audio.AudioPlayer

pause

public void pause()
Pauses the audio output

Specified by:
pause in interface com.sun.speech.freetts.audio.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 com.sun.speech.freetts.audio.AudioPlayer

resume

public void resume()
Resumes audio output

Specified by:
resume in interface com.sun.speech.freetts.audio.AudioPlayer

close

public void close()
Waits for all audio playback to stop, and closes this AudioPlayer.

Specified by:
close in interface com.sun.speech.freetts.audio.AudioPlayer

getVolume

public float getVolume()
Returns the current volume.

Specified by:
getVolume in interface com.sun.speech.freetts.audio.AudioPlayer
Returns:
the current volume (between 0 and 1)

setVolume

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

Specified by:
setVolume in interface com.sun.speech.freetts.audio.AudioPlayer
Parameters:
volume - the current volume (between 0 and 1)

write

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

Specified by:
write in interface com.sun.speech.freetts.audio.AudioPlayer
Parameters:
audioData - array of audio data
Returns:
true of the write completed successfully, false if the write was cancelled.

begin

public void begin(int size)
Starts the output of a set of data

Specified by:
begin in interface com.sun.speech.freetts.audio.AudioPlayer
Parameters:
size - the size of data between now and the end

end

public boolean end()
Marks the end of a set of data

Specified by:
end in interface com.sun.speech.freetts.audio.AudioPlayer

write

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

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

startFirstSampleTimer

public void startFirstSampleTimer()
Starts the first sample timer

Specified by:
startFirstSampleTimer in interface com.sun.speech.freetts.audio.AudioPlayer

drain

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

Specified by:
drain in interface com.sun.speech.freetts.audio.AudioPlayer
Returns:
true if the audio played to completion, false if the audio was stopped

getTime

public long getTime()
Gets the amount of played since the last resetTime Currently not supported.

Specified by:
getTime in interface com.sun.speech.freetts.audio.AudioPlayer
Returns:
the amount of audio in milliseconds

resetTime

public void resetTime()
Resets the audio clock

Specified by:
resetTime in interface com.sun.speech.freetts.audio.AudioPlayer

showMetrics

public void showMetrics()
Shows metrics for this audio player

Specified by:
showMetrics in interface com.sun.speech.freetts.audio.AudioPlayer

getByteArray

public byte[] getByteArray()
Provide the audio data that has been written to this AudioPlayer since the last call to begin() as a byte array.

Returns:
a byte array

getAudioInputStream

public javax.sound.sampled.AudioInputStream getAudioInputStream()
Provide the audio data that has been written to this AudioPlayer since the last call to begin() as a byte array.