Skip to Content
Speech to text

Connect a live transcription session

Permissioninference-stt:createAdd-onInferenceAuthentication
GET
/inference/audio/transcriptions/realtime

Opens a WebSocket for live transcription.

Connecting

From a backend, send an Inference API key in the Authorization Bearer header, with the model, language (ar, en or auto; default ar) and max_audio_seconds (1–300; default 60, within the model's limit) query parameters.

From a browser, mint a one-use token with POST /inference/realtime-tokens and connect with the token query parameter alone. Never combine token with Authorization, and never put a long-lived key in a URL. A token is consumed on the first connection attempt.

Sending audio

Send binary PCM16 mono 16 kHz frames, at most 64 KiB each. Send {"type":"commit"} to finalize a segment, or {"type":"finish"} to finalize and close.

Events carry a type of ready, transcript, finished or error. A transcript carries final text — refining interim hypotheses are not supported.

Turn detection

Add turn_detection (semantic or vad) and any td_* settings as query parameters, or set turn_detection on the token request, and the model ends each turn itself: stream audio continuously and skip commit. Each turn is marked by speech_started and speech_stopped, and its final transcript carries end_of_turn (reason, probability, audio_end_ms, silence_ms) and no_speech: true when the turn held no speech. With turn detection on, max_audio_seconds accepts 1–525 (default 300), and pauses are charged like any other audio. Send commit before finish if a turn may still be open. A model without turn detection answers with a turn_detection_unavailable error event.

Limits and close codes

A session lasts at most 9 minutes, and accepted audio is charged, bounded by your reserved minutes and the published limit. A session that receives nothing for 30 seconds before finish gets an idle_timeout error event and closes with 1008.

Close codes are 1000 after finished; 1008 for idle_timeout, audio_limit_reached or invalid_message; 1011 when the model fails.

Credentials, options, permissions and available minutes are all checked before the upgrade, and each direct connection creates a new session.

See live transcription and turn detection.

Authorization

headerAuthorizationBearer <token>

Use an Inference API key. Access and keys.

Query Parameters

token?string

One-use browser token. Omit when authenticating with an API key.

Length43 <= length <= 43
model?string

Published STT model alias. Required with API-key authentication; omit when using a token.

language?string

STT language with API-key authentication. Omit when using a token.

Default"ar"
Value in"ar""en""auto"
max_audio_seconds?integer

Audio reservation cap with API-key authentication. Omit when using a token. 1–300 (default 60) without turn detection; 1–525 (default 300) with turn_detection. Always within the model limit.

Range1 <= value <= 525
turn_detection?string

Turn detection with API-key authentication (see InferenceTurnDetection). The model finds turns in a continuous stream and sends speech_started, speech_stopped and one final transcript per turn. Omit for the commit-driven session; omit when using a token.

Value in"semantic""vad"
td_silence_ms?integer

Silence before a verdict (semantic) or before the turn ends (vad), in milliseconds. Requires turn_detection. API-key authentication only.

Range100 <= value <= 5000
td_max_silence_ms?integer

Semantic backstop in milliseconds; at least td_silence_ms. Requires turn_detection. API-key authentication only.

Range200 <= value <= 10000
td_threshold?number

Turn-model completion probability (semantic). Requires turn_detection. API-key authentication only.

Range0 <= value <= 1
td_min_speech_ms?integer

Voice needed before a turn opens, in milliseconds. Requires turn_detection. API-key authentication only.

Range0 <= value <= 2000
td_prefix_padding_ms?integer

Audio kept from before the detected start of speech, in milliseconds. Requires turn_detection. API-key authentication only.

Range0 <= value <= 2000
td_vad_threshold?number

Speech probability above which a frame counts as voice. Requires turn_detection. API-key authentication only.

Range0 <= value <= 1
td_idle_ms?integer

Ends an open turn when no audio arrives for this long; 0 turns it off. Requires turn_detection. API-key authentication only.

Range0 <= value <= 10000
td_no_speech_logprob?number

Mean token log-probability below which a turn is reported as no speech. Requires turn_detection. API-key authentication only.

Range-10 <= value <= 0
td_incomplete_threshold?number

With semantic turn detection, an end-of-turn probability below this counts as clearly unfinished and extends the wait by td_incomplete_extend_ms; 0 turns it off. Must not exceed td_threshold. Requires turn_detection. API-key authentication only.

Range0 <= value <= 1
td_incomplete_extend_ms?integer

Extra silence allowed after the speaker's last word when the end-of-turn model judges the sentence clearly unfinished. Requires turn_detection. API-key authentication only.

Range0 <= value <= 10000

Response Body

WebSocket upgraded. Client sends binary PCM16 mono 16 kHz; JSON controls commit or finish. Server events: ready, transcript (final text), finished, error.

Example Request
curl -X GET 'https://api.kejue.co/v1/inference/audio/transcriptions/realtime'
Example Response
Empty