Close Menu
    DevStackTipsDevStackTips
    • Home
    • News & Updates
      1. Tech & Work
      2. View All

      Sunshine And March Vibes (2025 Wallpapers Edition)

      May 16, 2025

      The Case For Minimal WordPress Setups: A Contrarian View On Theme Frameworks

      May 16, 2025

      How To Fix Largest Contentful Paint Issues With Subpart Analysis

      May 16, 2025

      How To Prevent WordPress SQL Injection Attacks

      May 16, 2025

      Microsoft has closed its “Experience Center” store in Sydney, Australia — as it ramps up a continued digital growth campaign

      May 16, 2025

      Bing Search APIs to be “decommissioned completely” as Microsoft urges developers to use its Azure agentic AI alternative

      May 16, 2025

      Microsoft might kill the Surface Laptop Studio as production is quietly halted

      May 16, 2025

      Minecraft licensing robbed us of this controversial NFL schedule release video

      May 16, 2025
    • Development
      1. Algorithms & Data Structures
      2. Artificial Intelligence
      3. Back-End Development
      4. Databases
      5. Front-End Development
      6. Libraries & Frameworks
      7. Machine Learning
      8. Security
      9. Software Engineering
      10. Tools & IDEs
      11. Web Design
      12. Web Development
      13. Web Security
      14. Programming Languages
        • PHP
        • JavaScript
      Featured

      The power of generators

      May 16, 2025
      Recent

      The power of generators

      May 16, 2025

      Simplify Factory Associations with Laravel’s UseFactory Attribute

      May 16, 2025

      This Week in Laravel: React Native, PhpStorm Junie, and more

      May 16, 2025
    • Operating Systems
      1. Windows
      2. Linux
      3. macOS
      Featured

      Microsoft has closed its “Experience Center” store in Sydney, Australia — as it ramps up a continued digital growth campaign

      May 16, 2025
      Recent

      Microsoft has closed its “Experience Center” store in Sydney, Australia — as it ramps up a continued digital growth campaign

      May 16, 2025

      Bing Search APIs to be “decommissioned completely” as Microsoft urges developers to use its Azure agentic AI alternative

      May 16, 2025

      Microsoft might kill the Surface Laptop Studio as production is quietly halted

      May 16, 2025
    • Learning Resources
      • Books
      • Cheatsheets
      • Tutorials & Guides
    Home»Development»Artificial Intelligence»How to Create SRT Files for Videos in Node.js

    How to Create SRT Files for Videos in Node.js

    June 17, 2024

    SRT .srt is a widely used and supported format for subtitles in videos.
    This is what the first lines of the SRT file for this YouTube video look like:

    1
    00:00:00,170 –> 00:00:04,234
    AssemblyAI is building AI systems to help you build AI applications

    2
    00:00:04,282 –> 00:00:08,106
    with spoken data. We create superhuman AI models for speech

    In this guide, you’ll learn how to create SRT files for videos using Node.js and the AssemblyAI API.

    Step 1: Set up your development environment

    First, install Node.js 18 or higher on your system.
    Next, create a new project folder, change directories to it, and initialize a new Node.js project:

    mkdir srt-subtitles
    cd srt-subtitles
    npm init -y

    Open the package.json file and add type: “module”, to the list of properties.

    {
    …
    “type”: “module”,
    …
    }

    This will tell Node.js to use the ES Module syntax for exporting and importing modules, and not to use the old CommonJS syntax.

    Then, install the AssemblyAI JavaScript SDK which makes it easier to interact with the AssemblyAI API:

    npm install –save assemblyai

    Next, you need an AssemblyAI API key that you can find on your dashboard. If you don’t have an AssemblyAI account, first sign up for free. Once you’ve copied your API key, configure it as the ASSEMBLYAI_API_KEY environment variable on your machine:

    # Mac/Linux:
    export ASSEMBLYAI_API_KEY=<YOUR_KEY>

    # Windows:
    set ASSEMBLYAI_API_KEY=<YOUR_KEY>

    Step 2. Transcribe your video

    Now that your development environment is ready, you can start transcribing your video files. In this tutorial, you’ll use this video in MP4 format. The AssemblyAI SDK can transcribe any audio or video file that’s publicly accessible via a URL, but you can also specify local files. Create a file called index.js and add the following code:

    import { AssemblyAI } from ‘assemblyai’;

    // create AssemblyAI API client
    const client = new AssemblyAI({ apiKey: process.env.ASSEMBLYAI_API_KEY });

    // transcribe audio or video file
    const transcript = await client.transcripts.transcribe({
    audio: “https://storage.googleapis.com/aai-web-samples/aai-overview.mp4”,
    });

    If the transcription is successful, the transcript object will be populated with the transcript text and many additional properties. However, you should verify whether an error occurred and log the error.

    Add the following lines of JavaScript:

    // throw error if transcript status is error
    if (transcript.status === “error”) {
    throw new Error(transcript.error);
    }

    Step 3. Generate SRT file

    Now that you have a transcript, you can generate the subtitles in SRT format.
    Add the following import which you’ll need to save the SRT file to disk.

    import { writeFile } from “fs/promises”

    Then add the following code to generate the SRT subtitles from the transcript and download the SRT file to disk.

    // generate SRT subtitles
    const srt = await client.transcripts.subtitles(transcript.id, “srt”);
    await writeFile(“./subtitles.srt”, srt);

    You can customize the maximum number of characters per caption by specifying the third parameter (chars_per_caption).

    // generate SRT subtitles
    const srt = await client.transcripts.subtitles(transcript.id, “srt”, 32);
    await writeFile(“./subtitles.srt”, srt);

    WebVTT Subtitle Format

    WebVTT file or Web Video Text to Track File is another widely supported and popular subtitle format. To generate WebVTT, replace “srt” with “vtt”, and save the file with the vtt-extension.

    Step 4. Run the script

    To run the script, go back to your shell and run:

    node index.js

    After a couple of seconds, you’ll see a new file on disk subtitles.srt, which looks like this:

    1
    00:00:00,200 –> 00:00:03,438
    AssemblyAI is building AI systems to help you build AI

    2
    00:00:03,486 –> 00:00:06,838
    applications with spoken data. We create superhuman

    3
    00:00:06,886 –> 00:00:09,806
    AI models for speech recognition, summarization,

    Next steps

    Now that you have your subtitle file, you can configure it in your video player, or if you’re creating a YouTube video, upload it to YouTube Studio. You can also use other tools to bundle or even burn the subtitles into your video.

    Check out our Audio Intelligence models and LeMUR to add even more capabilities to your audio and video applications.

    Alternatively, feel free to check out our blog or YouTube channel for educational content on AI and Machine Learning, or feel free to join us on Twitter or Discord to stay in the loop when we release new content.

    Source: Read More 

    Facebook Twitter Reddit Email Copy Link
    Previous ArticleHow to Create WebVTT Files for Videos in Node.js
    Next Article How to send large files in Gmail – up to 10GB

    Related Posts

    Security

    Nmap 7.96 Launches with Lightning-Fast DNS and 612 Scripts

    May 16, 2025
    Common Vulnerabilities and Exposures (CVEs)

    CVE-2025-47916 – Invision Community Themeeditor Remote Code Execution

    May 16, 2025
    Leave A Reply Cancel Reply

    Continue Reading

    Boosting Queue Management with Laravel’s JobQueueing Event

    Development

    mult runs a command multiple times

    Linux

    Distribution Release: Clonezilla Live 3.2.1-9

    News & Updates

    How to Recover Lost Web Design Files After a Crash or Mistake

    Web Development

    Highlights

    News & Updates

    Game Pass carried Xbox with record revenue and huge subscriber gains last quarter

    January 30, 2025

    The effect of Black Ops 6 resonates across platform services with record growth. Source: Read…

    Claude AI can do your research and handle your emails now – here’s how

    April 16, 2025

    Neptune is a Linux distribution built upon Debian Stable

    April 25, 2025

    CVE-2024-13344 – WooCommerce Advance Seat Reservation SQL Injection

    May 2, 2025
    © DevStackTips 2025. All rights reserved.
    • Contact
    • Privacy Policy

    Type above and press Enter to search. Press Esc to cancel.