@storyteller-platform/ghost-story 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (135) hide show
  1. package/LICENSE.md +611 -0
  2. package/README.md +18 -0
  3. package/dist/api/APIOptions.cjs +16 -0
  4. package/dist/api/APIOptions.d.cts +18 -0
  5. package/dist/api/APIOptions.d.ts +18 -0
  6. package/dist/api/APIOptions.js +0 -0
  7. package/dist/api/Recognition.cjs +263 -0
  8. package/dist/api/Recognition.d.cts +77 -0
  9. package/dist/api/Recognition.d.ts +77 -0
  10. package/dist/api/Recognition.js +233 -0
  11. package/dist/api/VoiceActivityDetection.cjs +77 -0
  12. package/dist/api/VoiceActivityDetection.d.cts +24 -0
  13. package/dist/api/VoiceActivityDetection.d.ts +24 -0
  14. package/dist/api/VoiceActivityDetection.js +43 -0
  15. package/dist/audio/AudioConverter.cjs +331 -0
  16. package/dist/audio/AudioConverter.d.cts +53 -0
  17. package/dist/audio/AudioConverter.d.ts +53 -0
  18. package/dist/audio/AudioConverter.js +310 -0
  19. package/dist/audio/AudioFormat.cjs +151 -0
  20. package/dist/audio/AudioFormat.d.cts +25 -0
  21. package/dist/audio/AudioFormat.d.ts +25 -0
  22. package/dist/audio/AudioFormat.js +123 -0
  23. package/dist/audio/AudioSource.cjs +119 -0
  24. package/dist/audio/AudioSource.d.cts +33 -0
  25. package/dist/audio/AudioSource.d.ts +33 -0
  26. package/dist/audio/AudioSource.js +88 -0
  27. package/dist/audio/index.cjs +74 -0
  28. package/dist/audio/index.d.cts +6 -0
  29. package/dist/audio/index.d.ts +6 -0
  30. package/dist/audio/index.js +54 -0
  31. package/dist/cli/bin.cjs +277 -0
  32. package/dist/cli/bin.d.cts +1 -0
  33. package/dist/cli/bin.d.ts +1 -0
  34. package/dist/cli/bin.js +275 -0
  35. package/dist/cli/config.cjs +347 -0
  36. package/dist/cli/config.d.cts +33 -0
  37. package/dist/cli/config.d.ts +33 -0
  38. package/dist/cli/config.js +285 -0
  39. package/dist/cli/install.cjs +334 -0
  40. package/dist/cli/install.d.cts +62 -0
  41. package/dist/cli/install.d.ts +62 -0
  42. package/dist/cli/install.js +316 -0
  43. package/dist/cli/whisper-server.cjs +172 -0
  44. package/dist/cli/whisper-server.d.cts +24 -0
  45. package/dist/cli/whisper-server.d.ts +24 -0
  46. package/dist/cli/whisper-server.js +152 -0
  47. package/dist/config.cjs +60 -0
  48. package/dist/config.d.cts +12 -0
  49. package/dist/config.d.ts +12 -0
  50. package/dist/config.js +32 -0
  51. package/dist/convert.cjs +88 -0
  52. package/dist/convert.d.cts +12 -0
  53. package/dist/convert.d.ts +12 -0
  54. package/dist/convert.js +63 -0
  55. package/dist/encodings/Ascii.cjs +75 -0
  56. package/dist/encodings/Ascii.d.cts +13 -0
  57. package/dist/encodings/Ascii.d.ts +13 -0
  58. package/dist/encodings/Ascii.js +48 -0
  59. package/dist/encodings/Base64.cjs +155 -0
  60. package/dist/encodings/Base64.d.cts +5 -0
  61. package/dist/encodings/Base64.d.ts +5 -0
  62. package/dist/encodings/Base64.js +129 -0
  63. package/dist/encodings/TextEncodingsCommon.cjs +16 -0
  64. package/dist/encodings/TextEncodingsCommon.d.cts +6 -0
  65. package/dist/encodings/TextEncodingsCommon.d.ts +6 -0
  66. package/dist/encodings/TextEncodingsCommon.js +0 -0
  67. package/dist/index.cjs +153 -0
  68. package/dist/index.d.cts +15 -0
  69. package/dist/index.d.ts +15 -0
  70. package/dist/index.js +140 -0
  71. package/dist/recognition/AmazonTranscribeSTT.cjs +188 -0
  72. package/dist/recognition/AmazonTranscribeSTT.d.cts +21 -0
  73. package/dist/recognition/AmazonTranscribeSTT.d.ts +21 -0
  74. package/dist/recognition/AmazonTranscribeSTT.js +160 -0
  75. package/dist/recognition/AzureCognitiveServicesSTT.cjs +124 -0
  76. package/dist/recognition/AzureCognitiveServicesSTT.d.cts +21 -0
  77. package/dist/recognition/AzureCognitiveServicesSTT.d.ts +21 -0
  78. package/dist/recognition/AzureCognitiveServicesSTT.js +95 -0
  79. package/dist/recognition/DeepgramSTT.cjs +172 -0
  80. package/dist/recognition/DeepgramSTT.d.cts +23 -0
  81. package/dist/recognition/DeepgramSTT.d.ts +23 -0
  82. package/dist/recognition/DeepgramSTT.js +153 -0
  83. package/dist/recognition/GoogleCloudSTT.cjs +125 -0
  84. package/dist/recognition/GoogleCloudSTT.d.cts +35 -0
  85. package/dist/recognition/GoogleCloudSTT.d.ts +35 -0
  86. package/dist/recognition/GoogleCloudSTT.js +107 -0
  87. package/dist/recognition/OpenAICloudSTT.cjs +180 -0
  88. package/dist/recognition/OpenAICloudSTT.d.cts +29 -0
  89. package/dist/recognition/OpenAICloudSTT.d.ts +29 -0
  90. package/dist/recognition/OpenAICloudSTT.js +150 -0
  91. package/dist/recognition/WhisperCppSTT.cjs +296 -0
  92. package/dist/recognition/WhisperCppSTT.d.cts +40 -0
  93. package/dist/recognition/WhisperCppSTT.d.ts +40 -0
  94. package/dist/recognition/WhisperCppSTT.js +275 -0
  95. package/dist/recognition/WhisperServerSTT.cjs +119 -0
  96. package/dist/recognition/WhisperServerSTT.d.cts +24 -0
  97. package/dist/recognition/WhisperServerSTT.d.ts +24 -0
  98. package/dist/recognition/WhisperServerSTT.js +105 -0
  99. package/dist/utilities/FileSystem.cjs +54 -0
  100. package/dist/utilities/FileSystem.d.cts +3 -0
  101. package/dist/utilities/FileSystem.d.ts +3 -0
  102. package/dist/utilities/FileSystem.js +20 -0
  103. package/dist/utilities/Locale.cjs +46 -0
  104. package/dist/utilities/Locale.d.cts +9 -0
  105. package/dist/utilities/Locale.d.ts +9 -0
  106. package/dist/utilities/Locale.js +20 -0
  107. package/dist/utilities/ObjectUtilities.cjs +41 -0
  108. package/dist/utilities/ObjectUtilities.d.cts +3 -0
  109. package/dist/utilities/ObjectUtilities.d.ts +3 -0
  110. package/dist/utilities/ObjectUtilities.js +7 -0
  111. package/dist/utilities/Timeline.cjs +120 -0
  112. package/dist/utilities/Timeline.d.cts +23 -0
  113. package/dist/utilities/Timeline.d.ts +23 -0
  114. package/dist/utilities/Timeline.js +94 -0
  115. package/dist/utilities/Timing.cjs +287 -0
  116. package/dist/utilities/Timing.d.cts +64 -0
  117. package/dist/utilities/Timing.d.ts +64 -0
  118. package/dist/utilities/Timing.js +256 -0
  119. package/dist/utilities/WhisperTimeline.cjs +344 -0
  120. package/dist/utilities/WhisperTimeline.d.cts +86 -0
  121. package/dist/utilities/WhisperTimeline.d.ts +86 -0
  122. package/dist/utilities/WhisperTimeline.js +313 -0
  123. package/dist/vad/ActiveGate.cjs +357 -0
  124. package/dist/vad/ActiveGate.d.cts +53 -0
  125. package/dist/vad/ActiveGate.d.ts +53 -0
  126. package/dist/vad/ActiveGate.js +329 -0
  127. package/dist/vad/ActiveGateOg.cjs +1366 -0
  128. package/dist/vad/ActiveGateOg.d.cts +33 -0
  129. package/dist/vad/ActiveGateOg.d.ts +33 -0
  130. package/dist/vad/ActiveGateOg.js +1341 -0
  131. package/dist/vad/Silero.cjs +174 -0
  132. package/dist/vad/Silero.d.cts +25 -0
  133. package/dist/vad/Silero.d.ts +25 -0
  134. package/dist/vad/Silero.js +153 -0
  135. package/package.json +125 -0
@@ -0,0 +1,54 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+ var FileSystem_exports = {};
30
+ __export(FileSystem_exports, {
31
+ getAppDataDir: () => getAppDataDir
32
+ });
33
+ module.exports = __toCommonJS(FileSystem_exports);
34
+ var os = __toESM(require("node:os"), 1);
35
+ var import_node_path = require("node:path");
36
+ function getAppDataDir(appName) {
37
+ let dataDir;
38
+ const platform = process.platform;
39
+ const homeDir = os.homedir();
40
+ if (platform === "win32") {
41
+ dataDir = (0, import_node_path.join)(homeDir, "AppData", "Local", appName);
42
+ } else if (platform === "darwin") {
43
+ dataDir = (0, import_node_path.join)(homeDir, "Library", "Application Support", appName);
44
+ } else if (platform === "linux") {
45
+ dataDir = (0, import_node_path.join)(homeDir, ".local", "share", appName);
46
+ } else {
47
+ throw new Error(`Unsupport platform ${platform}`);
48
+ }
49
+ return dataDir;
50
+ }
51
+ // Annotate the CommonJS export names for ESM import in node:
52
+ 0 && (module.exports = {
53
+ getAppDataDir
54
+ });
@@ -0,0 +1,3 @@
1
+ declare function getAppDataDir(appName: string): string;
2
+
3
+ export { getAppDataDir };
@@ -0,0 +1,3 @@
1
+ declare function getAppDataDir(appName: string): string;
2
+
3
+ export { getAppDataDir };
@@ -0,0 +1,20 @@
1
+ import * as os from "node:os";
2
+ import { join } from "node:path";
3
+ function getAppDataDir(appName) {
4
+ let dataDir;
5
+ const platform = process.platform;
6
+ const homeDir = os.homedir();
7
+ if (platform === "win32") {
8
+ dataDir = join(homeDir, "AppData", "Local", appName);
9
+ } else if (platform === "darwin") {
10
+ dataDir = join(homeDir, "Library", "Application Support", appName);
11
+ } else if (platform === "linux") {
12
+ dataDir = join(homeDir, ".local", "share", appName);
13
+ } else {
14
+ throw new Error(`Unsupport platform ${platform}`);
15
+ }
16
+ return dataDir;
17
+ }
18
+ export {
19
+ getAppDataDir
20
+ };
@@ -0,0 +1,46 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var Locale_exports = {};
20
+ __export(Locale_exports, {
21
+ formatLanguageCodeWithName: () => formatLanguageCodeWithName,
22
+ getShortLanguageCode: () => getShortLanguageCode,
23
+ languageCodeToName: () => languageCodeToName
24
+ });
25
+ module.exports = __toCommonJS(Locale_exports);
26
+ function languageCodeToName(languageCode) {
27
+ const languageNames = new Intl.DisplayNames(["en"], { type: "language" });
28
+ try {
29
+ return languageNames.of(languageCode) ?? "Unknown";
30
+ } catch {
31
+ return "Unknown";
32
+ }
33
+ }
34
+ function formatLanguageCodeWithName(languageCode) {
35
+ return `${languageCodeToName(languageCode)} (${languageCode})`;
36
+ }
37
+ function getShortLanguageCode(langCode) {
38
+ const dashIndex = langCode.indexOf("-");
39
+ return dashIndex === -1 ? langCode : langCode.substring(0, dashIndex).toLowerCase();
40
+ }
41
+ // Annotate the CommonJS export names for ESM import in node:
42
+ 0 && (module.exports = {
43
+ formatLanguageCodeWithName,
44
+ getShortLanguageCode,
45
+ languageCodeToName
46
+ });
@@ -0,0 +1,9 @@
1
+ declare function languageCodeToName(languageCode: string): string;
2
+ declare function formatLanguageCodeWithName(languageCode: string): string;
3
+ declare function getShortLanguageCode(langCode: string): string;
4
+ interface LangInfo {
5
+ Name: string;
6
+ TwoLetterISOLanguageName: string;
7
+ }
8
+
9
+ export { type LangInfo, formatLanguageCodeWithName, getShortLanguageCode, languageCodeToName };
@@ -0,0 +1,9 @@
1
+ declare function languageCodeToName(languageCode: string): string;
2
+ declare function formatLanguageCodeWithName(languageCode: string): string;
3
+ declare function getShortLanguageCode(langCode: string): string;
4
+ interface LangInfo {
5
+ Name: string;
6
+ TwoLetterISOLanguageName: string;
7
+ }
8
+
9
+ export { type LangInfo, formatLanguageCodeWithName, getShortLanguageCode, languageCodeToName };
@@ -0,0 +1,20 @@
1
+ function languageCodeToName(languageCode) {
2
+ const languageNames = new Intl.DisplayNames(["en"], { type: "language" });
3
+ try {
4
+ return languageNames.of(languageCode) ?? "Unknown";
5
+ } catch {
6
+ return "Unknown";
7
+ }
8
+ }
9
+ function formatLanguageCodeWithName(languageCode) {
10
+ return `${languageCodeToName(languageCode)} (${languageCode})`;
11
+ }
12
+ function getShortLanguageCode(langCode) {
13
+ const dashIndex = langCode.indexOf("-");
14
+ return dashIndex === -1 ? langCode : langCode.substring(0, dashIndex).toLowerCase();
15
+ }
16
+ export {
17
+ formatLanguageCodeWithName,
18
+ getShortLanguageCode,
19
+ languageCodeToName
20
+ };
@@ -0,0 +1,41 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+ var ObjectUtilities_exports = {};
30
+ __export(ObjectUtilities_exports, {
31
+ extendDeep: () => extendDeep
32
+ });
33
+ module.exports = __toCommonJS(ObjectUtilities_exports);
34
+ var import_lodash = __toESM(require("lodash.merge"), 1);
35
+ function extendDeep(base, extension) {
36
+ return (0, import_lodash.default)(base, extension);
37
+ }
38
+ // Annotate the CommonJS export names for ESM import in node:
39
+ 0 && (module.exports = {
40
+ extendDeep
41
+ });
@@ -0,0 +1,3 @@
1
+ declare function extendDeep<T extends object>(base: T, extension: Partial<T> | undefined): T;
2
+
3
+ export { extendDeep };
@@ -0,0 +1,3 @@
1
+ declare function extendDeep<T extends object>(base: T, extension: Partial<T> | undefined): T;
2
+
3
+ export { extendDeep };
@@ -0,0 +1,7 @@
1
+ import merge from "lodash.merge";
2
+ function extendDeep(base, extension) {
3
+ return merge(base, extension);
4
+ }
5
+ export {
6
+ extendDeep
7
+ };
@@ -0,0 +1,120 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var Timeline_exports = {};
20
+ __export(Timeline_exports, {
21
+ addTimeOffsetToTimeline: () => addTimeOffsetToTimeline,
22
+ addWordTextOffsetsToTimelineInPlace: () => addWordTextOffsetsToTimelineInPlace,
23
+ getUTF32Chars: () => getUTF32Chars
24
+ });
25
+ module.exports = __toCommonJS(Timeline_exports);
26
+ function addWordTextOffsetsToTimelineInPlace(timeline, text) {
27
+ const { utf16To32Mapping } = getUTF32Chars(text);
28
+ let currentOffset = 0;
29
+ function processTimeline(timeline2) {
30
+ var _a;
31
+ let lastEndOffset = 0;
32
+ for (const entry of timeline2) {
33
+ if (entry.type === "word") {
34
+ let word = entry.text;
35
+ word = word.trim().replaceAll(/\s+/g, " ");
36
+ const wordParts = word.split(" ");
37
+ let startOffset;
38
+ let endOffset;
39
+ for (let i = 0; i < wordParts.length; i++) {
40
+ const wordPart = wordParts[i];
41
+ if (!wordPart) {
42
+ continue;
43
+ }
44
+ const wordPartOffset = text.indexOf(wordPart, currentOffset);
45
+ if (wordPartOffset === -1) {
46
+ continue;
47
+ }
48
+ currentOffset = wordPartOffset + (((_a = wordParts[i]) == null ? void 0 : _a.length) ?? 0);
49
+ if (i === 0) {
50
+ startOffset = wordPartOffset;
51
+ }
52
+ endOffset = currentOffset;
53
+ }
54
+ const startOffsetUtf16 = startOffset ?? lastEndOffset;
55
+ const endOffsetUtf16 = endOffset ?? lastEndOffset;
56
+ entry.startOffsetUtf16 = startOffsetUtf16;
57
+ entry.endOffsetUtf16 = endOffsetUtf16;
58
+ const startOffsetUtf32 = utf16To32Mapping[startOffsetUtf16];
59
+ const endOffsetUtf32 = utf16To32Mapping[endOffsetUtf16];
60
+ if (startOffsetUtf32 === void 0 || endOffsetUtf32 === void 0) {
61
+ console.error("startOffsetUtf32 or endOffsetUtf32 is undefined", {
62
+ startOffsetUtf16,
63
+ endOffsetUtf16,
64
+ utf16To32Mapping
65
+ });
66
+ throw new Error("startOffsetUtf32 or endOffsetUtf32 is undefined");
67
+ }
68
+ entry.startOffsetUtf32 = startOffsetUtf32;
69
+ entry.endOffsetUtf32 = endOffsetUtf32;
70
+ if (endOffset !== void 0) {
71
+ lastEndOffset = endOffset;
72
+ }
73
+ } else if (entry.timeline) {
74
+ processTimeline(entry.timeline);
75
+ }
76
+ }
77
+ }
78
+ processTimeline(timeline);
79
+ return;
80
+ }
81
+ function getUTF32Chars(str) {
82
+ const utf32chars = [];
83
+ const utf16To32Mapping = [];
84
+ let utf32Index = 0;
85
+ for (const utf32char of str) {
86
+ utf32chars.push(utf32char);
87
+ for (let i = 0; i < utf32char.length; i++) {
88
+ utf16To32Mapping.push(utf32Index);
89
+ }
90
+ utf32Index += 1;
91
+ }
92
+ utf16To32Mapping.push(utf32Index);
93
+ return { utf32chars, utf16To32Mapping };
94
+ }
95
+ function addTimeOffsetToTimeline(targetTimeline, timeOffset) {
96
+ const newTimeline = structuredClone(targetTimeline);
97
+ for (const segmentTimelineEntry of newTimeline) {
98
+ segmentTimelineEntry.startTime = Math.max(
99
+ segmentTimelineEntry.startTime + timeOffset,
100
+ 0
101
+ );
102
+ segmentTimelineEntry.endTime = Math.max(
103
+ segmentTimelineEntry.endTime + timeOffset,
104
+ 0
105
+ );
106
+ if (segmentTimelineEntry.timeline) {
107
+ segmentTimelineEntry.timeline = addTimeOffsetToTimeline(
108
+ segmentTimelineEntry.timeline,
109
+ timeOffset
110
+ );
111
+ }
112
+ }
113
+ return newTimeline;
114
+ }
115
+ // Annotate the CommonJS export names for ESM import in node:
116
+ 0 && (module.exports = {
117
+ addTimeOffsetToTimeline,
118
+ addWordTextOffsetsToTimelineInPlace,
119
+ getUTF32Chars
120
+ });
@@ -0,0 +1,23 @@
1
+ type TimelineEntryType = "segment" | "paragraph" | "sentence" | "clause" | "phrase" | "word" | "token" | "letter" | "phone" | "subphone";
2
+ interface TimelineEntry {
3
+ type: TimelineEntryType;
4
+ text: string;
5
+ startTime: number;
6
+ endTime: number;
7
+ startOffsetUtf16?: number;
8
+ endOffsetUtf16?: number;
9
+ startOffsetUtf32?: number;
10
+ endOffsetUtf32?: number;
11
+ confidence?: number;
12
+ id?: number;
13
+ timeline?: Timeline;
14
+ }
15
+ type Timeline = TimelineEntry[];
16
+ declare function addWordTextOffsetsToTimelineInPlace(timeline: Timeline, text: string): void;
17
+ declare function getUTF32Chars(str: string): {
18
+ utf32chars: string[];
19
+ utf16To32Mapping: number[];
20
+ };
21
+ declare function addTimeOffsetToTimeline(targetTimeline: Timeline, timeOffset: number): Timeline;
22
+
23
+ export { type Timeline, type TimelineEntry, type TimelineEntryType, addTimeOffsetToTimeline, addWordTextOffsetsToTimelineInPlace, getUTF32Chars };
@@ -0,0 +1,23 @@
1
+ type TimelineEntryType = "segment" | "paragraph" | "sentence" | "clause" | "phrase" | "word" | "token" | "letter" | "phone" | "subphone";
2
+ interface TimelineEntry {
3
+ type: TimelineEntryType;
4
+ text: string;
5
+ startTime: number;
6
+ endTime: number;
7
+ startOffsetUtf16?: number;
8
+ endOffsetUtf16?: number;
9
+ startOffsetUtf32?: number;
10
+ endOffsetUtf32?: number;
11
+ confidence?: number;
12
+ id?: number;
13
+ timeline?: Timeline;
14
+ }
15
+ type Timeline = TimelineEntry[];
16
+ declare function addWordTextOffsetsToTimelineInPlace(timeline: Timeline, text: string): void;
17
+ declare function getUTF32Chars(str: string): {
18
+ utf32chars: string[];
19
+ utf16To32Mapping: number[];
20
+ };
21
+ declare function addTimeOffsetToTimeline(targetTimeline: Timeline, timeOffset: number): Timeline;
22
+
23
+ export { type Timeline, type TimelineEntry, type TimelineEntryType, addTimeOffsetToTimeline, addWordTextOffsetsToTimelineInPlace, getUTF32Chars };
@@ -0,0 +1,94 @@
1
+ function addWordTextOffsetsToTimelineInPlace(timeline, text) {
2
+ const { utf16To32Mapping } = getUTF32Chars(text);
3
+ let currentOffset = 0;
4
+ function processTimeline(timeline2) {
5
+ var _a;
6
+ let lastEndOffset = 0;
7
+ for (const entry of timeline2) {
8
+ if (entry.type === "word") {
9
+ let word = entry.text;
10
+ word = word.trim().replaceAll(/\s+/g, " ");
11
+ const wordParts = word.split(" ");
12
+ let startOffset;
13
+ let endOffset;
14
+ for (let i = 0; i < wordParts.length; i++) {
15
+ const wordPart = wordParts[i];
16
+ if (!wordPart) {
17
+ continue;
18
+ }
19
+ const wordPartOffset = text.indexOf(wordPart, currentOffset);
20
+ if (wordPartOffset === -1) {
21
+ continue;
22
+ }
23
+ currentOffset = wordPartOffset + (((_a = wordParts[i]) == null ? void 0 : _a.length) ?? 0);
24
+ if (i === 0) {
25
+ startOffset = wordPartOffset;
26
+ }
27
+ endOffset = currentOffset;
28
+ }
29
+ const startOffsetUtf16 = startOffset ?? lastEndOffset;
30
+ const endOffsetUtf16 = endOffset ?? lastEndOffset;
31
+ entry.startOffsetUtf16 = startOffsetUtf16;
32
+ entry.endOffsetUtf16 = endOffsetUtf16;
33
+ const startOffsetUtf32 = utf16To32Mapping[startOffsetUtf16];
34
+ const endOffsetUtf32 = utf16To32Mapping[endOffsetUtf16];
35
+ if (startOffsetUtf32 === void 0 || endOffsetUtf32 === void 0) {
36
+ console.error("startOffsetUtf32 or endOffsetUtf32 is undefined", {
37
+ startOffsetUtf16,
38
+ endOffsetUtf16,
39
+ utf16To32Mapping
40
+ });
41
+ throw new Error("startOffsetUtf32 or endOffsetUtf32 is undefined");
42
+ }
43
+ entry.startOffsetUtf32 = startOffsetUtf32;
44
+ entry.endOffsetUtf32 = endOffsetUtf32;
45
+ if (endOffset !== void 0) {
46
+ lastEndOffset = endOffset;
47
+ }
48
+ } else if (entry.timeline) {
49
+ processTimeline(entry.timeline);
50
+ }
51
+ }
52
+ }
53
+ processTimeline(timeline);
54
+ return;
55
+ }
56
+ function getUTF32Chars(str) {
57
+ const utf32chars = [];
58
+ const utf16To32Mapping = [];
59
+ let utf32Index = 0;
60
+ for (const utf32char of str) {
61
+ utf32chars.push(utf32char);
62
+ for (let i = 0; i < utf32char.length; i++) {
63
+ utf16To32Mapping.push(utf32Index);
64
+ }
65
+ utf32Index += 1;
66
+ }
67
+ utf16To32Mapping.push(utf32Index);
68
+ return { utf32chars, utf16To32Mapping };
69
+ }
70
+ function addTimeOffsetToTimeline(targetTimeline, timeOffset) {
71
+ const newTimeline = structuredClone(targetTimeline);
72
+ for (const segmentTimelineEntry of newTimeline) {
73
+ segmentTimelineEntry.startTime = Math.max(
74
+ segmentTimelineEntry.startTime + timeOffset,
75
+ 0
76
+ );
77
+ segmentTimelineEntry.endTime = Math.max(
78
+ segmentTimelineEntry.endTime + timeOffset,
79
+ 0
80
+ );
81
+ if (segmentTimelineEntry.timeline) {
82
+ segmentTimelineEntry.timeline = addTimeOffsetToTimeline(
83
+ segmentTimelineEntry.timeline,
84
+ timeOffset
85
+ );
86
+ }
87
+ }
88
+ return newTimeline;
89
+ }
90
+ export {
91
+ addTimeOffsetToTimeline,
92
+ addWordTextOffsetsToTimelineInPlace,
93
+ getUTF32Chars
94
+ };