类 AudioPlayer
java.lang.Object
io.agentscope.core.model.tts.AudioPlayer
Audio player for playing PCM audio data in real-time.
This player uses Java Sound API (javax.sound.sampled) to play audio data. It supports both synchronous and asynchronous playback.
Example usage:
AudioPlayer player = AudioPlayer.builder()
.sampleRate(24000)
.build();
player.start();
// Play audio chunks as they arrive
ttsModel.push("hello").subscribe(player::play);
player.stop();
-
嵌套类概要
嵌套类 -
方法概要
修饰符和类型方法说明static AudioPlayer.Builderbuilder()Creates a new builder for AudioPlayer.voiddrain()Waits for all queued audio to finish playing.voidInterrupts current playback and clears the queue, but keeps the audio line open.voidplay(byte[] audioData) Queues audio data for asynchronous playback.voidplay(AudioBlock audioBlock) Plays an AudioBlock.voidplaySync(byte[] audioData) Plays audio data synchronously.voidstart()Starts the audio player and opens the audio line.voidstop()Stops the audio player and closes the audio line.
-
方法详细资料
-
start
public void start()Starts the audio player and opens the audio line.- 抛出:
TTSException- if audio line cannot be opened
-
playSync
public void playSync(byte[] audioData) Plays audio data synchronously.- 参数:
audioData- PCM audio data
-
play
public void play(byte[] audioData) Queues audio data for asynchronous playback.- 参数:
audioData- PCM audio data
-
play
Plays an AudioBlock.- 参数:
audioBlock- the audio block to play
-
interrupt
public void interrupt()Interrupts current playback and clears the queue, but keeps the audio line open.This is useful when you want to immediately stop current playback and start playing new audio without closing and reopening the audio line. Unlike
stop(), this method keeps the audio line open so new audio can be played immediately. -
stop
public void stop()Stops the audio player and closes the audio line. -
drain
public void drain()Waits for all queued audio to finish playing. -
builder
Creates a new builder for AudioPlayer.- 返回:
- a new Builder instance
-