Skip to navigation

Word-Level Timestamps

View as Markdown

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:

ValueResponse fieldEach entry coversModels and modes
wordwordsOne wordsaaras:v4, in transcribe, codemix, verbatim, and translit mode
segmentsegmentsOne chunk of audio, which can hold several sentencessaaras: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.

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

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)

Word response

{
"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"
}
FieldDescription
words[].textThe word exactly as it appears in transcript, in the same script and with any punctuation attached (नमस्ते,).
words[].startWhen the word starts, in seconds from the start of the audio, rounded to 3 decimals. null if the word couldn’t be timed.
words[].endWhen 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:

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

Skip or fill in only the untimed entries:

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:

{
"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.

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")

After creating the job, upload the audio, start the job, and download the output with the standard 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:

{
"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"
}
}
Requesterror.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].

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

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.