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

      Sunshine And March Vibes (2025 Wallpapers Edition)

      June 1, 2025

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

      June 1, 2025

      How To Fix Largest Contentful Paint Issues With Subpart Analysis

      June 1, 2025

      How To Prevent WordPress SQL Injection Attacks

      June 1, 2025

      7 MagSafe accessories that I recommend every iPhone user should have

      June 1, 2025

      I replaced my Kindle with an iPad Mini as my ebook reader – 8 reasons why I don’t regret it

      June 1, 2025

      Windows 11 version 25H2: Everything you need to know about Microsoft’s next OS release

      May 31, 2025

      Elden Ring Nightreign already has a duos Seamless Co-op mod from the creator of the beloved original, and it’ll be “expanded on in the future”

      May 31, 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

      Student Record Android App using SQLite

      June 1, 2025
      Recent

      Student Record Android App using SQLite

      June 1, 2025

      When Array uses less memory than Uint8Array (in V8)

      June 1, 2025

      Laravel 12 Starter Kits: Definite Guide Which to Choose

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

      Photobooth is photobooth software for the Raspberry Pi and PC

      June 1, 2025
      Recent

      Photobooth is photobooth software for the Raspberry Pi and PC

      June 1, 2025

      Le notizie minori del mondo GNU/Linux e dintorni della settimana nr 22/2025

      June 1, 2025

      Rilasciata PorteuX 2.1: Novità e Approfondimenti sulla Distribuzione GNU/Linux Portatile Basata su Slackware

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

    How to Create WebVTT Files for Videos in Node.js

    June 17, 2024

    WebVTT .vtt or Web Video Text Tracks Format is a widely used and supported format for subtitles in videos. This is what the first lines of the WebVTT file for this YouTube video look like:

    WEBVTT

    00:00.170 –> 00:04.234
    AssemblyAI is building AI systems to help you build AI applications

    00:04.282 –> 00:08.106
    with spoken data. We create superhuman AI models for speech

    In this guide, you’ll learn how to create WebVTT 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 vtt-subtitles
    cd vtt-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>

    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.

    Hostinger

    Add the following lines of JavaScript:

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

    3. Generate WebVTT file

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

    import { writeFile } from “fs/promises”

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

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

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

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

    WebVTT Subtitle Format

    SRT is another widely supported and popular subtitle format. To generate SRT, replace `”vtt”` with `”srt”`, and save the file with the srt-extension.

    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.vtt, which looks like this:

    WEBVTT

    00:00.200 –> 00:04.430
    AssemblyAI is building AI systems to help you build AI applications with

    00:04.462 –> 00:08.694
    spoken data. We create superhuman AI models for speech recognition,

    00:08.774 –> 00:13.062
    summarization, knowledge, augmentation of large language models with spoken

    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 ArticleGenerating audio for video
    Next Article How to Create SRT Files for Videos in Node.js

    Related Posts

    Artificial Intelligence

    Markus Buehler receives 2025 Washington Award

    June 1, 2025
    Artificial Intelligence

    LWiAI Podcast #201 – GPT 4.5, Sonnet 3.7, Grok 3, Phi 4

    June 1, 2025
    Leave A Reply Cancel Reply

    Continue Reading

    Securing the Future: Best Practices for Data Privacy in AI Projects🔐

    Web Development

    Fibbo – web-based game engine

    Linux

    6 first world Windows 11 problems I desperately want Microsoft to fix

    News & Updates

    Apple and Google Launch Cross-Platform Feature to Detect Unwanted Bluetooth Tracking Devices

    Development

    Highlights

    The power of play

    April 30, 2025

    When Designer Advocate Laura Fehre set out to design a digital nail salon, she had…

    Meta AI Proposes ‘Imagine yourself’: A State-of-the-Art Model for Personalized Image Generation without Subject-Specific Fine-Tuning

    August 22, 2024

    Snowflake Arctic, a New AI LLM for Enterprise Tasks, is Coming to APAC

    May 23, 2024

    CVE-2025-4745 – Apache Code-projects Employee Record System Cross-Site Scripting

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

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