> ## Documentation Index
> Fetch the complete documentation index at: https://docs.modulate.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Language Detection

> Identify the spoken language of an audio file, with a confidence score, across 100 languages in one synchronous call.

Language Detection identifies the language being spoken and scores its confidence in that answer. It produces no transcript, diarization, or enrichment data.

The usual use is routing: read the language code off the response and send the audio to the matching downstream pipeline.

## Language Detection (batch)

Returns `application/json`. Every field is always present.

| Field | Type | Contents |
| - | - | - |
| `predicted_language` | string | Human-readable language name, such as `"English"`. Suitable for display. |
| `predicted_language_code` | string | Lowercase ISO 639-1 code, such as `"en"`. Suitable for routing, locale switching, or BCP 47 tags. |
| `confidence` | number | Probability for the predicted language, 0.0 to 1.0. |
| `duration_ms` | integer | Total duration of the decoded audio. Only the first 30 seconds are analyzed regardless of this value. |

### Try it

<CodeGroup>
  ```bash curl + jq theme={null}
  curl -sS -X POST https://platform.modulate.ai/api/velma-2-language-detection-batch \
    -H "X-API-Key: $MODULATE_API_KEY" \
    -F "upload_file=@audio.mp3" \
  | jq -r 'if .detail then "error: \(.detail)" else
      "\(.predicted_language) (\(.predicted_language_code)) at \(.confidence)"
    end'
  ```

  ```python Python theme={null}
  import os, requests

  response = requests.post(
      "https://platform.modulate.ai/api/velma-2-language-detection-batch",
      headers={"X-API-Key": os.environ["MODULATE_API_KEY"]},
      files={"upload_file": open("audio.mp3", "rb")},
  )
  response.raise_for_status()
  result = response.json()

  print(f"{result['predicted_language']} ({result['predicted_language_code']}) "
        f"at {result['confidence']}")
  ```

  ```javascript JavaScript theme={null}
  import fs from "fs";
  import FormData from "form-data";

  const form = new FormData();
  form.append("upload_file", fs.createReadStream("audio.mp3"), { filename: "audio.mp3" });

  const response = await fetch(
    "https://platform.modulate.ai/api/velma-2-language-detection-batch",
    {
      method: "POST",
      headers: { "X-API-Key": process.env.MODULATE_API_KEY, ...form.getHeaders() },
      body: form,
    }
  );

  const result = await response.json();

  if (!response.ok) {
    console.error(`error: ${result.detail}`);
    process.exit(1);
  }
  console.log(`${result.predicted_language} (${result.predicted_language_code}) at ${result.confidence}`);
  ```
</CodeGroup>

```text Output theme={null}
English (en) at 0.9847
```

<Accordion title="Response">
  ```json theme={null}
  {
    "predicted_language": "English",
    "predicted_language_code": "en",
    "confidence": 0.9847,
    "duration_ms": 14253
  }
  ```
</Accordion>

### What you can configure

| Form field | Default | Effect |
| - | - | - |
| `upload_file` | *required* | The audio to analyze. This endpoint takes no other parameters. |

### Audio formats

Accepted extensions include `.mp3`, `.wav`, `.flac`, `.m4a`, `.mp4`, `.ogg`, `.opus`, `.webm`, `.aac`, `.aiff`, and `.mov`, plus 85 others.

<Accordion title="All 96 accepted extensions">
  `.3g2`, `.3ga`, `.3gp`, `.3gpp`, `.8svx`, `.aa3`, `.aac`, `.ac3`, `.act`, `.adts`, `.aif`,
  `.aifc`, `.aiff`, `.alac`, `.amb`, `.amr`, `.ape`, `.asf`, `.at3`, `.au`, `.avi`, `.avr`,
  `.awb`, `.bwf`, `.c2`, `.caf`, `.dss`, `.dts`, `.dtshd`, `.eac3`, `.ec3`, `.f4a`, `.f4b`,
  `.flac`, `.flv`, `.gsm`, `.iff`, `.m2a`, `.m2ts`, `.m4a`, `.m4b`, `.m4r`, `.m4v`, `.mka`,
  `.mkv`, `.mlp`, `.mmf`, `.mov`, `.mp+`, `.mp1`, `.mp2`, `.mp3`, `.mp4`, `.mpa`, `.mpc`, `.mpeg`,
  `.mpg`, `.mpga`, `.mpp`, `.mts`, `.mxf`, `.nist`, `.oga`, `.ogg`, `.ogx`, `.oma`, `.omg`,
  `.opus`, `.paf`, `.pvf`, `.qcp`, `.ra`, `.rf64`, `.rka`, `.rm`, `.rmvb`, `.sf`, `.shn`, `.snd`,
  `.sph`, `.svx`, `.tak`, `.thd`, `.ts`, `.tta`, `.vob`, `.voc`, `.vqf`, `.w64`, `.wav`,
  `.wave`, `.weba`, `.webm`, `.wma`, `.wmv`, `.wv`
</Accordion>

Maximum file size is 100 MB. Empty files are rejected with `400`.

### Behavior and constraints

Only the first 30 seconds of audio are analyzed. Longer files are accepted and the remainder is ignored, so `duration_ms` can exceed the analyzed span. Aim for at least 3 to 5 seconds of clear speech at the start.

Audio in a language outside the supported set returns the closest supported match, usually with low `confidence`.

## Acting on the confidence score

`confidence` near `1.0` means the model committed to an answer. Near `0.0` means it could not. There is no universally correct threshold; set one against how much misclassification the application can absorb.

```python theme={null}
result = response.json()

if result["confidence"] < 0.5:
    handle_unknown_language()
else:
    route_to_language_pipeline(result["predicted_language_code"])
```

## Supported languages

100 spoken languages are recognized: Afrikaans, Albanian, Amharic, Arabic, Armenian, Assamese, Azerbaijani, Bashkir, Basque, Belarusian, Bengali, Bosnian, Breton, Bulgarian, Cantonese, Catalan, Chinese, Croatian, Czech, Danish, Dutch, English, Estonian, Faroese, Finnish, French, Galician, Georgian, German, Greek, Gujarati, Haitian Creole, Hausa, Hawaiian, Hebrew, Hindi, Hungarian, Icelandic, Indonesian, Italian, Japanese, Javanese, Kannada, Kazakh, Khmer, Korean, Lao, Latin, Latvian, Lingala, Lithuanian, Luxembourgish, Macedonian, Malagasy, Malay, Malayalam, Maltese, Maori, Marathi, Mongolian, Myanmar, Nepali, Norwegian, Nynorsk, Occitan, Pashto, Persian, Polish, Portuguese, Punjabi, Romanian, Russian, Sanskrit, Serbian, Shona, Sindhi, Sinhala, Slovak, Slovenian, Somali, Spanish, Sundanese, Swahili, Swedish, Tagalog, Tajik, Tamil, Tatar, Telugu, Thai, Tibetan, Turkish, Turkmen, Ukrainian, Urdu, Uzbek, Vietnamese, Welsh, Yiddish, Yoruba.

## API reference

* [Language Detection Batch](/api-reference/language-detection/batch)


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.