|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object com.sun.speech.freetts.audio.JavaStreamingAudioPlayer
Streams audio to java audio. This class provides a low latency method of sending audio output through the javax.sound audio API. Audio data is sent in small sets to the audio system allowing it to be played soon after it is generated. Unfortunately, the current release of the JDK (JDK 1.4 beta 2) has a bug or two in the implementation of 'SourceDataLine.drain'. A workaround solution that sleep/waits on SourceDataLine.isActive is used here instead. To disable the work around (i.e use the real 'drain') set the property:
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.
Constructor Summary | |
JavaStreamingAudioPlayer()
Constructs a default JavaStreamingAudioPlayer |
Method Summary | |
void |
begin(int size)
Starts the output of a set of data. |
void |
cancel()
Cancels currently playing audio. |
void |
close()
Closes this audio player |
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()
Gets the audio format for this player |
long |
getTime()
Gets the amount of played since the last mark |
float |
getVolume()
Returns the current volume. |
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(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 audioplayer |
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 |
public JavaStreamingAudioPlayer()
Method Detail |
public void setAudioFormat(javax.sound.sampled.AudioFormat format)
setAudioFormat
in interface AudioPlayer
format
- the audio format
java.lang.UnsupportedOperationException
- if the line cannot be opened with
the given formatpublic javax.sound.sampled.AudioFormat getAudioFormat()
getAudioFormat
in interface AudioPlayer
public void startFirstSampleTimer()
startFirstSampleTimer
in interface AudioPlayer
public 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)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 device
true
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 buffer
true
of the write completed successfully,
false
if the write was cancelled.public java.lang.String toString()
public void showMetrics()
showMetrics
in interface AudioPlayer
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |