AGTCloud API Docs
GuidesAPI ReferenceIntegrations and resourcesUpdate and help
RealtimeMuse Voice Transcribe

Realtime transcription

Stream PCM audio to Muse Voice Transcribe over WebSocket and receive realtime transcription events.

Send raw PCM audio over WebSocket and receive transcription, speech-turn and speaker events. This endpoint returns text, not spoken replies.

WSS
wss://api.agtcloud.cn/v1/asr/realtime

Connection parameters

First-frame configuration

Send this JSON within 10 seconds of connecting, without type, up to 64 KiB. Wait for sessionId before sending audio. Configuration cannot change after the session starts.

Connection flow

  1. Connect and send authentication and audio settings in the first JSON text frame.
  2. Wait for an acknowledgement containing sessionId, then send binary audio at realtime speed while receiving events.
  3. After the audio, send {"type":"endStream"} and keep reading trailing results until the server closes the connection.

The examples read audio.pcm, use the API_KEY environment variable and run for at most 60 seconds. Install ws for Node.js or websocket-client for Python. Keep long-lived API Keys on the server.

Audio input

ItemRequirement
FormatMono PCM16 little-endian; no WAV header or Base64 encoding
Sample rate16 kHz or 24 kHz, matching audioEncoding in the first frame
ChunksAt most 1 MiB per frame, with an even byte count; one frame every 100 ms is recommended
PaceAt 24 kHz, 4800 bytes per 100 ms; at 16 kHz, 3200 bytes. Send at realtime speed

Silence is part of the audio timeline. Send PCM silence in the same format when continuous input is needed.

# Convert audio to raw 24 kHz mono PCM16
ffmpeg -i input.mp3 -ac 1 -ar 24000 -c:a pcm_s16le -f s16le audio.pcm

Event Reference

The first acknowledgement has no type. Dispatch later events by type and ignore unknown types. After configuration, the client only sends binary audio and the endStream text message.

Event direction
Category
Event

endStream

After ending audio input, keep receiving trailing events until the server closes the connection.

Handling results

SituationHandling
Partial textCUMULATIVE replaces the current turn's partial text; DELTA appends new text
Turn completespeechEnd only marks the end of speech. Read full text from speechComplete.transcript and save by turnId; turns may interleave
Empty final texttranscript with final: true may be empty. Do not overwrite saved cumulative text or complete turn results
Speakerspeaker.label labels the preceding audio span within this session; it does not mean speech ended or the speaker changed
Audio progressaudioProcessedMs is cumulative processing time. Do not add event values or treat them as precise word-level timestamps

Partial transcript events have no turnId; maintain current partial text using the latest speechStart. Archive completed results by speechComplete.turnId. Do not disconnect immediately after endStream, or trailing events may be lost.

Session limits and errors

Sessions last about 60 minutes at most. No client messages for 15 seconds may trigger input finalization. Set read and total-duration limits. Reconnect with a new session; do not reuse sessionId to resume audio.

Close codeMeaningHandling
1000Normal completionSave the final results received and finish
1008Invalid parameters, authentication or audio pacing policyCheck the first frame, audio format and sending pace; do not repeatedly retry unchanged
1011Server or upstream interruptionKeep the session ID and close reason; start a new session when the duration limit is reached
1013Rate limitedWait and reconnect with backoff; limit retries

On error, retain message, sessionId and the close reason. Realtime transcription is billed by processed audio duration; see the Model catalog for prices.

References