Skip to content

Voice-to-text dictation app with local (Nvidia Parakeet/Whisper) and cloud models (BYOK). Privacy-first and available cross-platform.

fix(export): roll SRT millisecond overflow into seconds (#1294)

Henry Su99698bd3e927
diff --git a/src/helpers/transcriptFormatter.js b/src/helpers/transcriptFormatter.js
index c4ecf2a17..ee4c8e9d5 100644
--- a/src/helpers/transcriptFormatter.js
+++ b/src/helpers/transcriptFormatter.js
@@ -40,8 +40,9 @@ function formatTimestamp(seconds) {
}
function formatSrtTimestamp(seconds) {
- const s = Math.floor(seconds);
- const ms = Math.round((seconds - s) * 1000);
+ const totalMs = Math.round(seconds * 1000);
+ const ms = totalMs % 1000;
+ const s = Math.floor(totalMs / 1000);
const h = Math.floor(s / 3600);
const m = Math.floor((s % 3600) / 60);
const sec = s % 60;
diff --git a/test/helpers/transcriptFormatter.test.js b/test/helpers/transcriptFormatter.test.js
index 50b66eb92..c18858f8d 100644
--- a/test/helpers/transcriptFormatter.test.js
+++ b/test/helpers/transcriptFormatter.test.js
@@ -88,6 +88,29 @@ test("the final merged SRT cue ends relative to its last segment, not its first"
assert.match(output, /^1\n00:00:00,000 --> 00:00:06,000\nSpeaker 1: One\. Two\. Three\./);
});
+test("SRT timestamps roll sub-second rounding into the next second", () => {
+ const output = formatSrt(
+ [{ speaker: "speaker_0", timestamp: 0.9995, text: "Near boundary." }],
+ {}
+ );
+
+ assert.match(output, /^1\n00:00:01,000 --> 00:00:04,000\nSpeaker 1: Near boundary\./);
+});
+
+test("every cue in a multi-cue SRT rolls its own sub-second rounding", () => {
+ const output = formatSrt(
+ [
+ { speaker: "speaker_0", timestamp: 0.9995, text: "Opening." },
+ { speaker: "speaker_1", timestamp: 1.9995, text: "Reply." },
+ ],
+ {}
+ );
+
+ assert.doesNotMatch(output, /,\d{4}/);
+ assert.match(output, /^1\n00:00:01,000 --> 00:00:02,000\nSpeaker 1: Opening\./);
+ assert.match(output, /\n2\n00:00:02,000 --> 00:00:05,000\nSpeaker 2: Reply\./);
+});
+
test("JSON duration reflects the last merged segment's timestamp", () => {
const output = formatJson(
{ title: "Note", created_at: "2026-01-01T00:00:00Z" },