POST /v1/audio/language-detection
What it does
Detects only the language of one or more short audio clips. No transcript text is returned. Use it when you do not know the language up front, then pass the detected code to a realtime session, a segment request, or a batch job.
If you already know the language, pass it directly — an explicit language is more accurate than detection.
Endpoint
POST /v1/audio/language-detectionAuthentication
Authorization: Bearer sk-...Request
Content-Type: multipart/form-data
| Field | Type | Required | Description |
|---|---|---|---|
file | file | yes | Audio clip (WAV, MP3, M4A, FLAC, …). Repeat the field (or use files) for batch detection. |
files | file | no | Alternative batch field name. Max 10 files per request. |
Limits
| Limit | Value |
|---|---|
| Max duration per file | 20 seconds |
| Max files per request | 10 |
| Max size per file | 10 MB |
A file over 20 seconds rejects the whole request with 413 audio_too_long.
Example
curl -X POST https://audio.lansonai.com/v1/audio/language-detection \
-H "Authorization: Bearer sk-..." \
-F "file=@sample.wav"Response — 200 OK
Single file:
{
"language": "en",
"confidence": 0.952,
"duration_seconds": 11,
"speech_seconds": 11
}| Field | Type | Description |
|---|---|---|
language | string | null | ISO 639-1 style code (zh, en, yue, …); null when undetermined (for example, no speech) |
confidence | number | null | Language probability (0–1); null when undetermined |
duration_seconds | number | null | Original audio duration |
speech_seconds | number | null | Speech duration after VAD |
Multiple files return { "results": [...] }, with one entry per file. Per-file failures appear as error entries in the batch response.
Using the detected language
{ "type": "session.update", "language": "en" }Use the returned language in realtime session.update, as the segment language form field, or as the batch language field.
For a realtime session whose language changes mid-stream, detect the new clip again and send the new explicit code, or send { "type": "session.update", "language": "auto" } and let the session re-detect on subsequent speech.
If you use session-level auto-detection instead of calling this endpoint, the detected language is returned on each conversation.item.input_audio_transcription.completed event as language, with language_source: "auto" and language_provisional indicating whether detection has locked.
Errors
| Status | Code | Description |
|---|---|---|
| 400 | — | Invalid multipart body, missing/empty file, or too many files |
| 401 | — | Authentication failed |
| 413 | audio_too_long | A file exceeds 20 seconds or 10 MB |
| 502 | — | Upstream detection failed |
| 503 | — | Detection backend is not configured |
Related
- Languages & Models — language behavior per API
- Realtime API —
session.update - Segment Transcription — sync clips
- Batch Jobs — async transcription