接口 RealtimeTTSModel
- 所有超级接口:
TTSModel
- 所有已知实现类:
DashScopeRealtimeTTSModel
This interface extends TTSModel with methods for streaming text input,
enabling "speak as you generate" functionality. Unlike the base TTSModel
which requires complete text upfront, this interface allows pushing text
incrementally while maintaining context continuity.
Key difference from TTSModel:
TTSModel: One-time input, streaming output (e.g., HTTP + SSE)RealtimeTTSModel: Streaming input + streaming output (e.g., WebSocket)
Typical models:
qwen3-tts-flash-realtime- WebSocket real-time modelcosyvoice-v2- WebSocket streaming model
Usage Example:
RealtimeTTSModel tts = DashScopeRealtimeTTSModel.builder()
.apiKey(apiKey)
.modelName("qwen3-tts-flash-realtime")
.voice("Cherry")
.build();
// Start streaming session
tts.startSession();
// Push text chunks (context maintained for natural prosody)
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 session and get remaining audio
tts.finish().blockLast();
// Clean up
tts.close();
- 另请参阅:
-
方法概要
修饰符和类型方法说明voidclose()Closes the TTS session and releases resources.reactor.core.publisher.Flux<AudioBlock> finish()Signals end of input and flushes remaining audio.reactor.core.publisher.Flux<AudioBlock> Gets the audio stream for receiving synthesized audio.reactor.core.publisher.Flux<AudioBlock> Pushes text incrementally to the TTS service.voidStarts a new streaming session.reactor.core.publisher.Flux<AudioBlock> synthesizeStream(String text) Synthesizes text using streaming and returns audio blocks.从接口继承的方法 io.agentscope.core.model.tts.TTSModel
getModelName, synthesize
-
方法详细资料
-
startSession
void startSession()Starts a new streaming session.This typically establishes a WebSocket connection to the TTS service. Must be called before
push(String)orfinish().- 抛出:
TTSException- if session cannot be started
-
push
Pushes text incrementally to the TTS service.Text is buffered and synthesized while maintaining context continuity, resulting in natural prosody and intonation across chunks.
- 参数:
text- the text chunk to synthesize- 返回:
- Flux of AudioBlock containing synthesized audio
-
finish
reactor.core.publisher.Flux<AudioBlock> finish()Signals end of input and flushes remaining audio.Call this when all text has been pushed to receive any remaining synthesized audio.
- 返回:
- Flux of AudioBlock containing remaining audio
-
synthesizeStream
Synthesizes text using streaming and returns audio blocks.This is a convenience method that handles the full session lifecycle (start, push, finish) for a single text input.
- 参数:
text- the complete text to synthesize- 返回:
- Flux of AudioBlock as audio is synthesized
-
close
void close()Closes the TTS session and releases resources.Should be called when the model is no longer needed to close WebSocket connections and clean up resources.
-
getAudioStream
reactor.core.publisher.Flux<AudioBlock> getAudioStream()Gets the audio stream for receiving synthesized audio.This method returns a Flux that emits audio blocks as they are synthesized. Subscribe to this stream once after calling
startSession()to receive audio data.Important: Only subscribe once per session. Multiple subscriptions may cause duplicate audio playback.
- 返回:
- Flux of AudioBlock that emits audio as it's synthesized
-