You can export your completed transcripts in SRT or VTT format, which can be used for subtitles and closed captions in videos. Once your transcript status shows as completed, you can make a request to the appropriate endpoint to export your transcript in SRT or VTT format.
In this Colab, we’ll walk through the process of generating subtitles for videos using the AssemblyAI API.
SRT (SubRip Text) files are commonly used to store subtitles for videos. The format is plain text, and it contains the timing information for each subtitle along with the subtitle text itself.
Here’s a breakdown of how the format works:
hours:minutes:seconds,milliseconds and are separated by -->.WEBVTT (Web Video Text Tracks), which is a standard format for displaying timed text tracks (such as subtitles or captions) within HTML5 video.
The syntax is similar to SRT but has some differences:
.) separating seconds and milliseconds instead of a comma (,).<track> element to add subtitles to a <video> element.If you’re planning to upload this file to YouTube, you should be able to use it just like an SRT file. YouTube supports various subtitle formats, including WEBVTT.
Before we begin, make sure you have an AssemblyAI account and an API key. You can sign up for a free account and get your API key from your dashboard.
The entire source code of this guide can be viewed here.
Install the SDK.
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.
Export SRT subtitles with the export_subtitles_srt method.
Export VTT subtitles with the export_subtitles_vtt method.
You can also customize the maximum number of characters per caption using the chars_per_caption URL parameter in your API requests to either the SRT or VTT endpoints. For example, adding ?chars_per_caption=32 to the SRT endpoint URL ensures that each caption has no more than 32 characters.
AssemblyAI can produce subtitles as both .srt and .vtt files. These are standard subtitle formats, and can be used with videos both on and off the web. For example, after generating your subtitle file, you can add it to a Mux video using their platform, or you can use ffmpeg to embed it in a local video file. Subtitle formats contain plain text, so you can import these formatted captions to most video editors, or fine-tune them as needed.