Create Custom Length Subtitles
While our SRT/VTT endpoints do allow you to customize the maximum number of characters per caption using the chars_per_caption URL parameter in your API requests, there are some use-cases that require a custom number of words in each subtitle.
In this guide, we will demonstrate how to construct these subtitles yourself in Python!
Quickstart
Step-by-Step Instructions
Import the assemblyai package and set the API key.
Create a Transcriber object.
Use the Transcriber object’s transcribe method and pass in the audio file’s path as a parameter. The transcribe method saves the results of the transcription to the Transcriber object’s transcript attribute.
Alternatively, you can pass in the URL of the publicly accessible audio file on the internet.
Define a function that converts seconds to timecodes
Define a function that iterates through the transcripts object to construct a list according to the number of words per subtitle
Generate your subtitle file