Audio Language Detection

Give it an uploaded audio or video file and it identifies which language is spoken, returning the language code and confidence synchronously — no polling required.

It answers only that one question. It does not produce a transcript, subtitles, or timecodes. For transcription use Speech Recognition; for subtitles use AI Subtitles.

Typical use: you have a batch of unlabeled footage and want to sort it by language before sending each group to transcription or subtitling — without paying for a full recognition pass just to learn the language.

Detection uses the first 30 seconds of audio, matching the recognition model's single-pass window. Anything beyond that never enters the decision. Only those 30 seconds are decoded during sampling, so runtime is independent of source length — a 2-hour video costs the same as a 30-second clip. That is why this endpoint is billed per call.

Create a task

Basics

ItemValue
MethodPOST
Path/task/audio_language_detect
Content-Typeapplication/json
AuthenticationAuthorization header (pass the API Key directly)
ResponseSynchronous (not an async task; no polling)

Request body

FieldTypeRequiredDefaultDescription
file_idstringYes—ID of an uploaded file. Audio or video both work; for video the audio track is used. The file must contain a usable audio stream, otherwise a parameter error is returned and nothing is billed

Billing

1 credit per call, independent of source length (detection always uses the first 30 seconds). Failures are not billed: if the upstream service is unavailable, times out, or the file has no audio stream, the pre-deduction is refunded and the net charge is 0.

Every call leaves a task record; the task_id in the response can be looked up through the task list.

Request example

curl -X POST https://api.ai-mcn.tv:10000/task/audio_language_detect \
  -H "Authorization: YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"file_id": "537489015178246"}'

Response example

{
  "code": 200,
  "msg": "success",
  "data": {
    "language": "zh-CN",
    "raw_language": "zh",
    "confidence": 0.9873,
    "candidates": [
      { "language": "zh-CN", "raw_language": "zh", "confidence": 0.9873 },
      { "language": "zh-HK", "raw_language": "yue", "confidence": 0.0071 },
      { "language": "ja-JP", "raw_language": "ja", "confidence": 0.0022 },
      { "language": "ko-KR", "raw_language": "ko", "confidence": 0.0011 },
      { "language": "en-US", "raw_language": "en", "confidence": 0.0009 }
    ],
    "detected_window_sec": 30.0,
    "task_id": "537489015178247"
  }
}

Response fields

FieldTypeDescription
languagestring | nullPlatform language code, e.g. zh-CN. null when the detected language is not in the platform language table — read raw_language in that case. The server never falls back to a default language
raw_languagestringThe recognition model's own language code, e.g. zh / yue / th. Never empty
confidencenumberProbability of the top language (0–1)
candidatesobject[]Five candidates in descending probability order, with the same three fields as the top result
detected_window_secnumberActual detection window for this call, in seconds. 30.0 when the source is longer; the true source length when shorter
task_idstringTask ID recorded for billing

How to read the result

Always check the confidence

Language detection is a probability distribution, so silence, pure music, and ambient noise will still yield some language — the model has no "none of these" option. A low confidence usually means there is no recognizable speech in that audio, not that it really is that language.

Pick your own threshold: tolerance for misclassification varies by use case, so the server returns the distribution as-is rather than deciding for you.

The candidate list exists for confusable languages

These pairs are known confusions for the recognition model, and looking only at the top result turns them into invisible errors:

  • Mandarin (zh-CN) and Cantonese (zh-HK)
  • Spanish and Portuguese
  • Indonesian and Malay

When these are in play, compare the top two probabilities in candidates; a narrow gap means you should bring in business context.

Short audio yields a short window

Sources shorter than 30 seconds are accepted normally, but detected_window_sec will be below 30. When the evidence is only two or three seconds, lower confidence is expected.

Notes

  • The first call may be slow. The recognition model loads on demand and is released when idle, so the first request after eviction can take minutes to warm up. Set a client timeout of ≥180 seconds.
  • Fails fast when the model is busy. The model serves one task at a time; if a long job holds it, this endpoint returns 6402 and asks you to retry. That is a capacity condition, and a retry usually succeeds.
  • Single language only. This endpoint returns one language verdict; it does not segment "Chinese first half, English second half."

Error codes

HTTPCodeMeaning
4006016Parameter error, or the file has no usable audio stream
401—Authentication failed
4026201 / 6202Insufficient balance or quota. Rejected upfront — the recognition service is not contacted and nothing is billed
4046004File does not exist or does not belong to this account
5006401Upstream recognition service unavailable (not billed)
5006402Upstream timeout, or the model is busy (not billed). Retry later