> ## 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.

# Label speakers

> Find out who said what: speaker labels (diarization) on Batch transcription, with start and end times for every turn.

Use this when a recording has more than one speaker, such as a call or an interview, and you need to know who said each part.

## Turn it on

Speaker labels are a [Batch](https://docs.gnani.ai/api/STTBatch/Introduction.md) feature. Set `with_diarization: true` in the job's `config`, and optionally `num_speakers`, the most speakers to separate. Each segment of the transcript then carries a `speaker_id`. This example runs the whole job on the two-speaker sample clip:

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

# 1. Create the job and upload the file
JOB_ID=$(curl --silent --request POST \
  --url https://api.vachana.ai/stt/v3/batch/jobs \
  --header "X-API-Key-ID: $GNANI_API_KEY" \
  -F 'config={"model":"prisma-v3.0","language_code":"hi-IN","with_diarization":true,"num_speakers":2};type=application/json' \
  -F "files=@./two-speakers.wav" | jq -r .job_id)

# 2. Start it
curl --silent --request POST --url "https://api.vachana.ai/stt/v3/batch/jobs/$JOB_ID/start" \
  --header "X-API-Key-ID: $GNANI_API_KEY" > /dev/null

# 3. Wait until it finishes, polling every 10 seconds
while true; do
  status=$(curl --silent --url "https://api.vachana.ai/stt/v3/batch/jobs/$JOB_ID" \
    --header "X-API-Key-ID: $GNANI_API_KEY" | jq -r '.status // empty')
  if [ -z "$status" ]; then echo "Could not read the job status" >&2; break; fi
  case $status in COMPLETED|PARTIAL_FAILURE|FAILED|START_FAILED|CANCELLED) break ;; esac
  sleep 10
done

# 4. Download the transcript and print who said what
URL=$(curl --silent --url "https://api.vachana.ai/stt/v3/batch/jobs/$JOB_ID/files" \
  --header "X-API-Key-ID: $GNANI_API_KEY" | jq -r '.data[0].transcript_url')
curl --silent "$URL" | jq -r '.segments[] | "[\(.start_time)–\(.end_time)] speaker \(.speaker_id): \(.text)"'
```

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

import requests

API = "https://api.vachana.ai/stt/v3/batch/jobs"
HEADERS = {"X-API-Key-ID": os.environ["GNANI_API_KEY"]}
TERMINAL = {"COMPLETED", "PARTIAL_FAILURE", "FAILED", "START_FAILED", "CANCELLED"}
config = {"model": "prisma-v3.0", "language_code": "hi-IN", "with_diarization": True, "num_speakers": 2}

# 1. Create the job and upload the file
with open("two-speakers.wav", "rb") as f:
    r = requests.post(
        API,
        headers=HEADERS,
        files={
            "config": (None, json.dumps(config), "application/json"),
            "files": ("two-speakers.wav", f, "audio/wav"),
        },
        timeout=120,
    )
r.raise_for_status()
job_id = r.json()["job_id"]

# 2. Start it
requests.post(f"{API}/{job_id}/start", headers=HEADERS, timeout=60).raise_for_status()

# 3. Wait until it finishes, polling every 10 seconds
while True:
    job = requests.get(f"{API}/{job_id}", headers=HEADERS, timeout=60).json()
    if job["status"] in TERMINAL:
        break
    time.sleep(10)

# 4. Download the transcript and print who said what
files = requests.get(f"{API}/{job_id}/files", headers=HEADERS, timeout=60).json()["data"]
transcript = requests.get(files[0]["transcript_url"], timeout=60).json()
for seg in transcript["segments"]:
    print(f"[{seg['start_time']}–{seg['end_time']}] speaker {seg['speaker_id']}: {seg['text']}")
```

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

const API = "https://api.vachana.ai/stt/v3/batch/jobs";
const headers = { "X-API-Key-ID": process.env.GNANI_API_KEY };
const terminal = ["COMPLETED", "PARTIAL_FAILURE", "FAILED", "START_FAILED", "CANCELLED"];
const config = { model: "prisma-v3.0", language_code: "hi-IN", with_diarization: true, num_speakers: 2 };

// 1. Create the job and upload the file
const form = new FormData();
form.append("config", new Blob([JSON.stringify(config)], { type: "application/json" }));
form.append("files", new Blob([readFileSync("two-speakers.wav")], { type: "audio/wav" }), "two-speakers.wav");
let response = await fetch(API, { method: "POST", headers, body: form });
if (!response.ok) throw new Error(await response.text());
const { job_id } = await response.json();

// 2. Start it
response = await fetch(`${API}/${job_id}/start`, { method: "POST", headers });
if (!response.ok) throw new Error(await response.text());

// 3. Wait until it finishes, polling every 10 seconds
while (true) {
  const job = await (await fetch(`${API}/${job_id}`, { headers })).json();
  if (terminal.includes(job.status)) break;
  await new Promise((resolve) => setTimeout(resolve, 10_000));
}

// 4. Download the transcript and print who said what
const { data } = await (await fetch(`${API}/${job_id}/files`, { headers })).json();
const transcript = await (await fetch(data[0].transcript_url)).json();
for (const seg of transcript.segments) {
  console.log(`[${seg.start_time}–${seg.end_time}] speaker ${seg.speaker_id}: ${seg.text}`);
}
```

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

client = GnaniSTTBatchClient()  # reads GNANI_API_KEY

result = client.transcribe(
    "two-speakers.wav",
    model="prisma-v3.0",
    language_code="hi-IN",
    diarization=True,  # with_diarization
    speakers=2,        # num_speakers
)
for seg in result[0].segments:
    print(f"[{seg.start}–{seg.end}] speaker {seg.speaker}: {seg.text}")
```

## Examples

A synthetic call (Timbre v3.0, Hindi, 12.2 seconds): three turns from two voices, an agent and a customer.

| Listen | What is said |
| - | - |
| <audio controls preload="none" src="https://docs.gnani.ai/audio/samples/two-speakers-hi-IN.wav" aria-label="Sample call with two speakers, in Hindi" /> | **Agent:** नमस्ते, मैं Vachana से बोल रही हूँ। क्या आपके पास दो मिनट हैं? **Customer:** हाँ, बताइए। मेरा सवाल EMI की तारीख के बारे में है। **Agent:** आपकी अगली EMI पंद्रह तारीख को है। |

The segments from a Prisma v3.0 job with `with_diarization: true` and `num_speakers: 2`:

| `start_time` | `end_time` | `speaker_id` | `text` |
| - | - | - | - |
| 0 | 4.2 | 1 | नमस्ते, मैं वचना से बोल रही हूँ, क्या आपके पास 2 minute हैं? |
| 4.2 | 9.43 | 2 | हाँ, बताइए, मेरा सवाल EMI की तारीख के बारे में है। |
| 9.43 | 12.16 | 1 | आपकी अगली ईएमआई 15 तारीख को है। |

The agent's two turns are both `1`, and the customer is `2`. Prisma v2.5 split and labelled the same three turns at the same times, with its own wording. Both models also returned labels without `with_diarization`: see [By model](#by-model).

## By interface

> [tab] Batch
>
> `config.with_diarization` and `config.num_speakers` on [Create job](https://docs.gnani.ai/api/STTBatch/Create_Job.md). Each segment in the [transcript document](https://docs.gnani.ai/api/STTBatch/Get_Job_Files.md#transcript-document) has `speaker_id`, `start_time` and `end_time`.

> [tab] REST
>
> Not available. [REST](https://docs.gnani.ai/api/STT/speech-to-text.md) returns one transcript for the clip. `speaker_names` is not speaker labelling: it only helps the model spell names. For a short clip with several speakers, send it as a one-file Batch job.

> [tab] Realtime
>
> Not available. Each [Realtime](https://docs.gnani.ai/api/STT/stt-websocket.md) message is one utterance, with no speaker label. If each speaker is on a separate channel, as in many phone systems, stream each channel on its own connection.

## By model

| | Prisma v3.0 | Prisma v2.5 |
| - | - | - |
| Speaker labels | Always produced on Batch. `with_diarization` decides only whether a labelling failure fails the file. | Documented as needing `with_diarization: true`. In the example job, labels came back without it too (TBC). |
| `num_speakers` | 1 to 8, default 5 | Same |
| Language per segment | Each segment's language in `language_detected` | Per file only |

## Rules and limits

| | Rule |
| - | - |
| `num_speakers` | 1 to 8. Default 5. An upper limit, not a target: speakers are counted automatically. |
| `speaker_id` | A number for each voice in the file (1, 2, …). It is not a name, and it only identifies a voice within that file. |
| Segments | A segment is a stretch of speech between pauses, split again where the speaker changes. |
| Multi-channel audio | Set `is_multi_channel: true` only for true multi-channel recordings. |
| Noisy audio | With `with_denoise: true`, speaker labels and timestamps come from the cleaned audio. |
| Limits | The [Batch limits](https://docs.gnani.ai/api/STTBatch/Introduction.md#limits): up to 4 hours per file, 100 files per upload. |

## Things to watch for

* **Labels are per file.** Speaker `1` in one file and speaker `1` in another are not the same person. Map labels to people yourself, for example by who speaks first.
* **`num_speakers` is a ceiling.** Set it lower than the real number of speakers and some voices cannot be told apart. If you are not sure, leave the default of 5.
* **`speaker_names` does not label speakers.** It helps the model spell names that are spoken; on Batch it cannot be combined with `keyterms` or `topic`.
* **Prisma v3.0 labels speakers even without `with_diarization`.** Set it to `true` if you want a file to fail when labelling fails, rather than come back without reliable labels.
* **Short turns and overlapping speech** are the hardest to label. The example uses clean synthetic speech with clear pauses; test with your own recordings.
* **Python SDK:** the options are `diarization` and `speakers`. Setting `speakers` also turns `diarization` on.

## Related

> [card] [Batch transcription](https://docs.gnani.ai/api/STTBatch/Introduction.md)
>
> Jobs, statuses, webhooks and limits.

> [card] [Get job files](https://docs.gnani.ai/api/STTBatch/Get_Job_Files.md#transcript-document)
>
> Every field of the transcript document.

> [card] [Detect the language](https://docs.gnani.ai/api/STT/detect-language.md)
>
> Language per segment on Prisma v3.0.

> [card] [Call analytics](https://docs.gnani.ai/api/use-cases/call-analytics.md)
>
> A worked example that builds on speaker-labelled transcripts.


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