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

@voctrolabs/vtt-utils

v0.11.4

Published

Utils for handling VTT subtitles

Readme

vtt-utils

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.

Install

npm i -S vtt-utils

Dependencies

node-webvtt (Voctro Labs fork)

Usage

Importing the library

var vttutils = require('vtt-utils');

API

srtToVtt(inputSrtText)

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
 */

parseToSentences(inputVttText)

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
*/

checkSubtitlesEquivalency(srcVttText, targetVttText)

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
*/

assignStyleToCue(inputVttText, style, cueIdx)

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
 */

getSpeakers(vttText)

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
 */

getAsJSON(language, modelsString, vttText)

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
*/

removeSpeaker(cueText)

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
 */

removeTags(cueText)

Return the text of a cue without any tags

/**
 * @param  {String} cueText Text from a sentence of a subtitle
 * @return {String}              cueText without tags
 */

generateNoiseGateString(vttText, transitionTime)

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
 */

getNumberOfCues(vttText)

Returns the number of cues in the vtt subtitle vttText

/**
* @param  {String} vttText Subtitle text, in VTT format
* @return {Number}         Number of cues
*/

getVideoFriendlyVtt(vttText)

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
*/

Development

To start developing first clone de repository and install the dependencies with NPM:

git clone [email protected]:VoctroLabs/vtt-utils.git
cd vtt-utils
npm install

Example

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.

Tests

Run tests with:

npm run test

License

MIT