vtt-utils is a library for handling VTT subtitles within voiceful. It includes different functions to import and parse subtitles, as well as to export them for voiceful in the appropriate format.
npm i -S vtt-utils
node-webvtt (Voctro Labs fork)
var vttutils = require('vtt-utils');
Generates a VTT-formatted subtitle from a SRT text
/**
* @param {String} inputSrtText Input subtitle text, in SRT format
* @return {String} Output subtitle text, in VTT format
*/
Parses an input subtitle provided as text and output the subtitle with sentence per cue. When several cues are joined into a single one, this function automatically adds <prosody duration>
SSML tags to keep the original time info, in milliseconds (e.g. <prosody duration="1000ms">
for 1 second). When two non-adjacent cues are joined (i.e. the ending time of the first is not equal to the start time of the second), it adds SSML <break>
SSML tags to keep this info (e.g. <break time="1000ms">
) for cues separated by 1 second.
/**
* @param {String} inputVttText Input subtitle text, in VTT format
* @return {String} Output subtitle text, in VTT format
*/
Checks that the start and end times of cues in two VTT subtitles are equal
/**
* @param {String} srcVttText Source subtitle text, in VTT format
* @param {String} targetVttText Target subtitle text, in VTT format
* @return {Boolean} True if both are equivalent, false otherwise
*/
Assigns a style to the cue in position cueIdx for the VTT-formatted subtitle inputVttText by adding a <emphasis level="style">
tag to the cue.
/**
* @param {String} inputVttText Input subtitle text, in VTT format
* @param {String} style Name of the style for the cue (e.g: 'neutral', 'sad', 'aggresive'...)
* @param {Number} cueIdx Index of the cue where the style must be applied
* @return {String} inputVttText modified
*/
Returns the different speakers present in the VTT formated subtitle vttText, looking at the voice (<v>
) tags in the cues.
/**
* @param {String} vttText Subtitle text, in VTT format
* @return {String[]} Array of speakers
*/
Generates JSON-formatted to generate synthesis with voiceful.
/**
* @param {String} language Language identifier
* @param {String} modelsString Array with speakers-voice models-(optional)defaultStyle correspondence (e.g. '[["speaker1","model1","style1"],["speaker2","model2"]]')
* @param {String} vttText Subtitle text, in VTT format
* @param {Number[]} selectedSentences Array with indexes of sentences to be synthesized
* @return {String} JSON-formatted string for synthesis
*/
Return the text of a cue without speaker tag
/**
* @param {String} cueText Text from a sentence of a subtitle
* @return {String} cueText without the speaker tag
*/
Return the text of a cue without any tags
/**
* @param {String} cueText Text from a sentence of a subtitle
* @return {String} cueText without tags
*/
Return noise gate values as string to introduce in VoMix effect
/**
* @param {String} vttText Subtitle text, in VTT format
* @param {Number} transitionTime Transition time, in seconds
* @return {String} Noise gate values as string to introduce in JSON
*/
Returns the number of cues in the vtt subtitle vttText
/**
* @param {String} vttText Subtitle text, in VTT format
* @return {Number} Number of cues
*/
Returns the subtitle with cues short enough that they are readable together with video. It <prosody duration>
tags are present, the function uses this information. Otherwise, it returns a subtitle with cues shorter than 70 characters.
/**
* @param {String} vttText Subtitle text, in VTT format
* @return {String} Video-friendly subtitle, in VTT format
*/
To start developing first clone de repository and install the dependencies with NPM:
git clone git@github.com:VoctroLabs/vtt-utils.git
cd vtt-utils
npm install
There is an example of usage in example/index.html
.
First run the following commands to produce the necessary bundle for the browser:
npm run build-example
Then open example/index.html
in your browser.
Run tests with:
npm run test