Class RecognitionSession
java.lang.Object
com.alibaba.dashscope.resources.audio.RecognitionSession
- All Implemented Interfaces:
AutoCloseable
ASR realtime session (audio design §1.1): ws duplex over the task protocol. Pull model — no SDK
threads; user discipline is one send thread + one receive thread,
finally close().
Pumped events are buffered inside the session, so stop() may be called before
consuming results (the design-doc pattern) and events()/results() can replay
from the beginning at any time. close() is idempotent and the session can be re-start()ed (new task, new socket unless a shared WsConnection was supplied).
-
Method Summary
Modifier and TypeMethodDescriptionvoidclose()Idempotent.Iterable<com.fasterxml.jackson.databind.JsonNode>events()Raw event frames (header included), task-finished included; task-failed raises.First audio frame to first 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).getUsage()results()Typed results: result-generated only, server heartbeat sentences filtered out.voidsendAudioFrame(byte[] data) Send one binary audio frame (zero-copy path upstream; at most one copy internally).voidsendAudioFrame(ByteBuffer data) voidstart()Connect (unless a shared connection was supplied), send run-task, block until task-started.voidstop()finish-task and wait for task-finished with the client receive timeout.voidfinish-task and wait for task-finished, bounded bytimeout(fixes the 2.x unboundedstopLatch.await()deadlock).voidupdateContext(Map<String, Object> payloadInput) continue-task with the map carried aspayload.inputverbatim (2.x parity).
-
Method Details
-
start
public void start()Connect (unless a shared connection was supplied), send run-task, block until task-started. -
sendAudioFrame
public void sendAudioFrame(byte[] data) Send one binary audio frame (zero-copy path upstream; at most one copy internally). -
sendAudioFrame
-
updateContext
continue-task with the map carried aspayload.inputverbatim (2.x parity). -
stop
public void stop()finish-task and wait for task-finished with the client receive timeout. -
stop
-
events
Raw event frames (header included), task-finished included; task-failed raises. -
results
Typed results: result-generated only, server heartbeat sentences filtered out. -
getTaskId
-
getRequestId
-
getLastResponse
public com.fasterxml.jackson.databind.JsonNode getLastResponse()The last text frame received (raw, header included). -
getUsage
-
getFirstPackageDelay
First audio frame to first result; null until both happened. -
getLastPackageDelay
finish-task to task-finished; null until both happened. -
close
public void close()Idempotent. With a shared connection this detaches the task only — unless the task owns the binary uplink and closed before its terminal event, which tears the whole shared connection down (binary frames carry no task id, so the lane cannot be handed over safely). The session may be re-started afterwards; on a torn-down shared connection the re-start fails fast.- Specified by:
closein interfaceAutoCloseable
-