类 TTSHook.Builder
java.lang.Object
io.agentscope.core.hook.TTSHook.Builder
- 封闭类:
TTSHook
Builder for constructing TTSHook instances.
-
构造器概要
构造器 -
方法概要
修饰符和类型方法说明audioCallback(Consumer<AudioBlock> audioCallback) Sets a callback for receiving audio blocks.audioPlayer(AudioPlayer audioPlayer) Sets the audio player for local playback.autoStartPlayer(boolean autoStartPlayer) Sets whether to auto-start the audio player.build()Builds the TTSHook instance.realtimeMode(boolean realtimeMode) Sets whether to use real-time mode.ttsModel(DashScopeRealtimeTTSModel ttsModel) Sets the TTS model for speech synthesis.
-
构造器详细资料
-
Builder
public Builder()
-
-
方法详细资料
-
ttsModel
Sets the TTS model for speech synthesis. (Required)- 参数:
ttsModel- the realtime TTS model- 返回:
- this builder
-
audioPlayer
Sets the audio player for local playback. (Optional)If not set:
- If audioCallback is also not set: A default AudioPlayer will be created automatically (24000 Hz sample rate, mono, 16-bit PCM) for local playback.
- If audioCallback is set: Audio will only be available via audioCallback or getAudioStream(), suitable for server-side usage.
- 参数:
audioPlayer- the audio player, or null to use default or server mode- 返回:
- this builder
-
autoStartPlayer
Sets whether to auto-start the audio player.- 参数:
autoStartPlayer- true to auto-start (default: true)- 返回:
- this builder
-
realtimeMode
Sets whether to use real-time mode.When true (default), TTS is triggered on each text chunk as LLM generates. When false, TTS waits for complete response before synthesis.
- 参数:
realtimeMode- true for real-time "speak as you generate" (default)- 返回:
- this builder
-
audioCallback
Sets a callback for receiving audio blocks. (Optional)This is the recommended way for server-side usage to handle audio. The callback is invoked for each audio block as it's synthesized.
Example for SSE:
.audioCallback(audio -> { Base64Source src = (Base64Source) audio.getSource(); sseEmitter.send(SseEmitter.event() .name("audio") .data(src.getData())); })- 参数:
audioCallback- callback to receive audio blocks- 返回:
- this builder
-
build
Builds the TTSHook instance.If neither audioPlayer nor audioCallback is provided, a default AudioPlayer will be created automatically for local playback (24000 Hz sample rate).
- 返回:
- configured TTSHook
- 抛出:
IllegalArgumentException- if ttsModel is not set
-