Package com.sun.speech.freetts.audio
Class RawFileAudioPlayer
- java.lang.Object
-
- com.sun.speech.freetts.audio.RawFileAudioPlayer
-
- All Implemented Interfaces:
AudioPlayer
public class RawFileAudioPlayer extends java.lang.Object implements AudioPlayer
Provides an implementation ofAudioPlayer
that sends all audio data to the given file.
-
-
Constructor Summary
Constructors Constructor Description RawFileAudioPlayer()
Creates a default audio player for an AudioFileFormat of type WAVE.RawFileAudioPlayer(java.lang.String path)
Constructs a NullAudioPlayer
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
begin(int size)
Starts the output of a set of datavoid
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 playedboolean
end()
Marks the end of a set of datajavax.sound.sampled.AudioFormat
getAudioFormat()
Retrieves the audio format for this playerlong
getTime()
Gets the amount of played since the last resetTime Currently not supported.float
getVolume()
Returns the current volume.void
pause()
Pauses the audio outputvoid
reset()
Prepares for another batch of output.void
resetTime()
Resets the audio clockvoid
resume()
Resumes audio outputvoid
setAudioFormat(javax.sound.sampled.AudioFormat format)
Sets the audio format for this playervoid
setVolume(float volume)
Sets the current volume.void
showMetrics()
Shows metrics for this audio playervoid
startFirstSampleTimer()
Starts the first sample timerboolean
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 Detail
-
RawFileAudioPlayer
public RawFileAudioPlayer() throws java.io.IOException
Creates a default audio player for an AudioFileFormat of type WAVE. Reads the "com.sun.speech.freetts.AudioPlayer.baseName" property for the base filename to use, and will produce files of the form <baseName>.raw. The default value for the base name is "freetts".- Throws:
java.io.IOException
-
RawFileAudioPlayer
public RawFileAudioPlayer(java.lang.String path) throws java.io.IOException
Constructs a NullAudioPlayer- Throws:
java.io.IOException
-
-
Method Detail
-
setAudioFormat
public void setAudioFormat(javax.sound.sampled.AudioFormat format)
Sets the audio format for this player- Specified by:
setAudioFormat
in interfaceAudioPlayer
- Parameters:
format
- the audio format
-
getAudioFormat
public javax.sound.sampled.AudioFormat getAudioFormat()
Retrieves the audio format for this player- Specified by:
getAudioFormat
in interfaceAudioPlayer
- Returns:
- the current audio format.
-
cancel
public void cancel()
Cancels all queued output. Current 'write' call will return false- Specified by:
cancel
in interfaceAudioPlayer
-
pause
public void pause()
Pauses the audio output- Specified by:
pause
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
-
resume
public void resume()
Resumes audio output- Specified by:
resume
in interfaceAudioPlayer
-
close
public void close()
Waits for all audio playback to stop, and closes this AudioPlayer.- 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)
-
write
public boolean write(byte[] audioData)
Writes the given bytes to the audio stream- Specified by:
write
in interfaceAudioPlayer
- 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 interfaceAudioPlayer
- 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 interfaceAudioPlayer
- Returns:
true
if the audio was output properly,false
if the output was canceled or interrupted.
-
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
of the write completed successfully,false
if the write was cancelled.
-
startFirstSampleTimer
public void startFirstSampleTimer()
Starts the first sample timer- Specified by:
startFirstSampleTimer
in interfaceAudioPlayer
-
drain
public boolean drain()
Waits for all queued audio to be played- Specified by:
drain
in interfaceAudioPlayer
- 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 interfaceAudioPlayer
- Returns:
- the amount of audio in milliseconds
-
resetTime
public void resetTime()
Resets the audio clock- Specified by:
resetTime
in interfaceAudioPlayer
-
showMetrics
public void showMetrics()
Shows metrics for this audio player- Specified by:
showMetrics
in interfaceAudioPlayer
-
-