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://api.agtcloud.cn/v1/asr/realtimeConnection 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
- Connect and send authentication and audio settings in the first JSON text frame.
- Wait for an acknowledgement containing
sessionId, then send binary audio at realtime speed while receiving events. - 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
| Item | Requirement |
|---|---|
| Format | Mono PCM16 little-endian; no WAV header or Base64 encoding |
| Sample rate | 16 kHz or 24 kHz, matching audioEncoding in the first frame |
| Chunks | At most 1 MiB per frame, with an even byte count; one frame every 100 ms is recommended |
| Pace | At 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.pcmEvent 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.
endStream
After ending audio input, keep receiving trailing events until the server closes the connection.
Handling results
| Situation | Handling |
|---|---|
| Partial text | CUMULATIVE replaces the current turn's partial text; DELTA appends new text |
| Turn complete | speechEnd only marks the end of speech. Read full text from speechComplete.transcript and save by turnId; turns may interleave |
| Empty final text | transcript with final: true may be empty. Do not overwrite saved cumulative text or complete turn results |
| Speaker | speaker.label labels the preceding audio span within this session; it does not mean speech ended or the speaker changed |
| Audio progress | audioProcessedMs 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 code | Meaning | Handling |
|---|---|---|
1000 | Normal completion | Save the final results received and finish |
1008 | Invalid parameters, authentication or audio pacing policy | Check the first frame, audio format and sending pace; do not repeatedly retry unchanged |
1011 | Server or upstream interruption | Keep the session ID and close reason; start a new session when the duration limit is reached |
1013 | Rate limited | Wait 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.