Class SynthesisSession
java.lang.Object
com.alibaba.dashscope.resources.audio.SynthesisSession
- All Implemented Interfaces:
AutoCloseable
TTS duplex session (audio design §1.2): ws task protocol, text up, binary audio down. Pull model
— no SDK threads.
events() (mixed JsonNode + byte[]) and audioChunks() (audio only) share one
single-use reader: whichever claims first (at iterator() time) wins, and any second claim
throws SdkException immediately. Frames are consumed on delivery — a reader that starts
late sees only the frames not yet consumed, e.g. buffered before stop(). close() is idempotent but the session is NOT restartable (Python parity — asymmetric with ASR).
On a shared WsConnection the binary downlink is claimed at start() and released
at task end.
-
Method Summary
Modifier and TypeMethodDescriptionIterable<byte[]>Audio frames only.voidcancel()finish-task withdirective:cancel— once only, and never sent after a terminal event.voidvoidclose()Idempotent; detaches from a shared connection — unless closed before the terminal event while owning the binary downlink, which tears the whole shared connection down.events()Mixed stream: JsonNode for text events (task-finished included), byte[] for audio frames.voidflush()continue-task{input:{flush:true}}— synthesize buffered text without ending.First text sent to first audio/result; null until both happened.finish-task to task-finished; null until both happened.com.fasterxml.jackson.databind.JsonNodeThe last text frame received (raw, header included) — recorded before error rethrow (§6).getUsage()voidcontinue-task carryingpayload.input.text(2.x SpeechSynthesizerV2 parity).voidstart()Connect (unless shared), send run-task, block until task-started; claims binary downlink.voidstop()finish-task and wait for task-finished with the client receive timeout.voidfinish-task and wait for task-finished, bounded bytimeout.
-
Method Details
-
start
public void start()Connect (unless shared), send run-task, block until task-started; claims binary downlink. -
sendText
continue-task carryingpayload.input.text(2.x SpeechSynthesizerV2 parity). -
flush
public void flush()continue-task{input:{flush:true}}— synthesize buffered text without ending. -
stop
public void stop()finish-task and wait for task-finished with the client receive timeout. -
stop
finish-task and wait for task-finished, bounded bytimeout. -
cancel
public void cancel()finish-task withdirective:cancel— once only, and never sent after a terminal event. -
cancel
-
events
Mixed stream: JsonNode for text events (task-finished included), byte[] for audio frames. Single-use and mutually exclusive withaudioChunks()(a second claim throws); frames are consumed on delivery; task-failed raises. -
audioChunks
Audio frames only. Single-use, mutually exclusive withevents(). -
getTaskId
-
getRequestId
-
getLastResponse
public com.fasterxml.jackson.databind.JsonNode getLastResponse()The last text frame received (raw, header included) — recorded before error rethrow (§6). -
getUsage
-
getFirstPackageDelay
First text sent to first audio/result; null until both happened. -
getLastPackageDelay
finish-task to task-finished; null until both happened. -
close
public void close()Idempotent; detaches from a shared connection — unless closed before the terminal event while owning the binary downlink, which tears the whole shared connection down. NOT restartable.- Specified by:
closein interfaceAutoCloseable
-