Language Detection

PreviousNext

Detect the language of a short audio clip without transcribing it.

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-detection

Authentication

Authorization: Bearer sk-...

Request

Content-Type: multipart/form-data

FieldTypeRequiredDescription
filefileyesAudio clip (WAV, MP3, M4A, FLAC, …). Repeat the field (or use files) for batch detection.
filesfilenoAlternative batch field name. Max 10 files per request.

Limits

LimitValue
Max duration per file20 seconds
Max files per request10
Max size per file10 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
}
FieldTypeDescription
languagestring | nullISO 639-1 style code (zh, en, yue, …); null when undetermined (for example, no speech)
confidencenumber | nullLanguage probability (0–1); null when undetermined
duration_secondsnumber | nullOriginal audio duration
speech_secondsnumber | nullSpeech 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

StatusCodeDescription
400—Invalid multipart body, missing/empty file, or too many files
401—Authentication failed
413audio_too_longA file exceeds 20 seconds or 10 MB
502—Upstream detection failed
503—Detection backend is not configured