npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

@mythli/subtitles-generator2

v1.0.10

Published

A node module to generate subtitles by segmenting a list of time-coded text.

Readme

Subtitles Generator

A node module to generate subtitles by segmenting a list of time-coded text.

Exports to

  • [x] TTML for Premiere as .xml
  • [x] TTML
  • [x] iTT - for Apple
  • [x] srt
  • [x] vtt
  • [x] csv
  • [x] txt - pre-segmented text

It can also provide pre-segmented lines if the input is plain text.

Getting Started

Install from npm:

npm install @mythli/subtitles-generator2

See the package on npm: https://www.npmjs.com/package/@mythli/subtitles-generator2

For local development

Clone the repository and install dependencies:

git clone https://github.com/Mythli/subtitles-generator.git
cd subtitles-generator
pnpm install

Usage

import subtitlesGenerator, { Word } from '@mythli/subtitles-generator2';

// const sampleWords: Word[] = // some word json 
const subtitlesJson = subtitlesGenerator({words: sampleWords, type: 'json'})
const ttmlPremiere = subtitlesGenerator({words: sampleWords, type: 'premiere'})
const ittData = subtitlesGenerator({words: sampleWords, type: 'itt'})
const ttmlData = subtitlesGenerator({words: sampleWords, type: 'ttml'})
const srtData = subtitlesGenerator({words: sampleWords, type: 'srt'})
const vttData = subtitlesGenerator({words: sampleWords, type: 'vtt'})

see example-usage.ts for a more comprehensive example.

To try locally:

pnpm start

words Input

  • either an array list of words objects (Word[]) example
import { Word } from '@mythli/subtitles-generator2';

const sampleWords: Word[] = [ 
      {
        "id": 0,
        "start": 13.02,
        "end": 13.17,
        "text": "There"
      },
      {
        "id": 1,
        "start": 13.17,
        "end": 13.38,
        "text": "is"
      },
      {
        "id": 2,
        "start": 13.38,
        "end": 13.44,
        "text": "a"
      },
      {
        "id": 3,
        "start": 13.44,
        "end": 13.86,
        "text": "day."
      },
...
  • or a string of text
    Example
const sampleWords: string = "There is a day. ...";

If input words is plain text only (and not a list of words with timecodes) then can only use pre-segment-txt option. (see test-presegment.txt for example)

Output:

see example-output folder for examples.

System Architecture

In pseudo code, at a high level

// expecting array list of words OR plain text string

  // if array list of words, convert text into string

  // presegment the text 
     using pre segmentation algorithm to break into line of x char - default 35

// generate subtitles 
   use subtitles generators for various format to convert presegemented json into subtitles

// return trsult

This project is a fork of the original BBC Subtitlelizer project. It has been updated with modern dependencies, converted to TypeScript, and uses Vitest for testing.

The original segmentation algorithm was refactored from pietrop/subtitlesComposer by @polizoto. Subtitles generation in various formats was originally by @laurian and @maboa.

Development env

Node version is set in node version manager .nvmrc

Build

npm run build

Tests

This project uses Vitest for testing.

npm test

To run tests during development

npm run test:watch

TODO

  • [x] Open source
  • [x] use import/export in modules