public interface AudioPlayer
setAudioFormat
) and output the data.
The AudioPlayer interface provides a set of potential synchronization points to allow a specific AudioPlayer to batch output in various ways.
These synchronization points are in pairs: reset,
drain
are used to bracket output of large amounts of audio
data. Typically, an implementation will not return from
drain
until all queued audio has been played (or
cancelled).
The methods: begin, end
are used to bracket smaller amounts of
audio data (typically associated with a single utterance).
pause,
resume, cancel, showMetrics, close, getTime, resetTime
which can be called from other threads.Modifier and Type | Method and Description |
---|---|
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()
Signals the end of a set of data.
|
AudioFormat |
getAudioFormat()
Retrieves the audio format for this player
|
long |
getTime()
Gets the amount of audio played since the last resetTime
|
float |
getVolume()
Returns the current volume.
|
void |
pause()
Pauses all audio output on this player.
|
void |
reset()
Prepares for another batch of output.
|
void |
resetTime()
Resets the audio clock
|
void |
resume()
Resumes audio output on this player
|
void |
setAudioFormat(AudioFormat format)
Sets the audio format to use for the next set of outputs.
|
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[] audioData,
int offset,
int size)
Writes the given bytes to the audio stream
|
void setAudioFormat(AudioFormat format)
format
- the audio formatAudioFormat getAudioFormat()
void pause()
void resume()
void reset()
boolean drain()
true
if the audio played to completion;
otherwise false
if the audio was stoppedvoid begin(int size) throws IOException
size
- the size of data in bytes to be output before
end
is called.IOException
- if an error occurs while preparing the output.boolean end() throws IOException
begin/end
pairs.true
if the audio was output properly,
false
if the output was canceled
or interrupted.IOException
- if an error occurs while closing the outputvoid cancel()
void close() throws IOException
IOException
- error closing the audio playerfloat getVolume()
void setVolume(float volume)
volume
- the new volume (between 0 and 1)long getTime()
void resetTime()
void startFirstSampleTimer()
boolean write(byte[] audioData) throws IOException
audioData
- audio data to write to the devicetrue
of the write completed successfully,
false
if the write was cancelled.IOException
- if an error occurs while writing the audio databoolean write(byte[] audioData, int offset, int size) throws IOException
audioData
- audio data to write to the deviceoffset
- the offset into the buffersize
- the number of bytes to write.true
of the write completed successfully,
false
if the write was cancelled.IOException
- if an error occurs while writing the audio datavoid showMetrics()
WebARTS Library Licensed Under the GNU - General Public License. Other Libraries licensed under their respective Open Source Licenses