Package com.sun.speech.freetts.audio
Class MultiFile8BitAudioPlayer
- java.lang.Object
-
- com.sun.speech.freetts.audio.MultiFile8BitAudioPlayer
-
- All Implemented Interfaces:
AudioPlayer
public class MultiFile8BitAudioPlayer extends java.lang.Object implements AudioPlayer
Streams audio to multiple files as 8-bit samples, one per utterance. Currently, FreeTTS always outputs 16-bit samples, and this MultiFile8BitAudioPlayer will convert them to 8-bit before outputting them.
-
-
Constructor Summary
Constructors Constructor Description MultiFile8BitAudioPlayer()
Creates a default audio player for an AudioFileFormat of type WAVE.MultiFile8BitAudioPlayer(java.lang.String baseName, javax.sound.sampled.AudioFileFormat.Type type)
Constructs a MultiFile8BitAudioPlayer
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
begin(int size)
Starts the output of a set of data.void
cancel()
Cancels currently playing audiovoid
close()
Closes this audio playerboolean
drain()
Waits for all queued audio to be playedboolean
end()
Marks the end of a set of data.javax.sound.sampled.AudioFormat
getAudioFormat()
Gets the audio format for this playerlong
getTime()
Gets the amount of played since the last markfloat
getVolume()
Returns the current volume.void
pause()
Pauses 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 timerjava.lang.String
toString()
Returns the name of this audioplayerboolean
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
-
MultiFile8BitAudioPlayer
public MultiFile8BitAudioPlayer()
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>1.wav. The default value for the base name is "freetts".
-
MultiFile8BitAudioPlayer
public MultiFile8BitAudioPlayer(java.lang.String baseName, javax.sound.sampled.AudioFileFormat.Type type)
Constructs a MultiFile8BitAudioPlayer- Parameters:
baseName
- the base name of the audio filetype
- the type of audio output
-
-
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- Throws:
java.lang.UnsupportedOperationException
- if the line cannot be opened with the given format
-
getAudioFormat
public javax.sound.sampled.AudioFormat getAudioFormat()
Gets the audio format for this player- Specified by:
getAudioFormat
in interfaceAudioPlayer
- Returns:
- format the audio format
-
pause
public void pause()
Pauses audio output- Specified by:
pause
in interfaceAudioPlayer
-
resume
public void resume()
Resumes audio output- Specified by:
resume
in interfaceAudioPlayer
-
startFirstSampleTimer
public void startFirstSampleTimer()
Starts the first sample timer- Specified by:
startFirstSampleTimer
in interfaceAudioPlayer
-
cancel
public void cancel()
Cancels currently playing audio- 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
-
close
public void close()
Closes this audio player- 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)
-
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 of a set of data. Audio data for a single utterance should be groupd between begin/end pairs.- Specified by:
end
in interfaceAudioPlayer
- Returns:
- true if the audio was output properly, false if the output was cancelled or interrupted.
-
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 mark- 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
-
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
of 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
of the write completed successfully,false
if the write was cancelled.
-
toString
public java.lang.String toString()
Returns the name of this audioplayer- Overrides:
toString
in classjava.lang.Object
- Returns:
- the name of the audio player
-
showMetrics
public void showMetrics()
Shows metrics for this audio player- Specified by:
showMetrics
in interfaceAudioPlayer
-
-