@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-generator2See 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 installUsage
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 startwords 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 trsultThis 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
- pnpm
- Node 20+
- Eslint
- TypeScript
Node version is set in node version manager .nvmrc
Build
npm run buildTests
This project uses Vitest for testing.
npm testTo run tests during development
npm run test:watchTODO
- [x] Open source
- [x] use import/export in modules
