@storyteller-platform/align 0.0.1 → 0.1.0
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.
package/dist/markup/markup.cjs
CHANGED
|
@@ -204,10 +204,15 @@ function markupBySegmentation(chapterId, state, segmentation, currentNode, tagge
|
|
|
204
204
|
taggedSentences
|
|
205
205
|
);
|
|
206
206
|
}
|
|
207
|
+
const mapping = mapWhitespace(remainingNodeText);
|
|
208
|
+
const mapped = mapThrough(
|
|
209
|
+
remainingSentence.length,
|
|
210
|
+
mapping.filter(([start]) => start >= index)
|
|
211
|
+
);
|
|
207
212
|
return {
|
|
208
213
|
currentSentenceIndex: state.currentSentenceIndex + 1,
|
|
209
214
|
currentSentenceProgress: 0,
|
|
210
|
-
currentNodeProgress: state.currentNodeProgress +
|
|
215
|
+
currentNodeProgress: state.currentNodeProgress + mapped + index
|
|
211
216
|
};
|
|
212
217
|
}
|
|
213
218
|
let nextState = {
|
|
@@ -265,6 +270,25 @@ function markupBySegmentation(chapterId, state, segmentation, currentNode, tagge
|
|
|
265
270
|
nextState.currentNodeProgress = -1;
|
|
266
271
|
return nextState;
|
|
267
272
|
}
|
|
273
|
+
function mapWhitespace(text) {
|
|
274
|
+
const re = /(\s\s+)/g;
|
|
275
|
+
const mapping = [];
|
|
276
|
+
let match = null;
|
|
277
|
+
while ((match = re.exec(text)) !== null) {
|
|
278
|
+
mapping.push([match.index, match[0].length, 1]);
|
|
279
|
+
}
|
|
280
|
+
return mapping;
|
|
281
|
+
}
|
|
282
|
+
function mapThrough(position, mapping) {
|
|
283
|
+
let result = position;
|
|
284
|
+
let index = 0;
|
|
285
|
+
while (index < mapping.length && mapping[index][0] < result) {
|
|
286
|
+
const map = mapping[index];
|
|
287
|
+
result += map[1] - map[2];
|
|
288
|
+
index++;
|
|
289
|
+
}
|
|
290
|
+
return result;
|
|
291
|
+
}
|
|
268
292
|
function appendTextNode(chapterId, xml, text, marks, taggedSentences, sentenceId) {
|
|
269
293
|
if (text.length === 0) return;
|
|
270
294
|
const textNode = { "#text": text };
|
package/dist/markup/markup.js
CHANGED
|
@@ -143,10 +143,15 @@ function markupBySegmentation(chapterId, state, segmentation, currentNode, tagge
|
|
|
143
143
|
taggedSentences
|
|
144
144
|
);
|
|
145
145
|
}
|
|
146
|
+
const mapping = mapWhitespace(remainingNodeText);
|
|
147
|
+
const mapped = mapThrough(
|
|
148
|
+
remainingSentence.length,
|
|
149
|
+
mapping.filter(([start]) => start >= index)
|
|
150
|
+
);
|
|
146
151
|
return {
|
|
147
152
|
currentSentenceIndex: state.currentSentenceIndex + 1,
|
|
148
153
|
currentSentenceProgress: 0,
|
|
149
|
-
currentNodeProgress: state.currentNodeProgress +
|
|
154
|
+
currentNodeProgress: state.currentNodeProgress + mapped + index
|
|
150
155
|
};
|
|
151
156
|
}
|
|
152
157
|
let nextState = {
|
|
@@ -204,6 +209,25 @@ function markupBySegmentation(chapterId, state, segmentation, currentNode, tagge
|
|
|
204
209
|
nextState.currentNodeProgress = -1;
|
|
205
210
|
return nextState;
|
|
206
211
|
}
|
|
212
|
+
function mapWhitespace(text) {
|
|
213
|
+
const re = /(\s\s+)/g;
|
|
214
|
+
const mapping = [];
|
|
215
|
+
let match = null;
|
|
216
|
+
while ((match = re.exec(text)) !== null) {
|
|
217
|
+
mapping.push([match.index, match[0].length, 1]);
|
|
218
|
+
}
|
|
219
|
+
return mapping;
|
|
220
|
+
}
|
|
221
|
+
function mapThrough(position, mapping) {
|
|
222
|
+
let result = position;
|
|
223
|
+
let index = 0;
|
|
224
|
+
while (index < mapping.length && mapping[index][0] < result) {
|
|
225
|
+
const map = mapping[index];
|
|
226
|
+
result += map[1] - map[2];
|
|
227
|
+
index++;
|
|
228
|
+
}
|
|
229
|
+
return result;
|
|
230
|
+
}
|
|
207
231
|
function appendTextNode(chapterId, xml, text, marks, taggedSentences, sentenceId) {
|
|
208
232
|
if (text.length === 0) return;
|
|
209
233
|
const textNode = { "#text": text };
|
|
@@ -87,7 +87,7 @@ async function processAudiobook(input, output, options) {
|
|
|
87
87
|
const outputFiles = [];
|
|
88
88
|
const controller = new AbortController();
|
|
89
89
|
const signal = AbortSignal.any([
|
|
90
|
-
options.signal
|
|
90
|
+
...options.signal ? [options.signal] : [],
|
|
91
91
|
controller.signal
|
|
92
92
|
]);
|
|
93
93
|
const semaphore = new import_async_semaphore.AsyncSemaphore(options.parallelism ?? 1);
|
|
@@ -34,7 +34,7 @@ async function processAudiobook(input, output, options) {
|
|
|
34
34
|
const outputFiles = [];
|
|
35
35
|
const controller = new AbortController();
|
|
36
36
|
const signal = AbortSignal.any([
|
|
37
|
-
options.signal
|
|
37
|
+
...options.signal ? [options.signal] : [],
|
|
38
38
|
controller.signal
|
|
39
39
|
]);
|
|
40
40
|
const semaphore = new AsyncSemaphore(options.parallelism ?? 1);
|
|
@@ -92,7 +92,7 @@ async function transcribe(input, output, locale, options) {
|
|
|
92
92
|
const semaphore = new import_async_semaphore.AsyncSemaphore(options.parallelism ?? 1);
|
|
93
93
|
const controller = new AbortController();
|
|
94
94
|
const signal = AbortSignal.any([
|
|
95
|
-
options.signal
|
|
95
|
+
...options.signal ? [options.signal] : [],
|
|
96
96
|
controller.signal
|
|
97
97
|
]);
|
|
98
98
|
await (0, import_promises.mkdir)(output, { recursive: true });
|
|
@@ -23,7 +23,7 @@ async function transcribe(input, output, locale, options) {
|
|
|
23
23
|
const semaphore = new AsyncSemaphore(options.parallelism ?? 1);
|
|
24
24
|
const controller = new AbortController();
|
|
25
25
|
const signal = AbortSignal.any([
|
|
26
|
-
options.signal
|
|
26
|
+
...options.signal ? [options.signal] : [],
|
|
27
27
|
controller.signal
|
|
28
28
|
]);
|
|
29
29
|
await mkdir(output, { recursive: true });
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@storyteller-platform/align",
|
|
3
|
-
"version": "0.0
|
|
3
|
+
"version": "0.1.0",
|
|
4
4
|
"description": "A library and CLI for automatically aligning audiobooks and EPUBs to produce Media Overlays",
|
|
5
5
|
"author": "Shane Friedman",
|
|
6
6
|
"license": "MIT",
|
|
@@ -56,9 +56,9 @@
|
|
|
56
56
|
"@esfx/async-semaphore": "^1.0.0",
|
|
57
57
|
"@optique/core": "^0.10.7",
|
|
58
58
|
"@optique/run": "^0.10.7",
|
|
59
|
-
"@storyteller-platform/audiobook": "^0.3.
|
|
59
|
+
"@storyteller-platform/audiobook": "^0.3.8",
|
|
60
60
|
"@storyteller-platform/epub": "^0.4.6",
|
|
61
|
-
"@storyteller-platform/ghost-story": "^0.1.
|
|
61
|
+
"@storyteller-platform/ghost-story": "^0.1.3",
|
|
62
62
|
"chalk": "^5.4.1",
|
|
63
63
|
"cli-progress": "^3.12.0",
|
|
64
64
|
"esbuild": "^0.27.3",
|