> This page is for Model APIs.

> For clean Markdown of any page, append `.md` to the page URL.
> For a complete documentation index, see https://docs.sarvam.ai/llms.txt. For a section index, append `/llms.txt` to any section URL (for example https://docs.sarvam.ai/voice-agents/llms.txt).
> For AI client integration (Claude Code, Cursor, etc.), connect to the MCP server at https://docs.sarvam.ai/_mcp/server.

# Word-Level Timestamps

> Get start and end times for every word in a Saaras v4 transcript with timestamp_granularity, on the REST and Batch speech-to-text APIs.

Set `timestamp_granularity` on the REST or Batch speech-to-text API to get start and end times for your transcript. The value you pick decides which field the response adds:

| Value     | Response field | Each entry covers                                    | Models and modes                                                         |
| --------- | -------------- | ---------------------------------------------------- | ------------------------------------------------------------------------ |
| `word`    | `words`        | One word                                             | `saaras:v4`, in `transcribe`, `codemix`, `verbatim`, and `translit` mode |
| `segment` | `segments`     | One chunk of audio, which can hold several sentences | `saaras:v4` and `saaras:v3`, in all modes                                |

Both fields are lists of `{text, start, end}` objects. `word` returns `words` and `segment` returns `segments`, each on its own. The older `timestamps` object appears only when you also set `with_timestamps=true`.

Use word timestamps for word-by-word caption highlighting, karaoke-style playback, cutting audio at an exact word, or lining up a transcript with video. Use segment timestamps to find roughly where each part of a long Batch recording is.

> **Note**
>
> `timestamp_granularity` is available in the Python SDK from `sarvamai` 0.1.50 and in the JavaScript SDK from `sarvamai` 1.1.23. Upgrade with `pip install -U sarvamai` or `npm install sarvamai@latest`.

## REST API

#### Python

```python
import os
from sarvamai import SarvamAI

client = SarvamAI(api_subscription_key=os.environ["SARVAM_API_KEY"])

with open("audio.wav", "rb") as audio:
    response = client.speech_to_text.transcribe(
        file=audio,
        model="saaras:v4",
        mode="transcribe",
        language_code="hi-IN",
        timestamp_granularity="word",
    )

for word in response.words:
    print(word.start, word.end, word.text)
```

#### JavaScript

```javascript
import { SarvamAIClient } from "sarvamai";
import fs from "fs";

const client = new SarvamAIClient({
    apiSubscriptionKey: process.env.SARVAM_API_KEY
});

const response = await client.speechToText.transcribe({
    file: fs.createReadStream("audio.wav"),
    model: "saaras:v4",
    mode: "transcribe",
    language_code: "hi-IN",
    timestamp_granularity: "word",
});

for (const word of response.words ?? []) {
    console.log(word.start, word.end, word.text);
}
```

#### cURL

```bash
curl -X POST https://api.sarvam.ai/speech-to-text \
  -H "api-subscription-key: $SARVAM_API_KEY" \
  -F 'model=saaras:v4' \
  -F 'mode=transcribe' \
  -F 'language_code=hi-IN' \
  -F 'timestamp_granularity=word' \
  -F 'file=@audio.wav;type=audio/wav'
```

### Word response

```json
{
  "request_id": "20261126_f7e630fe-d31e-48f0-b545-f6967cdce653",
  "transcript": "नमस्ते, आप कैसे हैं?",
  "words": [
    {"text": "नमस्ते,", "start": 0.018, "end": 0.667},
    {"text": "आप",     "start": 0.784, "end": 1.028},
    {"text": "कैसे",    "start": 1.061, "end": 1.36},
    {"text": "हैं?",    "start": 1.37,  "end": 1.673}
  ],
  "language_code": "hi-IN"
}
```

| Field           | Description                                                                                                                |
| --------------- | -------------------------------------------------------------------------------------------------------------------------- |
| `words[].text`  | The word exactly as it appears in `transcript`, in the same script and with any punctuation attached (`नमस्ते,`).          |
| `words[].start` | When the word starts, in seconds from the start of the audio, rounded to 3 decimals. `null` if the word couldn't be timed. |
| `words[].end`   | When the word ends, in seconds from the start of the audio, rounded to 3 decimals. `null` if the word couldn't be timed.   |

`words` has one entry per word of the transcript, in the same order, so you can map each word back to its place in `transcript`.

If a word couldn't be timed, it keeps its `text` but its `start` and `end` are `null`. The other words keep their times:

```json
"words": [
  {"text": "नमस्ते,", "start": 0.12, "end": 0.66},
  {"text": "ठीक",    "start": null, "end": null}
]
```

Skip or fill in only the untimed entries:

```python
for word in response.words:
    if word.start is None:
        continue  # This word has no timing; the rest of the list does.
    print(word.start, word.end, word.text)
```

### Segment response

With `timestamp_granularity=segment`, the response has a `segments` list instead of `words`. Each entry is one chunk of audio as the model processed it, so a segment can hold several sentences, and its `start` and `end` include any silence in that chunk. A REST request usually returns a single segment that covers the whole clip, from `0.0` to the end of the audio, even if the speaker pauses:

```json
{
  "request_id": "20261126_158fa2bd-d6c7-4f57-9acc-4f7d63be5444",
  "transcript": "नमस्ते, आप कैसे हैं? मेरा नाम राहुल है और मैं दिल्ली से बोल रहा हूँ। आज मौसम बहुत अच्छा है।",
  "segments": [
    {"text": "नमस्ते, आप कैसे हैं? मेरा नाम राहुल है और मैं दिल्ली से बोल रहा हूँ। आज मौसम बहुत अच्छा है।", "start": 0.0, "end": 6.79}
  ],
  "language_code": "hi-IN"
}
```

## Batch API

For recordings longer than 30 seconds, set `timestamp_granularity` in `job_parameters`. Each output file has the same `words` or `segments` field as the REST response. Times are measured from the start of that file, so you can use them directly even though long audio is processed in chunks. With `segment`, you get one entry per chunk; chunks are split at pauses in the speech.

Batch output files always include a `timestamps` key. It is `null` unless you also set `with_timestamps=true`, so check for `words` or `segments` rather than for `timestamps`.

#### Python

```python
job = client.speech_to_text_job.create_job(
    model="saaras:v4",
    mode="transcribe",
    language_code="hi-IN",
    timestamp_granularity="word",
)
job.upload_files(file_paths=["lecture.mp3"])
job.start()
job.wait_until_complete()
job.download_outputs(output_dir="./output")
```

#### JavaScript

```javascript
const job = await client.speechToTextJob.createJob({
    model: "saaras:v4",
    mode: "transcribe",
    languageCode: "hi-IN",
    timestampGranularity: "word",
});

await job.uploadFiles(["lecture.mp3"]);
await job.start();
await job.waitUntilComplete();
await job.downloadOutputs("./output");
```

#### cURL

```bash
curl --fail-with-body -X POST \
  'https://api.sarvam.ai/speech-to-text/job/v1' \
  -H "api-subscription-key: $SARVAM_API_KEY" \
  -H 'Content-Type: application/json' \
  -d '{
    "job_parameters": {
      "model": "saaras:v4",
      "mode": "transcribe",
      "language_code": "hi-IN",
      "timestamp_granularity": "word"
    }
  }'
```

After creating the job, upload the audio, start the job, and download the output with the standard [Batch API](/api/api-guides-tutorials/speech-to-text/batch-api) workflow.

You can combine `timestamp_granularity` with `with_diarization`. Speaker labels are in `diarized_transcript.entries`, so to see who said a word, match the word's time against each entry's `start_time_seconds` and `end_time_seconds`.

## Errors

The API checks `timestamp_granularity` when the request arrives. If the model or mode can't return the timestamps you asked for, it returns a `400` with a message that names the supported options:

```json
{
  "error": {
    "message": "'word' timestamps are not supported in mode 'translate'. Supported modes: transcribe, codemix, verbatim, translit.",
    "code": "invalid_request_error",
    "request_id": "20261126_1e8c8969-3e2a-410f-a422-9a6e081191e4"
  }
}
```

| Request                                                              | `error.message`                                                                                                               |
| -------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------- |
| `timestamp_granularity=word` with a model other than `saaras:v4`     | `'word' timestamps are not supported by model '<model>'. Supported models: saaras:v4.`                                        |
| `timestamp_granularity=word` with `mode=translate`                   | `'word' timestamps are not supported in mode 'translate'. Supported modes: transcribe, codemix, verbatim, translit.`          |
| Any value other than `word` or `segment` (values are case-sensitive) | `body.timestamp_granularity : Input should be 'segment' or 'word'` (Batch: `body.job_parameters.timestamp_granularity : ...`) |

For Batch jobs, these checks run when you create the job, so an unsupported combination fails before you upload any audio.

## The older `with_timestamps` format

Before `timestamp_granularity`, timestamps came from `with_timestamps=true`. It still works and returns the same `timestamps` object as before: three parallel lists, where `timestamps.words[i]` runs from `timestamps.start_time_seconds[i]` to `timestamps.end_time_seconds[i]`.

```json
"timestamps": {
  "words": ["नमस्ते, आप कैसे हैं? मेरा नाम राहुल है और मैं दिल्ली से बोल रहा हूँ। आज मौसम बहुत अच्छा है।"],
  "start_time_seconds": [0.0],
  "end_time_seconds": [6.79]
}
```

Despite its name, `timestamps.words` holds chunks of the transcript, not single words. It carries the same information as `segments`, in the older format.

> **Warning**
>
> `with_timestamps` will be deprecated soon. New integrations should use `timestamp_granularity`. Existing integrations keep working for now, but plan to move.

To switch an existing integration:

1. For the same segment-level output, replace `with_timestamps=true` with `timestamp_granularity=segment` and read `segments` instead of `timestamps`.
2. For one entry per word, use `timestamp_granularity=word` with `model="saaras:v4"` and read `words`.

`segments[i].text`, `.start`, and `.end` hold the same values as `timestamps.words[i]`, `timestamps.start_time_seconds[i]`, and `timestamps.end_time_seconds[i]`.

If you send both `with_timestamps=true` and `timestamp_granularity`, the response includes both the `timestamps` object and the `words` or `segments` field, so you can migrate one reader at a time.