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.
git clone, cd into folder, npm install
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
- 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)
see example-output
folder for examples.
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 @maboa
as part of BBC Subtitlelizer project.
- npm >
6.1.0
- Node 10 - dubnium
- Eslint
- Babel
Node version is set in node version manager .nvmrc
npm run build
uses babel-cli to transpile ES6 into the ./build
folder.
npm test
To run tests during development
npm run test:watch
To run linter
npm run lint
To run and fix
npm run lint:fix
coming soon, deploying to npm registry as @bbc/subtitles-composer
npm run publish:public
- Open source
- use import/export in modules
- add babel