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:
import requests
json = {
'source': {
'output_format': 'mp4',
'elements': [
{
'type': 'video',
'id': '17ca2169-786f-477f-aaea-4a2598bf24eb',
'source': 'https://cdn.creatomate.com/demo/the-daily-stoic-podcast.mp4'
},
{
'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 = requests.post(
'https://api.creatomate.com/v1/renders',
headers={
# Find your API key under 'Project Settings' in your account:
# https://creatomate.com/docs/api/rest-api/authentication
'Authorization': 'Bearer Your-API-Key',
'Content-Type': 'application/json',
},
json=json,
)
# Wait a minute, then visit the URL provided in the response:
print(response.json())
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.
We've also written a step-by-step tutorial on making videos with AI-generated voiceovers and matching subtitles. Even if you're looking to generate subtitles for other types of video or audio files, this guide is helpful for setting up a subtitle generation template.
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.