返回首页
Lanson Flow 文档库

Generate subtitle files from transcription result timestamps.

From transcription results to subtitles

Segment data from a completed transcription can be directly converted to SRT or VTT:

{
  "segments": [
    { "id": 0, "start_time": 0.0, "end_time": 3.2, "text": "The weather is nice today" },
    { "id": 1, "start_time": 3.5, "end_time": 8.1, "text": "It might rain tomorrow" }
  ]
}

SRT format

1
00:00:00,000 --> 00:00:03,200
The weather is nice today

2 00:00:03,500 --> 00:00:08,100 It might rain tomorrow

VTT format

WEBVTT

00:00:00.000 --> 00:00:03.200 The weather is nice today

00:00:03.500 --> 00:00:08.100 It might rain tomorrow

Time format conversion

| Format | Time notation | |---|---| | SRT | HH:MM:SS,mmm (comma for milliseconds) | | VTT | HH:MM:SS.mmm (dot for milliseconds) | | API | Seconds (float) |

Conversion function

def seconds_to_srt(seconds):
    h = int(seconds // 3600)
    m = int((seconds % 3600) // 60)
    s = int(seconds % 60)
    ms = int((seconds % 1) * 1000)
    return f"{h:02d}:{m:02d}:{s:02d},{ms:03d}"

def generate_srt(segments): lines = [] for i, seg in enumerate(segments, 1): lines.append(str(i)) lines.append(f"{seconds_to_srt(seg['start_time'])} --> {seconds_to_srt(seg['end_time'])}") lines.append(seg['text']) lines.append("") return "\n".join(lines)

Segmentation rules

  • Each API segment maps to one subtitle entry
  • Gaps between segments naturally become subtitle breaks
  • No additional subtitle length limits are imposed by the API
  • For traditional subtitle formatting (character-per-line limits), split long segments client-side
  • Related

  • [Timestamps & Speakers](/docs/recorded/timestamps-speakers) — timestamp reference
  • [Transcribe Audio](/docs/recorded/transcribe-audio) — get transcription results
  • [Save a Transcript](/docs/guides/save-transcript) — persistence guide