Skip to content

Speakers, subtitles and sentences

Three add-ons shape a pre-recorded transcript for reading: diarization says who speaks when, subtitles cut it into captions for a video, sentences split it into sentences. Ask for any of them when you create the job; they come back in the job’s result.

Terminal window
curl -X POST https://eu1.api.gladia.io/v2/pre-recorded \
-H "x-gladia-key: $GLADIA_API_KEY" -H "content-type: application/json" \
-d '{"audio_url": "https://eu1.api.gladia.io/file/0199d7a2-0000-7000-8000-00000000f11e", "diarization": true, "diarization_config": {"number_of_speakers": 2}}'

Every utterance of result.transcription.utterances (and result.diarization.results, the deprecated Classic alias) gets a speaker, from 0, in the order the speakers are first heard:

{"text": "Hello, thanks for calling.", "start": 0.4, "end": 1.9, "channel": 0, "speaker": 0}

The speaker count is optional:

diarization_config when to set it
number_of_speakers you know how many people speak (a two-party call: 2)
min_speakers, max_speakers you know a range (a meeting of 3 to 6)
none you know nothing: the model finds the count

Limits and gotchas:

  • 8 speakers at most per channel: the model tells up to 8 voices apart; with more, some voices share a number.
  • A speaker is a voice, not a name. The numbers are this file’s own: the same person on another file may get another number.
  • Two channels, two parties. When each party is on its own channel (call recordings), the channel already says who speaks: diarization is then only needed when several people share a channel.
Terminal window
curl -X POST https://eu1.api.gladia.io/v2/pre-recorded \
-H "x-gladia-key: $GLADIA_API_KEY" -H "content-type: application/json" \
-d '{"audio_url": "https://eu1.api.gladia.io/file/0199d7a2-0000-7000-8000-00000000f11e", "subtitles": true, "subtitles_config": {"formats": ["srt", "vtt"], "style": "compliance"}}'

result.transcription.subtitles holds one file per format asked, as text:

[
{"format": "srt", "subtitles": "1\n00:00:00,400 --> 00:00:01,900\nHello, thanks for calling.\n\n"},
{"format": "vtt", "subtitles": "WEBVTT\n\n00:00:00.400 --> 00:00:01.900\nHello, thanks for calling.\n\n"}
]
subtitles_config default what it does
formats ["srt"] srt, vtt, or both
maximum_characters_per_row 42 the longest row of a caption
maximum_rows_per_caption 2 rows per caption (1 to 5)
minimum_duration 1 s a shorter caption is held longer, never past the next one’s start
maximum_duration 7 s a longer sentence is split into several captions (1 to 30 s)
style default default: your limits as set. compliance: the usual broadcast rules, at most 42 characters per row and 2 rows per caption, whatever larger limits you set

Captions follow the speakers and channels: a caption never mixes two speakers, and a new speaker or a pause longer than 3 seconds starts a new caption. With pii_redaction, the captions read the redacted text.

Terminal window
curl -X POST https://eu1.api.gladia.io/v2/pre-recorded \
-H "x-gladia-key: $GLADIA_API_KEY" -H "content-type: application/json" \
-d '{"audio_url": "https://eu1.api.gladia.io/file/0199d7a2-0000-7000-8000-00000000f11e", "sentences": true}'

result.sentences.results (and result.transcription.sentences[0].results) holds one object per sentence, with its sentence, start, end, words, confidence, language, channel and speaker (with diarization):

{
"success": true,
"is_empty": false,
"exec_time": 0.004,
"error": null,
"results": [
{
"sentence": "Hello, thanks for calling.",
"start": 0.4,
"end": 1.9,
"confidence": 0.96,
"channel": 0,
"language": "en",
"words": [
{"word": "Hello,", "start": 0.4, "end": 0.8, "confidence": 0.97},
{"word": " thanks", "start": 0.9, "end": 1.2, "confidence": 0.96},
{"word": " for", "start": 1.2, "end": 1.4, "confidence": 0.96},
{"word": " calling.", "start": 1.4, "end": 1.9, "confidence": 0.95}
]
}
]
}

A sentence ends at terminal punctuation (. ! ? …) and at the end of its utterance: it never spans two utterances, so never two speakers or two channels.

Gotcha, words: every word after the first of an utterance or a sentence starts with the space that goes before it ("Hello,", " thanks"). Concatenate words[].word as they are to rebuild the text; joining them with a space doubles every space.