Speech to text
Transcribe short audio, submit long file jobs, or stream live audio for final segment transcripts.
Choose a published speech-to-text model from GET /v1/inference/models.
Use its public name and check the returned audio limit. Upload a WAV file
for one-shot transcription, submit a file transcription job
for a recording up to five hours when the model advertises supports_async,
or stream audio over a live WebSocket.
Upload a file
Send POST /v1/inference/audio/transcriptions with an Inference key, a unique
Idempotency-Key, and multipart/form-data fields:
| Field | Value |
|---|---|
model | Published STT alias, for example kejue-stt |
file | PCM16 mono 16 kHz WAV |
language | ar (default), en, or automatic recognition with auto |
Use the model's published duration limit, up to 300 seconds. We check the WAV samples themselves, not its filename or a duration your client reports. Studio converts supported browser audio locally; your API client must send the WAV format in the table. Deployment body limits also apply; use a file job for larger original recordings.
This synchronous response contains no word or speech-segment timestamps. For aligned word timing and durable results, use file jobs and inspect the model’s published timestamp and language capabilities.
The result gives you text, language, duration_ms, request_id, and the
public model name. The language echoes ar or en when you request it;
with auto, it returns unklang.
An unknown or unpublished name, or a TTS name, returns
404 inference_model_not_found. X-Kejue-Request-Id is returned after admission, including computation failures, so clients can inspect the durable request. Accepted input duration uses the STT wallet.
A repeated request identity returns 409 inference_request_exists without
another transcription. Use GET /v1/inference/requests/{id} for durable status.
Live transcription
Connect your backend directly to GET /v1/inference/audio/transcriptions/realtime.
Send your Inference key in the Authorization: Bearer … handshake header,
and model, language, and max_audio_seconds in the query string. You do
not need to mint a token first.
- Choose a published STT model.
languageisar(default),en, orauto.max_audio_secondsis 1–300, defaults to 60, and must fit the published cap. - Open the WebSocket with these parameters and your API-key header.
- Wait for
{"type":"ready"}. Send binary little-endian PCM16 mono at 16 kHz, at most 64 KiB per frame, with bounded client backpressure. - Send
{"type":"commit"}to finalize a segment. The server emits{"type":"transcript","text":"…","segment":1,"final":true}. To have us decide where each segment ends instead, turn on turn detection. - Send
{"type":"finish"}to finalize the last segment and close. Wait for thefinishedevent. Anerrorevent or an unexpected socket close means the session did not complete normally.
Install pip install "websockets>=14". This backend example streams a local
PCM16 mono 16 kHz WAV, then prints the final transcripts:
import asyncio, json, os, wave
from urllib.parse import urlencode
from websockets.asyncio.client import connect
API = os.environ.get("KEJUE_API_BASE", "https://api.kejue.co/v1")
KEY = os.environ["KEJUE_INFERENCE_KEY"]
async def main() -> None:
query = urlencode({"model": "kejue-stt", "language": "en", "max_audio_seconds": 60})
socket_base = API.replace("https://", "wss://", 1).replace("http://", "ws://", 1)
url = f"{socket_base}/inference/audio/transcriptions/realtime?{query}"
async with connect(url, additional_headers={"Authorization": f"Bearer {KEY}"}) as ws:
ready = json.loads(await ws.recv())
if ready["type"] != "ready":
raise RuntimeError(ready)
print("request", ready["request_id"])
async def send_audio() -> None:
with wave.open("input.wav", "rb") as audio:
if (audio.getnchannels(), audio.getsampwidth(), audio.getframerate()) != (1, 2, 16000):
raise ValueError("Use a PCM16 mono 16 kHz WAV")
if audio.getnframes() > 60 * 16000:
raise ValueError("Audio exceeds this session's 60-second cap")
while chunk := audio.readframes(1600):
await ws.send(chunk)
await asyncio.sleep(0.1)
await ws.send(json.dumps({"type": "finish"}))
async def receive_transcripts() -> None:
async for message in ws:
event = json.loads(message)
if event["type"] == "transcript":
print(event["text"])
elif event["type"] == "error":
raise RuntimeError(event["code"])
elif event["type"] == "finished":
return
raise RuntimeError("Session closed before finished")
async with asyncio.TaskGroup() as tasks:
tasks.create_task(send_audio())
tasks.create_task(receive_transcripts())
asyncio.run(main())Use Python 3.11 or later for TaskGroup. kejue-stt is the published
speech-to-text name today; confirm yours with GET /v1/inference/models.
Turn detection
With turn detection on, you stream the caller's audio continuously, pauses included, and we decide when each turn starts and ends. You do not need your own voice activity detection or end-of-turn logic. We listen for speech, and when the speaker pauses, an end-of-turn model judges from how the sentence ends whether they have finished or are only pausing. A finished turn is transcribed straight away, so its transcript usually arrives within tens of milliseconds of the decision.
Add turn_detection to the connection query string, or to the
POST /v1/inference/realtime-tokens body for a browser:
…/inference/audio/transcriptions/realtime?model=kejue-stt&language=ar&max_audio_seconds=300&turn_detection=semantic&td_silence_ms=400{
"model": "kejue-stt",
"language": "ar",
"max_audio_seconds": 300,
"turn_detection": { "type": "semantic", "silence_ms": 400, "max_silence_ms": 1200 }
}In the query string, prefix each setting with td_. Every setting is optional:
| Setting | Default | What it does |
|---|---|---|
type | semantic | semantic uses the end-of-turn model. vad ends the turn after silence_ms of silence, without the model |
silence_ms | 330 | Silence before we decide (semantic) or end the turn (vad) |
max_silence_ms | 1200 | With semantic, the longest we wait after the speaker's last word before ending the turn anyway |
threshold | 0.7 | How sure the model must be that the turn is complete, from 0 to 1. Lower ends turns sooner |
min_speech_ms | 200 | How much speech opens a turn. Raise it if short noises open turns |
prefix_padding_ms | 500 | Audio kept from just before speech starts, so first syllables are not clipped |
vad_threshold | 0.5 | How confident speech detection must be, from 0 to 1. Raise it on noisy lines |
idle_ms | 0 | End an open turn if your audio stops arriving for this long; 0 turns this off |
no_speech_logprob | -1.05 | Turns the model is this unsure about come back empty, with no_speech: true |
incomplete_threshold | 0.5 | With semantic, a verdict below this counts as unfinished, so we wait longer before ending the turn, more the less finished the sentence sounds; 0 turns it off |
incomplete_extend_ms | 1600 | The most extra time we wait after the speaker's last word when a sentence sounds unfinished, for example mid-way through a phone number |
You then receive these events for each turn, in order:
{"type": "speech_started", "segment": 0, "audio_start_ms": 1184}
{"type": "speech_stopped", "segment": 0, "audio_end_ms": 3808}
{"type": "transcript", "text": "…", "segment": 0, "final": true, "end_of_turn": {"reason": "semantic", "probability": 0.98, "audio_end_ms": 3808, "silence_ms": 352}}Times are milliseconds of audio since the session started. end_of_turn.reason
is semantic (the model judged the turn complete), silence (vad mode, or a
very short turn), max_silence, commit, idle, or max_turn. A transcript
with no_speech: true and empty text means the turn held no speech, for
example a cough or line noise; most voice agents ignore it.
speech_stopped is not the end of the turn: if the speaker carries on, you
get another speech_started for the same segment. React to speech_started
if you need to stop your own audio when the speaker interrupts.
If the selected model does not support turn detection yet, you get
{"type":"error","code":"turn_detection_unavailable"} right after ready;
connect without turn_detection and send commit instead.
You can still send {"type":"commit"} to end the current turn early, for
example when your app knows the speaker has finished. With no turn open, it
transcribes the audio received since the last turn.
Turn-detection sessions are billed on all the audio you send, pauses included; see Limits and completion.
Connect from a browser
Have your backend call POST /v1/inference/realtime-tokens with model,
language, and max_audio_seconds. Return the response to your authenticated
frontend. It contains kind: "stt", an absolute WebSocket url, and a one-use
token valid for 30 seconds. Connect to url with ?token=TOKEN and use the
same audio frames and control messages above. Do not combine a token with an
Authorization header or configuration parameters. Request a fresh token before
each connection attempt. See WebSocket authentication.
Limits and completion
Minutes and concurrency are reserved when the WebSocket connects. Sending
more audio than reserved or exceeding policy/transport limits closes the
session. Accepted PCM duration is chargeable, even when the client disconnects.
With turn detection you stream continuously, so every second you send is
charged, pauses included; max_audio_seconds then defaults to 300 and
accepts up to 525, within the model's published limit, so a session can run
its full time. A session lasts at most 9 minutes. If we receive nothing for 30 seconds before
finish, we send {"type":"error","code":"idle_timeout"} and close.
| Close code | Meaning |
|---|---|
1000 | Normal close after finished |
1008 | idle_timeout, audio_limit_reached, or invalid_message (preceded by an error event) |
1011 | The model failed |
You get final segment transcripts, rather than interim text that changes
while someone speaks. With turn detection, speech_started and
speech_stopped tell you about the speaker in the meantime. Studio stops microphone input before asking for the
final transcript. The usage ledger does not retain audio or transcript content.