public class JavaStreamingAudioPlayer extends Object implements AudioPlayer
com.sun.speech.freetts.audio.AudioPlayer.drainWorksProperly;
to true
.
If the workaround is enabled, the line.isActive method will be
performed periodically. The period of the test can be controlled
with:
com.sun.speech.freetts.audio.AudioPlayer.drainDelay"
The default if 5ms.
The property
com.sun.speech.freetts.audio.AudioPlayer.bufferSize"
Controls the audio buffer size, it defaults to 8192
Even with this drain work around, there are some issues with this
class. The workaround drain is not completely reliable.
A resume
following a pause
does not
always continue at the proper position in the audio. On a rare
occasion, sound output will be repeated a number of times. This may
be related to bug 4421330 in the Bug Parade database.
Modifier and Type | Class and Description |
---|---|
private class |
JavaStreamingAudioPlayer.JavaStreamLineListener
Provides a LineListener for this clas.
|
Modifier and Type | Field and Description |
---|---|
private static int |
AUDIO_BUFFER_SIZE
controls the buffering to java audio
|
private boolean |
audioMetrics |
private static int |
BYTES_PER_WRITE
controls the number of bytes of audio to write to the buffer
for each call to write()
|
private long |
cancelDelay |
private boolean |
cancelled |
private AudioFormat |
currentFormat |
private boolean |
debug |
private AudioFormat |
defaultFormat |
private boolean |
done |
private long |
drainDelay |
private boolean |
firstSample |
private SourceDataLine |
line |
private Object |
lineLock |
private long |
openFailDelayMs |
private Object |
openLock |
private boolean |
paused |
private long |
timeOffset |
private BulkTimer |
timer |
private long |
totalOpenFailDelayMs |
private float |
volume |
Constructor and Description |
---|
JavaStreamingAudioPlayer()
Constructs a default JavaStreamingAudioPlayer
|
Modifier and Type | Method and Description |
---|---|
void |
begin(int size)
Starts the output of a set of data.
|
void |
cancel()
Cancels currently playing audio.
|
void |
close()
Closes this audio player
|
private void |
debugPrint(String msg)
Outputs a debug message if debugging is turned on
|
boolean |
drain()
Waits for all queued audio to be played
|
boolean |
end()
Marks the end of a set of data.
|
AudioFormat |
getAudioFormat()
Gets the audio format for this player
|
long |
getTime()
Gets the amount of played since the last mark
|
float |
getVolume()
Returns the current volume.
|
private boolean |
isCancelled()
Determines if the output has been canceled.
|
private boolean |
isDone()
Determines if the output is done.
|
private boolean |
isPaused()
Returns true if we are in pause mode
|
private void |
openLine(AudioFormat format)
Opens the audio
|
void |
pause()
Pauses audio output
|
void |
reset()
Prepares for another batch of output.
|
void |
resetTime()
Resets the audio clock
|
void |
resume()
Resumes audio output
|
void |
setAudioFormat(AudioFormat format)
Sets the audio format for this player
|
private void |
setPaused(boolean state)
Sets us in pause mode
|
void |
setVolume(float volume)
Sets the current volume.
|
private void |
setVolume(SourceDataLine line,
float vol)
Sets the volume on the given clip
|
void |
showMetrics()
Shows metrics for this audio player
|
void |
startFirstSampleTimer()
Starts the first sample timer
|
String |
toString()
Returns the name of this audioplayer
|
private boolean |
waitResume()
Waits for resume.
|
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
|
private volatile boolean paused
private volatile boolean done
private volatile boolean cancelled
private SourceDataLine line
private float volume
private long timeOffset
private AudioFormat defaultFormat
private AudioFormat currentFormat
private boolean debug
private boolean audioMetrics
private boolean firstSample
private long cancelDelay
private long drainDelay
private long openFailDelayMs
private long totalOpenFailDelayMs
private static final int AUDIO_BUFFER_SIZE
private static final int BYTES_PER_WRITE
public JavaStreamingAudioPlayer()
public void setAudioFormat(AudioFormat format)
setAudioFormat
in interface AudioPlayer
format
- the audio formatUnsupportedOperationException
- if the line cannot be opened with
the given formatpublic AudioFormat getAudioFormat()
getAudioFormat
in interface AudioPlayer
public void startFirstSampleTimer()
startFirstSampleTimer
in interface AudioPlayer
private void openLine(AudioFormat format)
format
- the format for the audioUnsupportedOperationException
- if the line cannot be opened with
the given formatpublic void pause()
pause
in interface AudioPlayer
public void resume()
resume
in interface AudioPlayer
public void cancel()
cancel
in interface AudioPlayer
public void reset()
reset
in interface AudioPlayer
public void close()
close
in interface AudioPlayer
public float getVolume()
getVolume
in interface AudioPlayer
public void setVolume(float volume)
setVolume
in interface AudioPlayer
volume
- the current volume (between 0 and 1)private void setPaused(boolean state)
state
- true if we are pausedprivate boolean isPaused()
private void setVolume(SourceDataLine line, float vol)
line
- the line to set the volume onvol
- the volume (range 0 to 1)public void begin(int size)
size
parameter has no meaning and effect at all, so any value can be used.
Audio data for a single utterance should be grouped
between begin/end pairs.begin
in interface AudioPlayer
size
- supposedly the size of data between now and the end,
but since this is a streaming audio player, this parameter
has no meaning and effect at allpublic boolean end()
end
in interface AudioPlayer
public boolean drain()
drain
in interface AudioPlayer
public long getTime()
getTime
in interface AudioPlayer
public void resetTime()
resetTime
in interface AudioPlayer
public boolean write(byte[] audioData)
write
in interface AudioPlayer
audioData
- audio data to write to the devicetrue
of the write completed successfully,
false
if the write was cancelled.public boolean write(byte[] bytes, int offset, int size)
write
in interface AudioPlayer
bytes
- audio data to write to the deviceoffset
- the offset into the buffersize
- the size into the buffertrue
of the write completed successfully,
false
if the write was cancelled.private boolean waitResume()
private void debugPrint(String msg)
msg
- the message to outputpublic void showMetrics()
showMetrics
in interface AudioPlayer
private boolean isCancelled()
private boolean isDone()
WebARTS Library Licensed Under the GNU - General Public License. Other Libraries licensed under their respective Open Source Licenses