@beff/aula-cli 0.1.0 → 0.2.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.
Files changed (34) hide show
  1. package/README.md +2 -2
  2. package/dist/src/aula-render.core.wasm +0 -0
  3. package/dist/src/{chunk-3IBMAZRS.js → chunk-46KT47TH.js} +1 -1
  4. package/dist/src/{chunk-SDFXIMLW.js → chunk-7KT36JRP.js} +312 -113
  5. package/dist/src/chunk-BMP6H3SZ.js +104 -0
  6. package/dist/src/{chunk-OMBYV6CK.js → chunk-D2BDOCX7.js} +56 -14
  7. package/dist/src/{chunk-UREQAEFC.js → chunk-PSI7MMGP.js} +9 -226
  8. package/dist/src/{chunk-EYXQ2I7K.js → chunk-SW5BNPAM.js} +10 -36
  9. package/dist/src/cli.js +81 -16
  10. package/dist/src/{commands-VDGWDVWT.js → commands-CEBO6WWE.js} +6 -7
  11. package/dist/src/problems-FFAR72WZ.js +12 -0
  12. package/dist/src/{project-M63R4ENB.js → project-NWT5MDQI.js} +2 -2
  13. package/dist/src/{run-CY72QGZJ.js → run-DU2H6FZI.js} +10 -10
  14. package/dist/src/{server-ZG6K7Z7H.js → server-7AN6XCTF.js} +6 -66
  15. package/dist/web/app/assets/__vite-browser-external-B6HdzU1j.js +1 -0
  16. package/dist/web/app/assets/aula-method.js +1 -1
  17. package/dist/web/app/assets/{aula-voice-worker-BL6WcrSe.js → aula-voice-worker-DNzLI-en.js} +10 -10
  18. package/dist/web/app/assets/{aula.core5-BdGB-M10.wasm → aula.core5-BmrvjVro.wasm} +0 -0
  19. package/dist/web/app/assets/aula.js +1 -1
  20. package/dist/web/app/assets/build-worker.js +8 -9
  21. package/dist/web/app/assets/index-D6yaOVRx.js +53 -0
  22. package/dist/web/app/assets/index-cL-Dm_aw.css +2 -0
  23. package/dist/web/app/assets/protocol-CDkth-6D.js +15 -0
  24. package/dist/web/app/assets/{src-BbJ5r410.js → src-B22P60S6.js} +6 -6
  25. package/dist/web/app/index.html +4 -4
  26. package/package.json +2 -2
  27. package/dist/src/chunk-KLE5UOUB.js +0 -57
  28. package/dist/src/chunk-PYRORQA5.js +0 -88
  29. package/dist/src/chunk-X3HJY34X.js +0 -81
  30. package/dist/src/problems-OGUR4BLZ.js +0 -12
  31. package/dist/web/app/assets/__vite-browser-external-Bbi05A7N.js +0 -1
  32. package/dist/web/app/assets/index-BVQqteYG.js +0 -53
  33. package/dist/web/app/assets/index-CS60sOpp.css +0 -2
  34. package/dist/web/app/assets/protocol-Ds4jI5bY.js +0 -15
@@ -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-UREQAEFC.js";
25
- import {
26
- Parsers as Parsers2
27
- } from "./chunk-KLE5UOUB.js";
22
+ } from "./chunk-PSI7MMGP.js";
28
23
  import {
29
24
  narrateScript,
30
25
  scriptAudio,
31
26
  wav
32
- } from "./chunk-SDFXIMLW.js";
27
+ } from "./chunk-BMP6H3SZ.js";
33
28
  import {
34
29
  host
35
- } from "./chunk-3IBMAZRS.js";
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-PYRORQA5.js";
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(capabilities.narrator, chapters, (spoken, count, cue) => {
814
- capabilities.log.out(`[${String(spoken)}/${String(count)}] Narrating: ${cue.text.slice(0, 70)}`);
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) {
@@ -909,7 +951,7 @@ async function preview(capabilities, root, project, folder, given) {
909
951
  await printChecked(capabilities, root, project, checked);
910
952
  if (checked.errors > 0) return false;
911
953
  const all = checked.texts;
912
- const n = await clock(capabilities.narrator, narrationScript(project.title, all));
954
+ const n = await clock(capabilities.narrator, narrationScript(project, all));
913
955
  const jobs = previewJobs(targets, all).map((job) => ({
914
956
  ...job,
915
957
  out: path2.join(folder, job.base),
@@ -958,7 +1000,7 @@ async function exportVideo(capabilities, root, project, file) {
958
1000
  await ffmpeg(capabilities, ["-version"]);
959
1001
  return withWork(capabilities, async (work) => {
960
1002
  const audio = path2.join(work, "narration.wav");
961
- const cues = narrationScript(project.title, checked.texts);
1003
+ const cues = narrationScript(project, checked.texts);
962
1004
  const narrated = await withHeavy(capabilities, () => narrate(capabilities, cues));
963
1005
  const lotties = names.map((name) => path2.join(work, `${name}.json`));
964
1006
  const drawn = [];
@@ -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-SDFXIMLW.js";
3
+ } from "./chunk-BMP6H3SZ.js";
11
4
  import {
12
5
  Problems,
13
6
  error,
14
7
  isError,
15
8
  withSource,
16
9
  wrongArgument
17
- } from "./chunk-PYRORQA5.js";
10
+ } from "./chunk-7KT36JRP.js";
18
11
 
19
12
  // src/problems.ts
20
13
  import { loadEngine as loadEngine2 } from "@beff/aula/run";
@@ -68,14 +61,14 @@ function openCount(chapters, indexes) {
68
61
  }
69
62
 
70
63
  // ../aula-project/src/check.ts
71
- import { checkChapter, readChapter as readChapter2 } from "@beff/aula";
64
+ import { checkChapter, checkLexicon, readChapter as readChapter2 } from "@beff/aula";
72
65
  import { chapterNames } from "@beff/aula/run";
73
66
  import { check as rules } from "@beff/aula/text";
74
67
  async function clock(narrator, chapters) {
75
68
  const narrations = [];
76
69
  for (const cues of chapters) {
77
70
  const timings = [];
78
- for (const cue of cues) timings.push(await narrator.time(cue.text, cue.speed));
71
+ for (const cue of cues) timings.push(await narrator.time(cue.spoken, cue.speed));
79
72
  narrations.push(timeChapter(cues, timings));
80
73
  }
81
74
  return narrations;
@@ -107,7 +100,10 @@ function checkProject(project, host, only) {
107
100
  }
108
101
  }
109
102
  const byChapter = [...unloaded, ...[...own].toSorted(([a], [b]) => a - b)];
110
- const reported = byChapter.flatMap(([index, d]) => inScope(index) ? d : []);
103
+ const reported = [
104
+ ...checkLexicon(project, { host }),
105
+ ...byChapter.flatMap(([index, d]) => inScope(index) ? d : [])
106
+ ];
111
107
  const elsewhere = byChapter.flatMap(([index, d]) => inScope(index) ? [] : d);
112
108
  const errors = reported.filter(isError).length;
113
109
  const otherErrors = elsewhere.filter(isError).length;
@@ -230,7 +226,7 @@ async function timelineView(project, host, narrator, only) {
230
226
  const names = chapterNames3(project);
231
227
  const indexes = only.length === 0 ? project.chapters.map((_, i) => i + 1) : only.map((name) => chapterIndex(names, name));
232
228
  if (indexes.includes(0)) throw wrongArgument("the title card has no timeline: give a chapter name");
233
- const n = await clock(narrator, narrationScript(project.title, texts(project, host)));
229
+ const n = await clock(narrator, narrationScript(project, texts(project, host)));
234
230
  let out = header(project);
235
231
  for (const index of indexes) {
236
232
  const text = chapterText(project, host, index);
@@ -253,217 +249,6 @@ import {
253
249
  narrationScript as narrationScript2
254
250
  } from "@beff/aula/text";
255
251
 
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
252
  // src/problems.ts
468
253
  async function printDiagnostics(capabilities, root, diagnostics, print = (text) => capabilities.log.out(text)) {
469
254
  await loadEngine2();
@@ -485,7 +270,5 @@ export {
485
270
  pictureGroups,
486
271
  movesMarkdown,
487
272
  timelineView,
488
- Parsers,
489
- bundle,
490
273
  printDiagnostics
491
274
  };
@@ -1,6 +1,7 @@
1
1
  // ../aula-narration/src/align.ts
2
+ var WORD = /(?:\[[^\][\s]*\]\(\/[^/]*\/\)|\S)+/g;
2
3
  function tokens(text) {
3
- return [...text.matchAll(/\S+/g)].map((match) => ({ text: match[0], char: match.index }));
4
+ return [...text.matchAll(WORD)].map((match) => ({ text: match[0], char: match.index }));
4
5
  }
5
6
  function roundHalfEven(value) {
6
7
  const floor = Math.floor(value);
@@ -282,28 +283,28 @@ var KOKORO_VOCAB = /* @__PURE__ */ new Map([
282
283
  ]);
283
284
 
284
285
  // ../aula-narration/src/aula-voice.ts
285
- var AULA_VOICE_RELEASE = "v0.1.1";
286
+ var AULA_VOICE_RELEASE = "v0.1.2";
286
287
  var RELEASE_URL = `https://github.com/lucasavila00/aula-voice/releases/download/${AULA_VOICE_RELEASE}`;
287
288
  var AULA_VOICE_FILES = {
288
289
  model: {
289
290
  path: "model.safetensors",
290
291
  bytes: 33489768,
291
- sha256: "a15b9b378ee1e7d24004a4f5ff6ab03459fadec71d0acdf02d0e04034edde44a"
292
+ sha256: "862806a3dfb10196f1bdfedf08ae43ed9b640b969398ac9d37f8670586c57c6a"
292
293
  },
293
294
  config: {
294
295
  path: "config.json",
295
296
  bytes: 2346,
296
- sha256: "e5ea44e7d8ef2fe114725162aa68a4e57f1525cf4c206f9ac2f2db70ed051909"
297
+ sha256: "f297213a0673974916d9c309260f01a8259d36b0d595d66ed57668cc6eea4da3"
297
298
  }
298
299
  };
299
300
  var AULA_VOICE_WEIGHTS = {
300
301
  path: "aula-voice.avw",
301
302
  bytes: 33478208,
302
- sha256: "b382770c55637371fd5f0eda9f7f5a9b39572c8715d24149bfbba4d8c64ac951"
303
+ sha256: "519b3e3cff634d6dd8edec9fe322da64cdf184f866bb0c101dc364d9874c8440"
303
304
  };
304
305
  var SERVER_WEIGHTS_PATH = `/models/${AULA_VOICE_WEIGHTS.path}`;
305
306
  var aulaVoiceUrl = (file) => `${RELEASE_URL}/${file.path}`;
306
- var VOICE = { name: "bf_emma", index: 0 };
307
+ var VOICE = 0;
307
308
  var SAMPLE_RATE = 24e3;
308
309
  var HOP = 300;
309
310
  var MAX_TOKENS = 250;
@@ -326,7 +327,7 @@ async function layout(parts, text, speed, audio) {
326
327
  const { ids, known } = tokenize(KOKORO_VOCAB, batch);
327
328
  if (!ids.length) throw new Error(`No phonemes of ${JSON.stringify(batch)} are in the model's token table`);
328
329
  const padded = [0, ...ids, 0];
329
- const spoken = audio ? parts.model.speak(padded, VOICE.index, speed) : { audio: null, durations: parts.model.durations(padded, VOICE.index, speed) };
330
+ const spoken = audio ? parts.model.speak(padded, VOICE, speed) : { audio: null, durations: parts.model.durations(padded, VOICE, speed) };
330
331
  const edges = [0];
331
332
  for (let i = 0; i < spoken.durations.length; i++) edges.push((edges[i] ?? 0) + Number(spoken.durations[i]) * HOP);
332
333
  const head = Math.max((edges[1] ?? 0) - LEAD * HOP, 0);
@@ -356,7 +357,6 @@ async function timeAulaVoice(parts, text, speed) {
356
357
  const { total, words } = await layout(parts, text, speed, false);
357
358
  return { samples: total, sampleRate: SAMPLE_RATE, words };
358
359
  }
359
- var aulaVoiceId = (backend) => `aula-voice@${AULA_VOICE_RELEASE}+${AULA_VOICE_WEIGHTS.sha256.slice(0, 12)}/${VOICE.name}/${backend}`;
360
360
 
361
361
  // ../aula-narration/src/avw.ts
362
362
  var FIXED = {
@@ -553,33 +553,6 @@ function studentWeightFile(model, config) {
553
553
  return file;
554
554
  }
555
555
 
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
556
  // ../aula-narration/src/phonemize.ts
584
557
  import { loadEngine } from "@beff/aula/run";
585
558
  import { phonemize } from "@beff/aula/text";
@@ -598,7 +571,8 @@ export {
598
571
  AULA_VOICE_WEIGHTS,
599
572
  SERVER_WEIGHTS_PATH,
600
573
  aulaVoiceUrl,
574
+ speakAulaVoice,
575
+ timeAulaVoice,
601
576
  studentWeightFile,
602
- aulaVoiceNarrator,
603
577
  britishPhonemizer
604
578
  };
package/dist/src/cli.js CHANGED
@@ -4,11 +4,17 @@ import {
4
4
  status
5
5
  } from "./chunk-2XGNOG2U.js";
6
6
  import {
7
- aulaVoiceWeightFile,
8
- createAulaVoice,
9
- textTokens
10
- } from "./chunk-X3HJY34X.js";
11
- import "./chunk-EYXQ2I7K.js";
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-SW5BNPAM.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 path2 from "node:path";
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 createAulaVoice2(capabilities2, fetch2, models2) {
181
- return createAulaVoice(capabilities2, options(capabilities2, fetch2, models2));
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-OGUR4BLZ.js");
210
- var { host, loadProject } = await import("./project-M63R4ENB.js");
211
- var { USAGE, folderArgs, isHelp, optionsOf, parse, run: run2, webOptions } = await import("./run-CY72QGZJ.js");
212
- var locks = createLocks(base, path2.join(os.homedir(), ".cache/aula/heavy.lock"));
274
+ var { diagnosticsOf, printDiagnostics } = await import("./problems-FFAR72WZ.js");
275
+ var { host, loadProject } = await import("./project-NWT5MDQI.js");
276
+ var { USAGE, folderArgs, isHelp, optionsOf, parse, run: run2, webOptions } = await import("./run-DU2H6FZI.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 = path2.join(os.homedir(), ".cache/aula/models");
215
- var narrator = createAulaVoice2(base, fetch, models);
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-ZG6K7Z7H.js");
299
+ const { serve } = await import("./server-7AN6XCTF.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-VDGWDVWT.js");
315
+ const { tokens, tokensArgs } = await import("./commands-CEBO6WWE.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-OMBYV6CK.js";
10
+ } from "./chunk-D2BDOCX7.js";
11
11
  import "./chunk-GFCJYE75.js";
12
12
  import "./chunk-2XGNOG2U.js";
13
- import "./chunk-UREQAEFC.js";
14
- import "./chunk-KLE5UOUB.js";
15
- import "./chunk-SDFXIMLW.js";
16
- import "./chunk-EYXQ2I7K.js";
17
- import "./chunk-3IBMAZRS.js";
18
- import "./chunk-PYRORQA5.js";
13
+ import "./chunk-PSI7MMGP.js";
14
+ import "./chunk-BMP6H3SZ.js";
15
+ import "./chunk-SW5BNPAM.js";
16
+ import "./chunk-46KT47TH.js";
17
+ import "./chunk-7KT36JRP.js";
19
18
  export {
20
19
  bundle,
21
20
  check,
@@ -0,0 +1,12 @@
1
+ import {
2
+ printDiagnostics
3
+ } from "./chunk-PSI7MMGP.js";
4
+ import "./chunk-BMP6H3SZ.js";
5
+ import "./chunk-SW5BNPAM.js";
6
+ import {
7
+ diagnosticsOf
8
+ } from "./chunk-7KT36JRP.js";
9
+ export {
10
+ diagnosticsOf,
11
+ printDiagnostics
12
+ };