@beff/aula-cli 0.1.0 → 0.1.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.
- package/README.md +2 -2
- package/dist/src/aula-render.core.wasm +0 -0
- package/dist/src/{chunk-3IBMAZRS.js → chunk-46KT47TH.js} +1 -1
- package/dist/src/{chunk-SDFXIMLW.js → chunk-7KT36JRP.js} +312 -113
- package/dist/src/{chunk-UREQAEFC.js → chunk-IAQZ6DTC.js} +2 -222
- package/dist/src/{chunk-OMBYV6CK.js → chunk-QWNBVWUQ.js} +54 -12
- package/dist/src/chunk-XUBCUJW5.js +104 -0
- package/dist/src/{chunk-EYXQ2I7K.js → chunk-YX73KJQ6.js} +4 -31
- package/dist/src/cli.js +81 -16
- package/dist/src/{commands-VDGWDVWT.js → commands-M246OWYJ.js} +6 -7
- package/dist/src/problems-Y67BY7WB.js +12 -0
- package/dist/src/{project-M63R4ENB.js → project-NWT5MDQI.js} +2 -2
- package/dist/src/{run-CY72QGZJ.js → run-CTVGU7EK.js} +10 -10
- package/dist/src/{server-ZG6K7Z7H.js → server-5OGXX6BF.js} +6 -66
- package/dist/web/app/assets/__vite-browser-external-BN30sEqc.js +1 -0
- package/dist/web/app/assets/aula-method.js +1 -1
- package/dist/web/app/assets/{aula-voice-worker-BL6WcrSe.js → aula-voice-worker-DymX5vwM.js} +10 -10
- package/dist/web/app/assets/{aula.core5-BdGB-M10.wasm → aula.core5-YhDIb7Me.wasm} +0 -0
- package/dist/web/app/assets/aula.js +1 -1
- package/dist/web/app/assets/build-worker.js +8 -9
- package/dist/web/app/assets/index-B8_aMtuI.js +53 -0
- package/dist/web/app/assets/index-cL-Dm_aw.css +2 -0
- package/dist/web/app/assets/protocol-CnlzsyRt.js +15 -0
- package/dist/web/app/assets/{src-BbJ5r410.js → src-CmWmmzpF.js} +6 -6
- package/dist/web/app/index.html +4 -4
- package/package.json +2 -2
- package/dist/src/chunk-KLE5UOUB.js +0 -57
- package/dist/src/chunk-PYRORQA5.js +0 -88
- package/dist/src/chunk-X3HJY34X.js +0 -81
- package/dist/src/problems-OGUR4BLZ.js +0 -12
- package/dist/web/app/assets/__vite-browser-external-Bbi05A7N.js +0 -1
- package/dist/web/app/assets/index-BVQqteYG.js +0 -53
- package/dist/web/app/assets/index-CS60sOpp.css +0 -2
- package/dist/web/app/assets/protocol-Ds4jI5bY.js +0 -15
|
@@ -1,20 +1,13 @@
|
|
|
1
1
|
import {
|
|
2
|
-
AnyRuntype,
|
|
3
|
-
ArrayRuntype,
|
|
4
|
-
ObjectRuntype,
|
|
5
|
-
OptionalFieldRuntype,
|
|
6
|
-
RefRuntype,
|
|
7
|
-
TypeofRuntype,
|
|
8
|
-
buildParsers,
|
|
9
2
|
timeChapter
|
|
10
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-XUBCUJW5.js";
|
|
11
4
|
import {
|
|
12
5
|
Problems,
|
|
13
6
|
error,
|
|
14
7
|
isError,
|
|
15
8
|
withSource,
|
|
16
9
|
wrongArgument
|
|
17
|
-
} from "./chunk-
|
|
10
|
+
} from "./chunk-7KT36JRP.js";
|
|
18
11
|
|
|
19
12
|
// src/problems.ts
|
|
20
13
|
import { loadEngine as loadEngine2 } from "@beff/aula/run";
|
|
@@ -253,217 +246,6 @@ import {
|
|
|
253
246
|
narrationScript as narrationScript2
|
|
254
247
|
} from "@beff/aula/text";
|
|
255
248
|
|
|
256
|
-
// ../aula-bundle/generated/parser.js
|
|
257
|
-
var RequiredStringFormats = [];
|
|
258
|
-
var RequiredNumberFormats = [];
|
|
259
|
-
var namedRuntypes = {};
|
|
260
|
-
var stringFormatters = {};
|
|
261
|
-
var numberFormatters = {};
|
|
262
|
-
var direct_hoist_0 = new RefRuntype(void 0, "PackageJson", namedRuntypes);
|
|
263
|
-
var direct_hoist_1 = new AnyRuntype(void 0);
|
|
264
|
-
var direct_hoist_2 = new TypeofRuntype(void 0, "string");
|
|
265
|
-
var direct_hoist_3 = new ArrayRuntype(void 0, direct_hoist_2);
|
|
266
|
-
var direct_hoist_4 = new ObjectRuntype({
|
|
267
|
-
"description": "The part of a package.json that aula reads: how a package names its module and its\nworkspace packages."
|
|
268
|
-
}, {
|
|
269
|
-
"exports": new OptionalFieldRuntype(direct_hoist_1),
|
|
270
|
-
"main": new OptionalFieldRuntype(direct_hoist_2),
|
|
271
|
-
"module": new OptionalFieldRuntype(direct_hoist_2),
|
|
272
|
-
"name": new OptionalFieldRuntype(direct_hoist_2),
|
|
273
|
-
"workspaces": new OptionalFieldRuntype(direct_hoist_3)
|
|
274
|
-
}, []);
|
|
275
|
-
Object.assign(namedRuntypes, {
|
|
276
|
-
"PackageJson": direct_hoist_4
|
|
277
|
-
});
|
|
278
|
-
var buildParsersInput = {
|
|
279
|
-
"PackageJson": direct_hoist_0
|
|
280
|
-
};
|
|
281
|
-
var parser_default = {
|
|
282
|
-
buildParsers: (args) => buildParsers(
|
|
283
|
-
{
|
|
284
|
-
parsers: buildParsersInput,
|
|
285
|
-
stringFormatters,
|
|
286
|
-
numberFormatters,
|
|
287
|
-
requiredStringFormats: RequiredStringFormats,
|
|
288
|
-
requiredNumberFormats: RequiredNumberFormats
|
|
289
|
-
},
|
|
290
|
-
args
|
|
291
|
-
)
|
|
292
|
-
};
|
|
293
|
-
|
|
294
|
-
// ../aula-bundle/src/parsers.ts
|
|
295
|
-
var Parsers = parser_default.buildParsers();
|
|
296
|
-
|
|
297
|
-
// ../aula-bundle/src/index.ts
|
|
298
|
-
var SOURCE_PREFIX = "tree:";
|
|
299
|
-
function dirname(path) {
|
|
300
|
-
const at = path.lastIndexOf("/");
|
|
301
|
-
return at < 0 ? "" : path.slice(0, at);
|
|
302
|
-
}
|
|
303
|
-
function join(from, relative) {
|
|
304
|
-
const parts = from === "" ? [] : from.split("/");
|
|
305
|
-
for (const part of relative.split("/")) {
|
|
306
|
-
if (part === "" || part === ".") continue;
|
|
307
|
-
if (part === "..") {
|
|
308
|
-
if (!parts.length) return null;
|
|
309
|
-
parts.pop();
|
|
310
|
-
} else parts.push(part);
|
|
311
|
-
}
|
|
312
|
-
return parts.join("/");
|
|
313
|
-
}
|
|
314
|
-
var LOADERS = /* @__PURE__ */ new Map([
|
|
315
|
-
["ts", "ts"],
|
|
316
|
-
["mts", "ts"],
|
|
317
|
-
["js", "js"],
|
|
318
|
-
["mjs", "js"],
|
|
319
|
-
["json", "json"]
|
|
320
|
-
]);
|
|
321
|
-
var loaderOf = (path) => LOADERS.get(path.slice(path.lastIndexOf(".") + 1)) ?? "ts";
|
|
322
|
-
function treePlugin(tree, imports) {
|
|
323
|
-
return {
|
|
324
|
-
name: "aula-tree",
|
|
325
|
-
setup(build) {
|
|
326
|
-
build.onResolve({ filter: /.*/ }, async (args) => {
|
|
327
|
-
const url = imports[args.path];
|
|
328
|
-
if (url !== void 0) return { path: url, external: true };
|
|
329
|
-
if (args.kind === "entry-point") return { path: join("", args.path) ?? args.path, namespace: "tree" };
|
|
330
|
-
if (!args.path.startsWith("./") && !args.path.startsWith("../")) {
|
|
331
|
-
const found = await resolvePackage(tree, args.path, args.importer);
|
|
332
|
-
if (found !== null) return { path: found, namespace: "tree" };
|
|
333
|
-
return {
|
|
334
|
-
errors: [{ text: `cannot find the package "${args.path}" in node_modules or the workspace packages` }]
|
|
335
|
-
};
|
|
336
|
-
}
|
|
337
|
-
const path = join(dirname(args.importer), args.path);
|
|
338
|
-
if (path === null) return { errors: [{ text: `"${args.path}" is outside the folder you opened` }] };
|
|
339
|
-
for (const candidate of [path, `${path}.ts`, `${path}/index.ts`]) {
|
|
340
|
-
if (await tree.read(candidate) !== null) return { path: candidate, namespace: "tree" };
|
|
341
|
-
}
|
|
342
|
-
return { errors: [{ text: `cannot find "${args.path}" (${path})` }] };
|
|
343
|
-
});
|
|
344
|
-
build.onLoad({ filter: /.*/, namespace: "tree" }, async (args) => {
|
|
345
|
-
const contents = await tree.read(args.path);
|
|
346
|
-
if (contents === null) return { errors: [{ text: `cannot read ${args.path}` }] };
|
|
347
|
-
return { contents, loader: loaderOf(args.path) };
|
|
348
|
-
});
|
|
349
|
-
}
|
|
350
|
-
};
|
|
351
|
-
}
|
|
352
|
-
function isMessage(value) {
|
|
353
|
-
return typeof value === "object" && value !== null && typeof Reflect.get(value, "text") === "string";
|
|
354
|
-
}
|
|
355
|
-
var diagnostic = ({ text, location: at }) => ({
|
|
356
|
-
severity: "error",
|
|
357
|
-
message: text,
|
|
358
|
-
...at ? { location: { file: at.file.replace(SOURCE_PREFIX, ""), line: at.line, col: at.column + 1 } } : {},
|
|
359
|
-
stack: [],
|
|
360
|
-
related: []
|
|
361
|
-
});
|
|
362
|
-
async function bundle(esbuild, tree, entry, imports) {
|
|
363
|
-
let result;
|
|
364
|
-
try {
|
|
365
|
-
result = await esbuild.build({
|
|
366
|
-
entryPoints: [entry],
|
|
367
|
-
bundle: true,
|
|
368
|
-
write: false,
|
|
369
|
-
format: "esm",
|
|
370
|
-
platform: "browser",
|
|
371
|
-
target: "es2024",
|
|
372
|
-
outfile: "bundle.js",
|
|
373
|
-
sourcemap: "both",
|
|
374
|
-
sourcesContent: false,
|
|
375
|
-
metafile: true,
|
|
376
|
-
logLevel: "silent",
|
|
377
|
-
plugins: [treePlugin(tree, imports)]
|
|
378
|
-
});
|
|
379
|
-
} catch (error2) {
|
|
380
|
-
const errors = typeof error2 === "object" && error2 !== null ? Reflect.get(error2, "errors") : void 0;
|
|
381
|
-
if (Array.isArray(errors) && errors.every(isMessage)) return { _tag: "Left", left: errors.map(diagnostic) };
|
|
382
|
-
throw error2;
|
|
383
|
-
}
|
|
384
|
-
const code = result.outputFiles.find((f) => f.path.endsWith(".js"))?.text;
|
|
385
|
-
const map = result.outputFiles.find((f) => f.path.endsWith(".js.map"))?.text;
|
|
386
|
-
if (code === void 0 || map === void 0) throw new Error("esbuild wrote no bundle");
|
|
387
|
-
const inputs = Object.keys(result.metafile?.inputs ?? {}).filter((input) => input.startsWith(SOURCE_PREFIX)).map((input) => input.slice(SOURCE_PREFIX.length));
|
|
388
|
-
return { _tag: "Right", right: { code, map, inputs } };
|
|
389
|
-
}
|
|
390
|
-
function exportTarget(exports, subpath) {
|
|
391
|
-
if (typeof exports === "string") return subpath === "." ? exports : null;
|
|
392
|
-
if (typeof exports !== "object" || exports === null) return null;
|
|
393
|
-
const keys = Object.keys(exports);
|
|
394
|
-
if (keys.some((key) => key.startsWith("."))) {
|
|
395
|
-
return subpath in exports ? exportTarget(Reflect.get(exports, subpath), ".") : null;
|
|
396
|
-
}
|
|
397
|
-
for (const key of ["browser", "import", "default"]) {
|
|
398
|
-
if (key in exports) return exportTarget(Reflect.get(exports, key), ".");
|
|
399
|
-
}
|
|
400
|
-
return null;
|
|
401
|
-
}
|
|
402
|
-
function packageOf(specifier) {
|
|
403
|
-
const parts = specifier.split("/");
|
|
404
|
-
const size = specifier.startsWith("@") ? 2 : 1;
|
|
405
|
-
const rest = parts.slice(size).join("/");
|
|
406
|
-
return { name: parts.slice(0, size).join("/"), subpath: rest === "" ? "." : `./${rest}` };
|
|
407
|
-
}
|
|
408
|
-
async function packageModule(tree, folder, subpath) {
|
|
409
|
-
const found = manifest(`${folder}/package.json`, await tree.read(`${folder}/package.json`));
|
|
410
|
-
if (!found) return null;
|
|
411
|
-
const target = exportTarget(found.exports, subpath) ?? (subpath === "." ? found.module ?? found.main ?? "index.js" : subpath);
|
|
412
|
-
return join(folder, target);
|
|
413
|
-
}
|
|
414
|
-
async function resolveBare(tree, specifier, importer) {
|
|
415
|
-
const { name, subpath } = packageOf(specifier);
|
|
416
|
-
for (let dir = dirname(importer); ; dir = dirname(dir)) {
|
|
417
|
-
const found = await packageModule(
|
|
418
|
-
tree,
|
|
419
|
-
dir === "" ? `node_modules/${name}` : `${dir}/node_modules/${name}`,
|
|
420
|
-
subpath
|
|
421
|
-
);
|
|
422
|
-
if (found !== null) return found;
|
|
423
|
-
if (dir === "") return null;
|
|
424
|
-
}
|
|
425
|
-
}
|
|
426
|
-
function manifest(file, text) {
|
|
427
|
-
if (text === null) return null;
|
|
428
|
-
const parsed = Parsers.PackageJson.safeParse(JSON.parse(text));
|
|
429
|
-
return parsed.success ? parsed.data : null;
|
|
430
|
-
}
|
|
431
|
-
async function workspaceFolders(tree) {
|
|
432
|
-
const patterns = [];
|
|
433
|
-
const pnpm = await tree.read("pnpm-workspace.yaml");
|
|
434
|
-
if (pnpm !== null) {
|
|
435
|
-
let inside = false;
|
|
436
|
-
for (const line of pnpm.split("\n")) {
|
|
437
|
-
if (/^packages:\s*$/.test(line)) inside = true;
|
|
438
|
-
else if (/^\S/.test(line)) inside = false;
|
|
439
|
-
else if (inside) {
|
|
440
|
-
const item = /^\s*-\s*["']?([^"'#]+?)["']?\s*(#.*)?$/.exec(line)?.[1];
|
|
441
|
-
if (item !== void 0) patterns.push(item);
|
|
442
|
-
}
|
|
443
|
-
}
|
|
444
|
-
}
|
|
445
|
-
patterns.push(...manifest("package.json", await tree.read("package.json"))?.workspaces ?? []);
|
|
446
|
-
const folders = [];
|
|
447
|
-
for (const pattern of patterns) {
|
|
448
|
-
const clean = pattern.replace(/^\.\//, "").replace(/\/$/, "");
|
|
449
|
-
if (clean.endsWith("/*")) {
|
|
450
|
-
const parent = clean.slice(0, -2);
|
|
451
|
-
folders.push(...(await tree.list(parent)).map((name) => `${parent}/${name}`));
|
|
452
|
-
} else if (!clean.includes("*")) folders.push(clean);
|
|
453
|
-
}
|
|
454
|
-
return folders;
|
|
455
|
-
}
|
|
456
|
-
async function resolvePackage(tree, specifier, importer) {
|
|
457
|
-
const installed = await resolveBare(tree, specifier, importer);
|
|
458
|
-
if (installed !== null) return installed;
|
|
459
|
-
const { name, subpath } = packageOf(specifier);
|
|
460
|
-
for (const folder of await workspaceFolders(tree)) {
|
|
461
|
-
if (manifest(`${folder}/package.json`, await tree.read(`${folder}/package.json`))?.name !== name) continue;
|
|
462
|
-
return packageModule(tree, folder, subpath);
|
|
463
|
-
}
|
|
464
|
-
return null;
|
|
465
|
-
}
|
|
466
|
-
|
|
467
249
|
// src/problems.ts
|
|
468
250
|
async function printDiagnostics(capabilities, root, diagnostics, print = (text) => capabilities.log.out(text)) {
|
|
469
251
|
await loadEngine2();
|
|
@@ -485,7 +267,5 @@ export {
|
|
|
485
267
|
pictureGroups,
|
|
486
268
|
movesMarkdown,
|
|
487
269
|
timelineView,
|
|
488
|
-
Parsers,
|
|
489
|
-
bundle,
|
|
490
270
|
printDiagnostics
|
|
491
271
|
};
|
|
@@ -4,8 +4,6 @@ import {
|
|
|
4
4
|
ffmpeg
|
|
5
5
|
} from "./chunk-GFCJYE75.js";
|
|
6
6
|
import {
|
|
7
|
-
Parsers,
|
|
8
|
-
bundle,
|
|
9
7
|
chapterIndexes,
|
|
10
8
|
checkProject,
|
|
11
9
|
clipPlan,
|
|
@@ -21,25 +19,29 @@ import {
|
|
|
21
19
|
scriptView,
|
|
22
20
|
targetChapters,
|
|
23
21
|
timelineView
|
|
24
|
-
} from "./chunk-
|
|
25
|
-
import {
|
|
26
|
-
Parsers as Parsers2
|
|
27
|
-
} from "./chunk-KLE5UOUB.js";
|
|
22
|
+
} from "./chunk-IAQZ6DTC.js";
|
|
28
23
|
import {
|
|
29
24
|
narrateScript,
|
|
30
25
|
scriptAudio,
|
|
31
26
|
wav
|
|
32
|
-
} from "./chunk-
|
|
27
|
+
} from "./chunk-XUBCUJW5.js";
|
|
33
28
|
import {
|
|
34
29
|
host
|
|
35
|
-
} from "./chunk-
|
|
30
|
+
} from "./chunk-46KT47TH.js";
|
|
36
31
|
import {
|
|
32
|
+
ObjectRuntype,
|
|
33
|
+
OptionalFieldRuntype,
|
|
34
|
+
Parsers,
|
|
37
35
|
Problems,
|
|
36
|
+
RefRuntype,
|
|
37
|
+
TypeofRuntype,
|
|
38
|
+
buildParsers,
|
|
39
|
+
bundle,
|
|
38
40
|
folderOf,
|
|
39
41
|
isError,
|
|
40
42
|
nameOf,
|
|
41
43
|
wrongArgument
|
|
42
|
-
} from "./chunk-
|
|
44
|
+
} from "./chunk-7KT36JRP.js";
|
|
43
45
|
|
|
44
46
|
// src/commands.ts
|
|
45
47
|
import path2 from "node:path";
|
|
@@ -810,11 +812,51 @@ function zipBytes(entries) {
|
|
|
810
812
|
|
|
811
813
|
// src/narrate.ts
|
|
812
814
|
function narrate(capabilities, chapters) {
|
|
813
|
-
return narrateScript(
|
|
814
|
-
|
|
815
|
-
|
|
815
|
+
return narrateScript(
|
|
816
|
+
(text, speed) => capabilities.narrator.speak(text, speed),
|
|
817
|
+
chapters,
|
|
818
|
+
(spoken, count, cue) => {
|
|
819
|
+
capabilities.log.out(`[${String(spoken)}/${String(count)}] Narrating: ${cue.text.slice(0, 70)}`);
|
|
820
|
+
}
|
|
821
|
+
);
|
|
816
822
|
}
|
|
817
823
|
|
|
824
|
+
// generated/parser.js
|
|
825
|
+
var RequiredStringFormats = [];
|
|
826
|
+
var RequiredNumberFormats = [];
|
|
827
|
+
var namedRuntypes = {};
|
|
828
|
+
var stringFormatters = {};
|
|
829
|
+
var numberFormatters = {};
|
|
830
|
+
var direct_hoist_0 = new RefRuntype(void 0, "TokensLine", namedRuntypes);
|
|
831
|
+
var direct_hoist_1 = new TypeofRuntype(void 0, "string");
|
|
832
|
+
var direct_hoist_2 = new ObjectRuntype({
|
|
833
|
+
"description": "One input line of `aula tokens`: a text, and an optional id that the output line repeats."
|
|
834
|
+
}, {
|
|
835
|
+
"id": new OptionalFieldRuntype(direct_hoist_1),
|
|
836
|
+
"text": direct_hoist_1
|
|
837
|
+
}, []);
|
|
838
|
+
Object.assign(namedRuntypes, {
|
|
839
|
+
"TokensLine": direct_hoist_2
|
|
840
|
+
});
|
|
841
|
+
var buildParsersInput = {
|
|
842
|
+
"TokensLine": direct_hoist_0
|
|
843
|
+
};
|
|
844
|
+
var parser_default = {
|
|
845
|
+
buildParsers: (args) => buildParsers(
|
|
846
|
+
{
|
|
847
|
+
parsers: buildParsersInput,
|
|
848
|
+
stringFormatters,
|
|
849
|
+
numberFormatters,
|
|
850
|
+
requiredStringFormats: RequiredStringFormats,
|
|
851
|
+
requiredNumberFormats: RequiredNumberFormats
|
|
852
|
+
},
|
|
853
|
+
args
|
|
854
|
+
)
|
|
855
|
+
};
|
|
856
|
+
|
|
857
|
+
// src/parsers.ts
|
|
858
|
+
var Parsers2 = parser_default.buildParsers();
|
|
859
|
+
|
|
818
860
|
// src/project-zip.ts
|
|
819
861
|
import path from "node:path";
|
|
820
862
|
function diskTree(capabilities, root) {
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
// ../aula-narration/src/script.ts
|
|
2
|
+
import { chapterNarration } from "@beff/aula/text";
|
|
3
|
+
function joinChapter(cues, speeches) {
|
|
4
|
+
let rate = 0;
|
|
5
|
+
for (const [i, speech] of speeches.entries()) {
|
|
6
|
+
if (!speech.samples.length || speech.samples.some((s) => !Number.isFinite(s))) {
|
|
7
|
+
const text = cues[i]?.text.slice(0, 60) ?? "";
|
|
8
|
+
throw new Error(`the narrator returned empty or invalid audio for ${JSON.stringify(text)}`);
|
|
9
|
+
}
|
|
10
|
+
if (rate !== 0 && speech.sampleRate !== rate) throw new Error("the narrator changed its sample rate");
|
|
11
|
+
rate = speech.sampleRate;
|
|
12
|
+
}
|
|
13
|
+
const spoken = speeches.map((s) => ({
|
|
14
|
+
samples: s.samples.length,
|
|
15
|
+
words: s.words.map((w) => ({ text: w.text, char: w.char, start: w.start }))
|
|
16
|
+
}));
|
|
17
|
+
const narration = chapterNarration(cues, spoken, rate);
|
|
18
|
+
const samples = new Float32Array(narration.endFrame);
|
|
19
|
+
for (const [i, speech] of speeches.entries()) samples.set(speech.samples, narration.cues[i]?.speechStartFrame ?? 0);
|
|
20
|
+
return { samples, narration };
|
|
21
|
+
}
|
|
22
|
+
function withWaits(samples, waits) {
|
|
23
|
+
if (waits.length === 0) return samples;
|
|
24
|
+
const out = new Float32Array(samples.length + waits.reduce((sum, w) => sum + w.samples, 0));
|
|
25
|
+
let from = 0;
|
|
26
|
+
let to = 0;
|
|
27
|
+
for (const wait of waits.toSorted((a, b) => a.sample - b.sample)) {
|
|
28
|
+
const at = Math.min(wait.sample, samples.length);
|
|
29
|
+
out.set(samples.subarray(from, at), to);
|
|
30
|
+
to += at - from + wait.samples;
|
|
31
|
+
from = at;
|
|
32
|
+
}
|
|
33
|
+
out.set(samples.subarray(from), to);
|
|
34
|
+
return out;
|
|
35
|
+
}
|
|
36
|
+
function timeChapter(cues, timings) {
|
|
37
|
+
const rate = timings[0]?.sampleRate ?? 0;
|
|
38
|
+
if (timings.some((t) => t.sampleRate !== rate)) throw new Error("the narrator changed its sample rate");
|
|
39
|
+
const spoken = timings.map((t) => ({
|
|
40
|
+
samples: t.samples,
|
|
41
|
+
words: t.words.map((w) => ({ text: w.text, char: w.char, start: w.start }))
|
|
42
|
+
}));
|
|
43
|
+
return chapterNarration(cues, spoken, rate);
|
|
44
|
+
}
|
|
45
|
+
async function narrateScript(speak, chapters, speaking) {
|
|
46
|
+
const count = chapters.reduce((sum, c) => sum + c.length, 0);
|
|
47
|
+
let spoken = 0;
|
|
48
|
+
const narrated = [];
|
|
49
|
+
for (const cues of chapters) {
|
|
50
|
+
const speeches = [];
|
|
51
|
+
for (const cue of cues) {
|
|
52
|
+
spoken += 1;
|
|
53
|
+
speaking(spoken, count, cue);
|
|
54
|
+
speeches.push(await speak(cue.text, cue.speed));
|
|
55
|
+
}
|
|
56
|
+
narrated.push(joinChapter(cues, speeches));
|
|
57
|
+
}
|
|
58
|
+
if (!narrated.some((c) => c.narration.sampleRate > 0)) throw new Error("the script has no cues");
|
|
59
|
+
return narrated;
|
|
60
|
+
}
|
|
61
|
+
function scriptAudio(chapters, waits) {
|
|
62
|
+
const sounds = chapters.map((c, i) => withWaits(c.samples, waits[i] ?? []));
|
|
63
|
+
const samples = new Float32Array(sounds.reduce((sum, s) => sum + s.length, 0));
|
|
64
|
+
let at = 0;
|
|
65
|
+
for (const sound of sounds) {
|
|
66
|
+
samples.set(sound, at);
|
|
67
|
+
at += sound.length;
|
|
68
|
+
}
|
|
69
|
+
const sampleRate = chapters.find((c) => c.narration.sampleRate > 0)?.narration.sampleRate ?? 0;
|
|
70
|
+
return { samples, sampleRate };
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
// ../aula-narration/src/wav.ts
|
|
74
|
+
function wav(samples, rate) {
|
|
75
|
+
const bytes = new Uint8Array(44 + samples.length * 2);
|
|
76
|
+
const view = new DataView(bytes.buffer);
|
|
77
|
+
const text = (at, value) => {
|
|
78
|
+
for (let i = 0; i < value.length; i++) view.setUint8(at + i, value.charCodeAt(i));
|
|
79
|
+
};
|
|
80
|
+
text(0, "RIFF");
|
|
81
|
+
view.setUint32(4, 36 + samples.length * 2, true);
|
|
82
|
+
text(8, "WAVE");
|
|
83
|
+
text(12, "fmt ");
|
|
84
|
+
view.setUint32(16, 16, true);
|
|
85
|
+
view.setUint16(20, 1, true);
|
|
86
|
+
view.setUint16(22, 1, true);
|
|
87
|
+
view.setUint32(24, rate, true);
|
|
88
|
+
view.setUint32(28, rate * 2, true);
|
|
89
|
+
view.setUint16(32, 2, true);
|
|
90
|
+
view.setUint16(34, 16, true);
|
|
91
|
+
text(36, "data");
|
|
92
|
+
view.setUint32(40, samples.length * 2, true);
|
|
93
|
+
samples.forEach((sample, i) => {
|
|
94
|
+
view.setInt16(44 + i * 2, Math.round(Math.min(1, Math.max(-1, sample)) * 32767), true);
|
|
95
|
+
});
|
|
96
|
+
return bytes;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
export {
|
|
100
|
+
timeChapter,
|
|
101
|
+
narrateScript,
|
|
102
|
+
scriptAudio,
|
|
103
|
+
wav
|
|
104
|
+
};
|
|
@@ -303,7 +303,7 @@ var AULA_VOICE_WEIGHTS = {
|
|
|
303
303
|
};
|
|
304
304
|
var SERVER_WEIGHTS_PATH = `/models/${AULA_VOICE_WEIGHTS.path}`;
|
|
305
305
|
var aulaVoiceUrl = (file) => `${RELEASE_URL}/${file.path}`;
|
|
306
|
-
var VOICE =
|
|
306
|
+
var VOICE = 0;
|
|
307
307
|
var SAMPLE_RATE = 24e3;
|
|
308
308
|
var HOP = 300;
|
|
309
309
|
var MAX_TOKENS = 250;
|
|
@@ -326,7 +326,7 @@ async function layout(parts, text, speed, audio) {
|
|
|
326
326
|
const { ids, known } = tokenize(KOKORO_VOCAB, batch);
|
|
327
327
|
if (!ids.length) throw new Error(`No phonemes of ${JSON.stringify(batch)} are in the model's token table`);
|
|
328
328
|
const padded = [0, ...ids, 0];
|
|
329
|
-
const spoken = audio ? parts.model.speak(padded, VOICE
|
|
329
|
+
const spoken = audio ? parts.model.speak(padded, VOICE, speed) : { audio: null, durations: parts.model.durations(padded, VOICE, speed) };
|
|
330
330
|
const edges = [0];
|
|
331
331
|
for (let i = 0; i < spoken.durations.length; i++) edges.push((edges[i] ?? 0) + Number(spoken.durations[i]) * HOP);
|
|
332
332
|
const head = Math.max((edges[1] ?? 0) - LEAD * HOP, 0);
|
|
@@ -356,7 +356,6 @@ async function timeAulaVoice(parts, text, speed) {
|
|
|
356
356
|
const { total, words } = await layout(parts, text, speed, false);
|
|
357
357
|
return { samples: total, sampleRate: SAMPLE_RATE, words };
|
|
358
358
|
}
|
|
359
|
-
var aulaVoiceId = (backend) => `aula-voice@${AULA_VOICE_RELEASE}+${AULA_VOICE_WEIGHTS.sha256.slice(0, 12)}/${VOICE.name}/${backend}`;
|
|
360
359
|
|
|
361
360
|
// ../aula-narration/src/avw.ts
|
|
362
361
|
var FIXED = {
|
|
@@ -553,33 +552,6 @@ function studentWeightFile(model, config) {
|
|
|
553
552
|
return file;
|
|
554
553
|
}
|
|
555
554
|
|
|
556
|
-
// ../aula-narration/src/narrator.ts
|
|
557
|
-
function once(load) {
|
|
558
|
-
let loading = null;
|
|
559
|
-
return async () => {
|
|
560
|
-
if (loading) return loading;
|
|
561
|
-
const started = load();
|
|
562
|
-
loading = started;
|
|
563
|
-
let loaded = false;
|
|
564
|
-
try {
|
|
565
|
-
const value = await started;
|
|
566
|
-
loaded = true;
|
|
567
|
-
return value;
|
|
568
|
-
} finally {
|
|
569
|
-
if (!loaded) loading = null;
|
|
570
|
-
}
|
|
571
|
-
};
|
|
572
|
-
}
|
|
573
|
-
function aulaVoiceNarrator(backend, load) {
|
|
574
|
-
const model = once(load);
|
|
575
|
-
return {
|
|
576
|
-
id: aulaVoiceId(backend),
|
|
577
|
-
speak: async (text, speed) => speakAulaVoice(await model(), text, speed),
|
|
578
|
-
time: async (text, speed) => timeAulaVoice(await model(), text, speed),
|
|
579
|
-
onStatus: () => void 0
|
|
580
|
-
};
|
|
581
|
-
}
|
|
582
|
-
|
|
583
555
|
// ../aula-narration/src/phonemize.ts
|
|
584
556
|
import { loadEngine } from "@beff/aula/run";
|
|
585
557
|
import { phonemize } from "@beff/aula/text";
|
|
@@ -598,7 +570,8 @@ export {
|
|
|
598
570
|
AULA_VOICE_WEIGHTS,
|
|
599
571
|
SERVER_WEIGHTS_PATH,
|
|
600
572
|
aulaVoiceUrl,
|
|
573
|
+
speakAulaVoice,
|
|
574
|
+
timeAulaVoice,
|
|
601
575
|
studentWeightFile,
|
|
602
|
-
aulaVoiceNarrator,
|
|
603
576
|
britishPhonemizer
|
|
604
577
|
};
|
package/dist/src/cli.js
CHANGED
|
@@ -4,11 +4,17 @@ import {
|
|
|
4
4
|
status
|
|
5
5
|
} from "./chunk-2XGNOG2U.js";
|
|
6
6
|
import {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
7
|
+
AULA_VOICE_FILES,
|
|
8
|
+
AULA_VOICE_RELEASE,
|
|
9
|
+
AULA_VOICE_WEIGHTS,
|
|
10
|
+
KOKORO_VOCAB,
|
|
11
|
+
aulaVoiceUrl,
|
|
12
|
+
britishPhonemizer,
|
|
13
|
+
speakAulaVoice,
|
|
14
|
+
studentWeightFile,
|
|
15
|
+
timeAulaVoice,
|
|
16
|
+
tokenBatches
|
|
17
|
+
} from "./chunk-YX73KJQ6.js";
|
|
12
18
|
|
|
13
19
|
// src/cli.ts
|
|
14
20
|
import { spawn } from "node:child_process";
|
|
@@ -16,7 +22,7 @@ import { existsSync, watch } from "node:fs";
|
|
|
16
22
|
import * as fs from "node:fs/promises";
|
|
17
23
|
import os from "node:os";
|
|
18
24
|
import { createInterface } from "node:readline";
|
|
19
|
-
import
|
|
25
|
+
import path3 from "node:path";
|
|
20
26
|
|
|
21
27
|
// ../../node_modules/.pnpm/@beff+diy@0.0.36/node_modules/@beff/diy/dist/esm/capabilities.js
|
|
22
28
|
function create(serviceMap) {
|
|
@@ -167,6 +173,65 @@ function createRender(capabilities2, node) {
|
|
|
167
173
|
};
|
|
168
174
|
}
|
|
169
175
|
|
|
176
|
+
// ../aula-narration/src/node.ts
|
|
177
|
+
import { createHash } from "node:crypto";
|
|
178
|
+
import path2 from "node:path";
|
|
179
|
+
import { fault } from "@beff/aula/errors";
|
|
180
|
+
var sha256 = (bytes) => createHash("sha256").update(bytes).digest("hex");
|
|
181
|
+
async function download(capabilities2, fetch2, downloading, destination, url, hash) {
|
|
182
|
+
if (capabilities2.fs.existsSync(destination)) {
|
|
183
|
+
const kept = new Uint8Array(await capabilities2.fs.readFile(destination));
|
|
184
|
+
if (sha256(kept) === hash) return kept;
|
|
185
|
+
}
|
|
186
|
+
downloading(path2.basename(destination));
|
|
187
|
+
const response = await fetch2(url, { headers: { "User-Agent": "aula" } });
|
|
188
|
+
if (!response.ok) throw new Error(`Cannot download ${url}: HTTP ${String(response.status)}`);
|
|
189
|
+
const bytes = new Uint8Array(await response.arrayBuffer());
|
|
190
|
+
const expected = Number(response.headers.get("Content-Length") ?? 0);
|
|
191
|
+
if (expected && bytes.byteLength !== expected) throw new Error(`Incomplete download of ${url}; run again to retry`);
|
|
192
|
+
if (sha256(bytes) !== hash) {
|
|
193
|
+
fault(`the download of ${url} has the wrong SHA-256`, "run the command again; if it fails again, report it");
|
|
194
|
+
}
|
|
195
|
+
await capabilities2.fs.mkdir(path2.dirname(destination), { recursive: true });
|
|
196
|
+
await capabilities2.fs.writeFile(`${destination}.part`, bytes);
|
|
197
|
+
await capabilities2.fs.rename(`${destination}.part`, destination);
|
|
198
|
+
return bytes;
|
|
199
|
+
}
|
|
200
|
+
var phonemize = britishPhonemizer(new Set(KOKORO_VOCAB.keys()));
|
|
201
|
+
function textTokens() {
|
|
202
|
+
return (text) => tokenBatches(KOKORO_VOCAB, phonemize, text);
|
|
203
|
+
}
|
|
204
|
+
var aulaVoiceFolder = (models2) => path2.join(models2, "aula-voice", AULA_VOICE_RELEASE);
|
|
205
|
+
async function aulaVoiceWeightFile(capabilities2, options2) {
|
|
206
|
+
const { fetch: fetch2, models: models2, downloading } = options2;
|
|
207
|
+
const folder = aulaVoiceFolder(models2);
|
|
208
|
+
const destination = path2.join(folder, AULA_VOICE_WEIGHTS.path);
|
|
209
|
+
if (capabilities2.fs.existsSync(destination)) {
|
|
210
|
+
const kept = new Uint8Array(await capabilities2.fs.readFile(destination));
|
|
211
|
+
if (sha256(kept) === AULA_VOICE_WEIGHTS.sha256) return kept;
|
|
212
|
+
}
|
|
213
|
+
const { model, config } = AULA_VOICE_FILES;
|
|
214
|
+
const raw = (file) => download(capabilities2, fetch2, downloading, path2.join(folder, file.path), aulaVoiceUrl(file), file.sha256);
|
|
215
|
+
const avw = studentWeightFile(await raw(model), await raw(config));
|
|
216
|
+
if (sha256(avw) !== AULA_VOICE_WEIGHTS.sha256) {
|
|
217
|
+
fault("the weight file made from aula-voice's release has the wrong SHA-256", "report it");
|
|
218
|
+
}
|
|
219
|
+
await capabilities2.fs.writeFile(`${destination}.part`, avw);
|
|
220
|
+
await capabilities2.fs.rename(`${destination}.part`, destination);
|
|
221
|
+
return avw;
|
|
222
|
+
}
|
|
223
|
+
function aulaVoice(capabilities2, options2) {
|
|
224
|
+
let loading = null;
|
|
225
|
+
const parts = () => loading ??= (async () => {
|
|
226
|
+
const { aulaVoiceModel } = await import("./aula-voice-tts-ZXQ7XXHJ.js");
|
|
227
|
+
return { model: await aulaVoiceModel(await aulaVoiceWeightFile(capabilities2, options2)), phonemize };
|
|
228
|
+
})();
|
|
229
|
+
return {
|
|
230
|
+
speak: async (text, speed) => speakAulaVoice(await parts(), text, speed),
|
|
231
|
+
time: async (text, speed) => timeAulaVoice(await parts(), text, speed)
|
|
232
|
+
};
|
|
233
|
+
}
|
|
234
|
+
|
|
170
235
|
// src/aula-voice.ts
|
|
171
236
|
function options(capabilities2, fetch2, models2) {
|
|
172
237
|
return {
|
|
@@ -177,8 +242,8 @@ function options(capabilities2, fetch2, models2) {
|
|
|
177
242
|
}
|
|
178
243
|
};
|
|
179
244
|
}
|
|
180
|
-
function
|
|
181
|
-
return
|
|
245
|
+
function createAulaVoice(capabilities2, fetch2, models2) {
|
|
246
|
+
return aulaVoice(capabilities2, options(capabilities2, fetch2, models2));
|
|
182
247
|
}
|
|
183
248
|
function aulaVoiceWeights(capabilities2, fetch2, models2) {
|
|
184
249
|
return () => aulaVoiceWeightFile(capabilities2, options(capabilities2, fetch2, models2));
|
|
@@ -206,13 +271,13 @@ var base = Capabilities.create({
|
|
|
206
271
|
},
|
|
207
272
|
spawn
|
|
208
273
|
});
|
|
209
|
-
var { diagnosticsOf, printDiagnostics } = await import("./problems-
|
|
210
|
-
var { host, loadProject } = await import("./project-
|
|
211
|
-
var { USAGE, folderArgs, isHelp, optionsOf, parse, run: run2, webOptions } = await import("./run-
|
|
212
|
-
var locks = createLocks(base,
|
|
274
|
+
var { diagnosticsOf, printDiagnostics } = await import("./problems-Y67BY7WB.js");
|
|
275
|
+
var { host, loadProject } = await import("./project-NWT5MDQI.js");
|
|
276
|
+
var { USAGE, folderArgs, isHelp, optionsOf, parse, run: run2, webOptions } = await import("./run-CTVGU7EK.js");
|
|
277
|
+
var locks = createLocks(base, path3.join(os.homedir(), ".cache/aula/heavy.lock"));
|
|
213
278
|
var render = createRender(base, process.execPath);
|
|
214
|
-
var models =
|
|
215
|
-
var narrator =
|
|
279
|
+
var models = path3.join(os.homedir(), ".cache/aula/models");
|
|
280
|
+
var narrator = createAulaVoice(base, fetch, models);
|
|
216
281
|
var capabilities = Capabilities.extend(
|
|
217
282
|
base,
|
|
218
283
|
Capabilities.create({
|
|
@@ -231,7 +296,7 @@ async function main(argv) {
|
|
|
231
296
|
}
|
|
232
297
|
const args = parse(rest, optionsOf(command));
|
|
233
298
|
if (command === "web") {
|
|
234
|
-
const { serve } = await import("./server-
|
|
299
|
+
const { serve } = await import("./server-5OGXX6BF.js");
|
|
235
300
|
const stop = new AbortController();
|
|
236
301
|
for (const signal of ["SIGINT", "SIGTERM"]) process.once(signal, () => stop.abort());
|
|
237
302
|
const web = Capabilities.create({
|
|
@@ -247,7 +312,7 @@ async function main(argv) {
|
|
|
247
312
|
return 0;
|
|
248
313
|
}
|
|
249
314
|
if (command === "tokens") {
|
|
250
|
-
const { tokens, tokensArgs } = await import("./commands-
|
|
315
|
+
const { tokens, tokensArgs } = await import("./commands-M246OWYJ.js");
|
|
251
316
|
tokensArgs(args.positional);
|
|
252
317
|
const tokensOf = createTokens();
|
|
253
318
|
return await tokens(capabilities, tokensOf, createInterface({ input: process.stdin, crlfDelay: Infinity })) ? 0 : 1;
|
|
@@ -7,15 +7,14 @@ import {
|
|
|
7
7
|
timeline,
|
|
8
8
|
tokens,
|
|
9
9
|
tokensArgs
|
|
10
|
-
} from "./chunk-
|
|
10
|
+
} from "./chunk-QWNBVWUQ.js";
|
|
11
11
|
import "./chunk-GFCJYE75.js";
|
|
12
12
|
import "./chunk-2XGNOG2U.js";
|
|
13
|
-
import "./chunk-
|
|
14
|
-
import "./chunk-
|
|
15
|
-
import "./chunk-
|
|
16
|
-
import "./chunk-
|
|
17
|
-
import "./chunk-
|
|
18
|
-
import "./chunk-PYRORQA5.js";
|
|
13
|
+
import "./chunk-IAQZ6DTC.js";
|
|
14
|
+
import "./chunk-XUBCUJW5.js";
|
|
15
|
+
import "./chunk-YX73KJQ6.js";
|
|
16
|
+
import "./chunk-46KT47TH.js";
|
|
17
|
+
import "./chunk-7KT36JRP.js";
|
|
19
18
|
export {
|
|
20
19
|
bundle,
|
|
21
20
|
check,
|