How to Auto-Generate Subtitles using Python?

If you're looking to auto-generate subtitles through Python, you can use a speech-to-text AI. An example of a platform that supports auto-transcription is Creatomate; a cloud-based video editing API for developers. Here is how you can use its API to generate animated captions from your Python script:

Input Code
import requests

json = {
 'source': {
  'output_format': 'mp4',
  'elements': [
    'type': 'video',
    'id': '17ca2169-786f-477f-aaea-4a2598bf24eb',
    'source': ''
    'type': 'text',
    'transcript_source': '17ca2169-786f-477f-aaea-4a2598bf24eb',
    'transcript_effect': 'highlight',
    'transcript_maximum_length': 14,
    'y': '82%',
    'width': '81%',
    'height': '35%',
    'x_alignment': '50%',
    'y_alignment': '50%',
    'fill_color': '#ffffff',
    'stroke_color': '#000000',
    'stroke_width': '1.6 vmin',
    'font_family': 'Montserrat',
    'font_weight': '700',
    'font_size': '9.29 vmin',
    'background_color': 'rgba(216,216,216,0)',
    'background_x_padding': '31%',
    'background_y_padding': '17%',
    'background_border_radius': '31%'

response =
  # Find your API key under 'Project Settings' in your account:
  'Authorization': 'Bearer Your-API-Key',
  'Content-Type': 'application/json',

# Wait a minute, then visit the URL provided in the response:

Output Video

How it works: Creatomate is a simple yet powerful API that allows developers to create videos based on JSON instructions. Due to its REST interface, no infrastructure is required to process the videos; all you need is Python's "requests" library to use the API.

The API generates the transcribed video based on the JSON instructions provided by your Python application. In this example, we are providing two elements; a video and a text element.

Using the "source" attribute of the video element, we specify a video URL. We then specify the "transcript_source" attribute in the text element with the ID of the video element as the source. This will enable the auto-transcription on the specified video and use the text element to hold the captions.

All the other attributes are used to style, position, and animate the captions. This makes it highly customizable. For setting up a custom video template, try out the online video editor below to explore the different subtitle options.

Auto-transcription is just one of Creatomate's features. With its developer-driven approach, you can automate any video editing task to create dynamic videos, right from your Python apps. To get started, follow this quick tutorial or check out the API documentation.

Edit this Code Example in the Video Editor

Easily design your own video templates using the online editor. Then, export your templates as JSON and integrate them into your Python application to create any kind of video – completely through code.

Related Python Video Editing Questions

Start automating today

Start with a full-featured trial with 50 credits, no credit card required.
Get started for free