Package com.sun.speech.freetts.audio
Class JavaClipAudioPlayer
java.lang.Object
com.sun.speech.freetts.audio.JavaClipAudioPlayer
- All Implemented Interfaces:
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).-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
begin
(int size) Starts the output of a set of data.void
cancel()
Cancels all queued audio.void
close()
Closes this audio player [[[ WORKAROUND TODO The javax.sound.sampled drain is almost working properly.boolean
drain()
Waits for all queued audio to be playedboolean
end()
Marks the end a set of data.Retrieves the audio format for this playerlong
getTime()
Returns the current position in the output stream since the lastresetTime
Currently not supported.float
Returns the current volume.void
pause()
Pauses audio output.void
reset()
Prepares for another batch of output.void
Resets the time for this audio stream to zerovoid
resume()
Resumes playing audio after a pause.void
setAudioFormat
(AudioFormat format) Sets the audio format for this playervoid
setVolume
(float volume) Sets the current volume.void
Shows metrics for this audio playervoid
Starts the first sample timertoString()
Returns the name of this audio playerboolean
write
(byte[] audioData) Writes the given bytes to the audio streamboolean
write
(byte[] bytes, int offset, int size) Writes the given bytes to the audio stream
-
Constructor Details
-
JavaClipAudioPlayer
public JavaClipAudioPlayer()Constructs a default JavaClipAudioPlayer
-
-
Method Details
-
setAudioFormat
Sets the audio format for this player- Specified by:
setAudioFormat
in interfaceAudioPlayer
- Parameters:
format
- the audio format- Throws:
UnsupportedOperationException
- if the line cannot be opened with the given format
-
getAudioFormat
Retrieves the audio format for this player- Specified by:
getAudioFormat
in interfaceAudioPlayer
- 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 callingresume
. Output can be aborted by callingcancel
- Specified by:
pause
in interfaceAudioPlayer
-
resume
public void resume()Resumes playing audio after a pause.- Specified by:
resume
in interfaceAudioPlayer
-
cancel
public void cancel()Cancels all queued audio. Any 'write' in process will return immediately false.- Specified by:
cancel
in interfaceAudioPlayer
-
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 interfaceAudioPlayer
-
drain
public boolean drain()Waits for all queued audio to be played- Specified by:
drain
in interfaceAudioPlayer
- Returns:
true
if the write completed successfully,false
if the write was cancelled.
-
close
public void close()Closes this audio player [[[ WORKAROUND TODO The javax.sound.sampled drain is almost working properly. On linux, there is still a little bit of sound that needs to go out, even after drain is called. Thus, the drainDelay. We wait for a few hundred milliseconds while the data is really drained out of the system ]]]- Specified by:
close
in interfaceAudioPlayer
-
getVolume
public float getVolume()Returns the current volume.- Specified by:
getVolume
in interfaceAudioPlayer
- Returns:
- the current volume (between 0 and 1)
-
setVolume
public void setVolume(float volume) Sets the current volume.- Specified by:
setVolume
in interfaceAudioPlayer
- Parameters:
volume
- the current volume (between 0 and 1)
-
getTime
public long getTime()Returns the current position in the output stream since the lastresetTime
Currently not supported.- Specified by:
getTime
in interfaceAudioPlayer
- 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 interfaceAudioPlayer
-
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 interfaceAudioPlayer
- 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 interfaceAudioPlayer
- Returns:
true
if the audio was output properly,false
if the output was canceled or interrupted.
-
write
public boolean write(byte[] audioData) Writes the given bytes to the audio stream- Specified by:
write
in interfaceAudioPlayer
- 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 interfaceAudioPlayer
- Parameters:
bytes
- audio data to write to the deviceoffset
- the offset into the buffersize
- the size into the buffer- Returns:
true
if the write completed successfully,false
if the write was canceled.
-
toString
Returns the name of this audio player -
showMetrics
public void showMetrics()Shows metrics for this audio player- Specified by:
showMetrics
in interfaceAudioPlayer
-
startFirstSampleTimer
public void startFirstSampleTimer()Starts the first sample timer- Specified by:
startFirstSampleTimer
in interfaceAudioPlayer
-