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

# Detect the language

> Let Prisma v3.0 identify the spoken language with indic-auto or a short list of languages, and read which language it heard.

Use this when you do not know in advance which language a caller will speak, or when you need to know which language was heard.

## Turn it on

Send `model=prisma-v3.0` with `language_code=indic-auto`, and read `detected_language_code` in the reply. This example uses the Tamil sample clip:

```bash cURL theme={null}
curl -o ta-IN.wav https://docs.gnani.ai/audio/samples/ta-IN.wav

curl --request POST \
  --url https://api.vachana.ai/stt/v3 \
  --header "X-API-Key-ID: $GNANI_API_KEY" \
  --form audio_file=@ta-IN.wav \
  --form model=prisma-v3.0 \
  --form language_code=indic-auto
```

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

import requests

with open("ta-IN.wav", "rb") as f:
    r = requests.post(
        "https://api.vachana.ai/stt/v3",
        headers={"X-API-Key-ID": os.environ["GNANI_API_KEY"]},
        files={"audio_file": ("ta-IN.wav", f, "audio/wav")},
        data={"model": "prisma-v3.0", "language_code": "indic-auto"},
        timeout=60,
    )
r.raise_for_status()
body = r.json()
print(body.get("detected_language_code"), body["transcript"])
```

```javascript Node.js theme={null}
import { readFileSync } from "node:fs";

const form = new FormData();
form.append("audio_file", new Blob([readFileSync("ta-IN.wav")], { type: "audio/wav" }), "ta-IN.wav");
form.append("model", "prisma-v3.0");
form.append("language_code", "indic-auto");

const response = await fetch("https://api.vachana.ai/stt/v3", {
  method: "POST",
  headers: { "X-API-Key-ID": process.env.GNANI_API_KEY },
  body: form,
});
if (!response.ok) throw new Error(await response.text());
const body = await response.json();
console.log(body.detected_language_code, body.transcript);
```

```python Python SDK theme={null}
import os
from gnani.stt import GnaniSTTClient

client = GnaniSTTClient(api_key=os.environ["GNANI_API_KEY"])
result = client.transcribe("ta-IN.wav", model="prisma-v3.0", language_code="indic-auto")
print(result.get("detected_language_code"), result["transcript"])
```

If you know the likely languages, send them instead, comma-separated, such as `language_code=hi-IN,en-IN` (1 to 4). They are a hint for the model, not a limit.

## Examples

Hosted [sample clips](https://docs.gnani.ai/api/introduction/sample-audio.md) (synthetic, Timbre v3.0), sent to Prisma v3.0 on REST with no other options:

| Clip | Listen |
| - | - |
| Tamil | <audio controls preload="none" src="https://docs.gnani.ai/audio/samples/ta-IN.wav" aria-label="Tamil sample" /> |
| Marathi | <audio controls preload="none" src="https://docs.gnani.ai/audio/samples/mr-IN.wav" aria-label="Marathi sample" /> |
| Hindi with English words | <audio controls preload="none" src="https://docs.gnani.ai/audio/samples/hi-IN-en-IN-codemix.wav" aria-label="Hindi and English mixed sample" /> |

| Clip | `language_code` sent | `detected_language_code` | Transcript |
| - | - | - | - |
| Tamil | `indic-auto` | `ta-IN` | வணக்கம் இன்று நான் உங்களுக்கு எப்படி உதவ முடியும் தயவுசெய்து உங்கள் கேள்வியை சொல்லுங்கள் |
| Tamil | `hi-IN` (the wrong language) | `ta-IN` | வணக்கம், இன்று நான் உங்களுக்கு எப்படி உதவ முடியும், தயவுசெய்து உங்கள் கேள்வியை சொல்லுங்கள் |
| Marathi | `indic-auto` | `mr-IN` | नमस्कार, आज मी तुम्हाला कशी मदत करू शकते? कृपया तुमचा प्रश्न सांगा. |
| Hindi with English words | `indic-auto` | `hi-IN` | नमस्ते, मुझे अपना अकाउंट बैलेंस चेक करना है, क्या आप मेरी हेल्प कर सकते हैं? |
| Hindi with English words | `hi-IN,en-IN` | `hi-IN` | नमस्ते, मुझे अपना account balance check करना है, क्या आप मेरी help कर सकते हैं? |

* With the wrong hint, the Tamil clip is still transcribed in Tamil and tagged `ta-IN`.
* The Marathi clip is told apart from Hindi, though both use the Devanagari script.
* A Hindi sentence with English words is tagged `hi-IN`. To control how the English words are written, set the [output style](https://docs.gnani.ai/api/STT/output-styles.md); `format=codemix` keeps them in Latin letters.

Each request gave the same result both times it was run. Synthetic speech is cleaner than most real recordings, so test on your own audio.

## By interface

> [tab] REST
>
> Form field `language_code` on [`POST /stt/v3`](https://docs.gnani.ai/api/STT/speech-to-text), with `model=prisma-v3.0`. The reply carries `detected_language_code` for the whole clip.

> [tab] Realtime
>
> Headers `model: prisma-v3.0` and `language_code: indic-auto` (or a list) on [`WS /stt/v3/stream`](https://docs.gnani.ai/api/STT/stt-websocket#language-list). Each `transcript` message carries `detected_language_code` for that utterance, so it can change when the speaker switches language.
>
> To change the expected language mid-session, send `update_settings`. It applies from the next utterance:
>
> ```json theme={null}
> {"type": "update_settings", "language_code": "ta-IN"}
> ```

> [tab] Batch
>
> `config.language_code` on [Create job](https://docs.gnani.ai/api/STTBatch/Create_Job.md). On Prisma v3.0 the language is decided for each segment (a stretch of speech between pauses), so a call that switches language gets each part in its own language. The [transcript](https://docs.gnani.ai/api/STTBatch/Get_Job_Files.md#transcript-document) reports each segment's language in `language_detected`, and the language with the most speech in `language_code`. `"auto"` is accepted as another spelling of `"indic-auto"`.
>
> ```json theme={null}
> "config": { "model": "prisma-v3.0", "language_code": "indic-auto" }
> ```

## By model

| | Prisma v3.0 | Prisma v2.5 |
| - | - | - |
| `indic-auto` | REST, Realtime and Batch | No |
| A list of languages | 1 to 4 codes on every interface. A hint: speech clearly in another language is transcribed in that language. Order does not matter. | Batch only: up to 3 codes. A limit: each file is transcribed in exactly one of them. Order matters: the first code is the fallback. |
| Decided per | Clip (REST), utterance (Realtime), segment (Batch) | File (Batch) |
| Where it is reported | `detected_language_code` (REST, Realtime); `language_detected` per segment and `language_code` (Batch) | `language_code` in the Batch transcript |

## Rules and limits

| | Limit |
| - | - |
| Languages | Nine Indian languages and English. See [Supported languages](https://docs.gnani.ai/api/STT/languages.md). |
| Codes in a list | Prisma v3.0: 1 to 4. Prisma v2.5 on Batch: up to 3. |
| Too many codes | Batch: `400 INVALID_CONFIG` on Prisma v3.0, `400 UNSUPPORTED_LANGUAGE` on Prisma v2.5. |
| Missing `language_code` | REST: `422`, except with `format=transliterate`, where it defaults to `indic-auto`. Realtime: an `error` message, then the connection closes. |
| Other language errors | `INVALID_LANGUAGE_CODE` and `MODEL_UNSUPPORTED_LANGUAGE`. See [Error Reference](https://docs.gnani.ai/api/introduction/errors.md). |

## Things to watch for

* **The tag comes from the script of the transcript**, not from what you sent. Send `ta-IN` and get an English answer, and the tag is `en-IN`.
* **No tag** for an empty transcript, a transcript of only digits or punctuation, text in a script the API does not map (such as Urdu or Odia), or `format=transliterate`, whose output is always in Latin letters. Read it with `.get()` rather than assuming it is there.
* **Hindi and Marathi** share a script, so a very short utterance (a greeting, a name, a number) may be tagged `hi-IN`. If you know which one to expect, send only that code.
* **Mostly-English speech with a short native phrase** can be tagged `en-IN`: the native-language tag needs at least 30 % of the letters to be in the native script.
* **With `format=transliterate`**, a list of languages is ignored and the language is detected automatically.
* **Python SDK.** For a list of languages, the SDK takes `language_code="indic-auto"` with `language_candidates=[...]` (2 to 4) instead of a comma-separated `language_code`.

## Related

> [card] [Language detection on Prisma v3.0](https://docs.gnani.ai/api/STT/models/prisma-v3.md#language-detection)
>
> How the tag is worked out, in more detail.

> [card] [Supported languages](https://docs.gnani.ai/api/STT/languages.md)
>
> Every language code, with its script.

> [card] [Choose an output style](https://docs.gnani.ai/api/STT/output-styles.md)
>
> How English words and numbers are written in a mixed-language transcript.

> [card] [Improve names and terms](https://docs.gnani.ai/api/STT/names-and-terms.md)
>
> Help the model spell names and domain words.


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