类 DashScopeRealtimeTTSModel
- 所有已实现的接口:
RealtimeTTSModel,TTSModel
This model uses DashScope's WebSocket-based TTS API via WebSocketTransport, enabling true streaming input where text can be pushed incrementally while maintaining context continuity for natural prosody and intonation.
Key Features:
- WebSocket-based streaming with WebSocketTransport
- Supports both
server_commitandcommitmodes push(text)- Push text incrementally, TTS maintains contextfinish()- Signal end of input, get remaining audio- Solves prosody/intonation issues that occur with independent HTTP requests
- No 600-character limit per request (streaming input)
Session Modes:
server_commit- Server automatically commits text buffer for synthesiscommit- Client must manually commit text buffer
Usage Example:
DashScopeRealtimeTTSModel tts = DashScopeRealtimeTTSModel.builder()
.apiKey(apiKey)
.modelName("qwen3-tts-flash-realtime")
.voice("Cherry")
.mode(SessionMode.SERVER_COMMIT)
.build();
// Start a streaming session
tts.startSession();
// Push text chunks as LLM generates them (context is maintained!)
tts.push("Hello, ").subscribe(audio -> player.play(audio));
tts.push("welcome to ").subscribe(audio -> player.play(audio));
tts.push("AgentScope.").subscribe(audio -> player.play(audio));
// Finish and get remaining audio
tts.finish().subscribe(audio -> player.play(audio));
-
嵌套类概要
嵌套类修饰符和类型类说明static classBuilder for constructing DashScopeRealtimeTTSModel instances.static enumSession mode for TTS. -
方法概要
修饰符和类型方法说明builder()Creates a new builder for DashScopeRealtimeTTSModel.voidClears the text buffer.voidclose()Closes the WebSocket connection and releases resources.voidCommits the text buffer to trigger processing.reactor.core.publisher.Flux<AudioBlock> finish()Finishes the streaming session and retrieves remaining audio.reactor.core.publisher.Flux<AudioBlock> Gets the audio stream for listening to all audio chunks.Gets the model name.reactor.core.publisher.Flux<AudioBlock> Pushes a text chunk for synthesis.voidStarts a new TTS session with WebSocket connection.booleanReturns true if this model supports streaming input (push/finish pattern).reactor.core.publisher.Mono<TTSResponse> synthesize(String text, TTSOptions options) Synthesizes text to audio (blocking).reactor.core.publisher.Flux<AudioBlock> synthesizeStream(String text) Synthesizes complete text to audio using streaming.booleanwaitForResponseDone(long timeout, TimeUnit unit) Waits for the current response to complete.
-
方法详细资料
-
supportsStreamingInput
public boolean supportsStreamingInput()Returns true if this model supports streaming input (push/finish pattern).- 返回:
- always true for this implementation
-
startSession
public void startSession()Starts a new TTS session with WebSocket connection.This establishes a WebSocket connection to DashScope's TTS service. Call this before using push()/finish() pattern.
- 指定者:
startSession在接口中RealtimeTTSModel
-
push
Pushes a text chunk for synthesis.Unlike HTTP-based TTS, this maintains context continuity across multiple push() calls, resulting in natural prosody and intonation.
Note: This method returns empty Flux. Audio is delivered through
getAudioStream()to avoid duplicate subscriptions causing repeated audio playback.- 指定者:
push在接口中RealtimeTTSModel- 参数:
text- the text chunk to synthesize- 返回:
- empty Flux (audio delivered via getAudioStream)
-
commitTextBuffer
public void commitTextBuffer()Commits the text buffer to trigger processing.Only needed in
DashScopeRealtimeTTSModel.SessionMode.COMMITmode. InDashScopeRealtimeTTSModel.SessionMode.SERVER_COMMITmode, the server commits automatically. -
clearTextBuffer
public void clearTextBuffer()Clears the text buffer. -
finish
Finishes the streaming session and retrieves remaining audio.This signals the end of input and waits for all audio to be generated. The sink will be completed when the server sends the "session.finished" event.
- 指定者:
finish在接口中RealtimeTTSModel- 返回:
- Flux of remaining AudioBlock chunks
-
waitForResponseDone
Waits for the current response to complete.- 参数:
timeout- the maximum time to waitunit- the time unit of the timeout- 返回:
- true if the response completed within the timeout
-
close
public void close()Closes the WebSocket connection and releases resources.- 指定者:
close在接口中RealtimeTTSModel
-
getAudioStream
Gets the audio stream for listening to all audio chunks.- 指定者:
getAudioStream在接口中RealtimeTTSModel- 返回:
- Flux of AudioBlock that emits audio as it's synthesized
-
synthesizeStream
Synthesizes complete text to audio using streaming.This is a convenience method that creates a session, pushes all text, and returns the complete audio stream.
- 指定者:
synthesizeStream在接口中RealtimeTTSModel- 参数:
text- the complete text to synthesize- 返回:
- Flux of AudioBlock chunks as they are generated
-
synthesize
Synthesizes text to audio (blocking).- 指定者:
synthesize在接口中TTSModel- 参数:
text- the text to synthesizeoptions- optional TTS options (may be null)- 返回:
- Mono containing the TTS response with audio data
-
getModelName
Gets the model name.- 指定者:
getModelName在接口中TTSModel- 返回:
- the model name
-
builder
Creates a new builder for DashScopeRealtimeTTSModel.- 返回:
- a new Builder instance
-