Skip to content

A node module to generate subtitles by segmenting a list of time-coded text - BBC News Labs

Notifications You must be signed in to change notification settings

ddugovic/subtitles-generator

 
 

Repository files navigation

Subtitles Generator - draft

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

Exports to

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

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

Setup

git clone, cd into folder, npm install

Usage

const subtitlesComposer = require('./src/index.js');
// const sampleWords = // some word json 
const subtitlesJson = subtitlesComposer({words: sampleWords, type: 'json'})
const ttmlPremiere = subtitlesComposer({words: sampleWords, type: 'premiere'})
const ittData = subtitlesComposer({words: sampleWords, type: 'itt'})
const ttmlData = subtitlesComposer({words: sampleWords, type: 'ttml'})
const srtData = subtitlesComposer({words: sampleWords, type: 'srt'})
const vttData = subtitlesComposer({words: sampleWords, type: 'vtt'})

see example-usage.js for more comprehensive example.

To try locally

npx babel-node example-usage.js

words Input

  • either an array list of words objects
    example
const sampleWords =[ 
      {
        "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 = "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

Segmentation algorithm refactored from pietrop/subtitlesComposer originally by @polizoto. And subtitles generation in various originally format by @laurian and @maboaas part of BBC Subtitlelizer project.

Development env

Node version is set in node version manager .nvmrc

Build

npm run build

uses babel-cli to transpile ES6 into the ./build folder.

Tests

npm test

To run tests during development

npm run test:watch

Linting

To run linter

npm run lint

To run and fix

npm run lint:fix

Deployment

coming soon, deploying to npm registry as @bbc/subtitles-composer

npm run publish:public

TODO

  • Open source
  • use import/export in modules
  • add babel

About

A node module to generate subtitles by segmenting a list of time-coded text - BBC News Labs

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • JavaScript 100.0%