Package Exports
- subchunk
- subchunk/dist/index.js
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (subchunk) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
subchunk
Convert ElevenLabs transcript JSON into clean, readable subtitles (.srt / .vtt).
π¨ Problem
ElevenLabs provides SRT exports, but they often look like this:
1
00:00:00,000 --> 00:00:05,000
This is a very long subtitle line that contains too many words and is hard to read quickly.β Issues:
- Subtitles are too long
- Poor readability
- Weak alignment with speech timing
- Not optimized for modern content (Reels, Shorts, YouTube)
β Solution
ElevenLabs JSON includes word-level timestamps β this tool uses that to generate high-quality subtitles:
β Short, readable chunks
β Pause-aware timing
β Smart sentence splitting
β Multi-line subtitles (2 lines max)
β Speaker labels (optional)
β .srt and .vtt support
β¨ Example Output
1
00:00:00,460 --> 00:00:01,160
Three minutes.
2
00:00:01,200 --> 00:00:02,400
Thatβs all it takes
to get started.βοΈ Features
π― Smart chunking (punctuation + pauses + word limits)
π§ Human-friendly subtitle splitting
πͺΆ Lightweight & fast (Bun-powered)
π¬ Presets for different content styles:
reels(short captions)youtubepodcast
π£ Speaker labels support
π Multiple formats (
.srt,.vtt)π‘ Robust error handling
π¦ Installation
npm install subchunk
# or
yarn add subchunk
# or
bun add subchunkπ» Usage
subchunk is a pure function that processes ElevenLabs JSON directly. It has no file-system dependencies, making it perfect for both Node.js/Bun environments and the browser!
import { convertElevenlabsJsonToSubtitle } from "subchunk";
// 1. Pass the parsed JSON object directly
const elevenLabsData = {
segments: [
{
text: "Hello world",
words: [
{ text: "Hello", start: 0.1, end: 0.5, type: "word" },
{ text: "world", start: 0.5, end: 1.0, type: "word" }
]
}
]
};
const srtOutput = convertElevenlabsJsonToSubtitle(elevenLabsData, {
format: "srt",
preset: "reels"
});
console.log(srtOutput);
// 2. Or pass a raw JSON string
const jsonString = JSON.stringify(elevenLabsData);
const vttOutput = convertElevenlabsJsonToSubtitle(jsonString, {
format: "vtt",
speaker: true,
maxWords: 5,
gap: 0.8
});π§ Options
| Option | Type | Default | Description |
|---|---|---|---|
format |
"srt" | "vtt" |
"srt" |
Subtitle format type |
maxWords |
number |
8 |
Max words per subtitle |
gap |
number |
0.8 |
Pause threshold (seconds) |
speaker |
boolean |
false |
Include speaker labels |
preset |
"reels" | "youtube" | "podcast" |
β | Pre-configured chunking rules |
π― Presets
| Preset | Use Case | Behavior |
|---|---|---|
reels |
Shorts / TikTok | Very short captions (max 5 words, 0.4s gap) |
youtube |
General videos | Balanced (max 8 words, 0.8s gap) |
podcast |
Long conversations | Longer subtitles (max 12 words, 1.0s gap) |
π Input Format (ElevenLabs JSON)
{
"segments": [
{
"text": "Three minutes.",
"words": [
{
"text": "Three",
"start": 0.46,
"end": 0.66,
"type": "word"
}
]
}
]
}π§ How It Works
- Extracts words from
segments[].words[] - Detects:
- sentence endings (
. ? !) - pauses in speech
- word limits
- sentence endings (
- Groups words into natural subtitle chunks
- Formats and returns the
.srtor.vttraw string
π― Why This Matters
Good subtitles are critical for:
- Viewer retention π
- Accessibility βΏ
- Mobile-first content π±
This tool helps you generate modern, readable captions instead of outdated long blocks.
π License
MIT