How to Auto-Generate Subtitles using Node.js?

With auto-transcription, you can automatically generate subtitles for any video or audio file. This is an automated process in which captions are generated using speech-to-text AI, which identifies spoken words and turns them into animated subtitles. Here's how to do it in your Node.js app using a few lines of JavaScript:

Input Code
const Creatomate = require('creatomate');
const client = new Creatomate.Client('Your API Key');

  source: new Creatomate.Source({
    outputFormat: 'mp4',
    elements: [

      new Creatomate.Video({
        id: '17ca2169-786f-477f-aaea-4a2598bf24eb',
        source: '',

      new Creatomate.Text({
        transcriptSource: '17ca2169-786f-477f-aaea-4a2598bf24eb',
        transcriptEffect: 'highlight',
        transcriptMaximumLength: 14,
        y: '82%',
        width: '81%',
        height: '35%',
        xAlignment: '50%',
        yAlignment: '50%',
        fillColor: '#ffffff',
        strokeColor: '#000000',
        strokeWidth: '1.6 vmin',
        fontFamily: 'Montserrat',
        fontWeight: '700',
        fontSize: '9.29 vmin',
        backgroundColor: 'rgba(216,216,216,0)',
        backgroundXPadding: '31%',
        backgroundYPadding: '17%',
        backgroundBorderRadius: '31%',

}).then((renders) => {
Output Video

How it works: As a first step, install the Creatomate package from NPM, which allows you to edit video directly from your Node.js code. With this package, we get a straightforward way to use Creatomate's video API; the video is made with just one call to "render".

In the JSON object we pass to the "render" function, we tell the API how to make the subtitled video. In this case, we're using two elements: a video element and a text element.

The "source" parameter points to an MP4 clip for which subtitles should be generated. As a next step, we add a text element that will contain the auto-generated captions. With the "transcriptSource" parameter, we can specify the video element's ID so that the API uses that as the basis for creating captions.

The remaining attributes are used to style, position, and animate the captions. In terms of customization, you can pick from many different subtitle styles. The easiest way to explore the different caption attributes is using the video editor below.

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 JavaScript 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 Node.js application to create any kind of video – completely through code.

Related Node.js Video Editing Questions

Start automating today

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