@beff/aula-cli 0.0.1 → 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 +11 -1
- package/dist/licenses/aula-g2p-NOTICE.txt +13 -0
- package/dist/licenses/espeak-ng-COPYING.txt +674 -0
- package/dist/licenses/fonts-OFL-JetBrainsMono.txt +93 -0
- package/dist/licenses/fonts-OFL-NunitoSans.txt +93 -0
- package/dist/src/aula-render.core.wasm +0 -0
- package/dist/src/aula-voice-tts-ZXQ7XXHJ.js +14 -0
- package/dist/src/chunk-2XGNOG2U.js +28 -0
- package/dist/src/chunk-46KT47TH.js +21 -0
- package/dist/src/chunk-7KT36JRP.js +1282 -0
- package/dist/src/chunk-GFCJYE75.js +42 -0
- package/dist/src/chunk-IAQZ6DTC.js +271 -0
- package/dist/src/chunk-QWNBVWUQ.js +1105 -0
- package/dist/src/chunk-XUBCUJW5.js +104 -0
- package/dist/src/chunk-YX73KJQ6.js +577 -0
- package/dist/src/cli.js +334 -0
- package/dist/src/commands-M246OWYJ.js +27 -0
- package/dist/src/problems-Y67BY7WB.js +12 -0
- package/dist/src/project-NWT5MDQI.js +11 -0
- package/dist/src/render-child.js +3771 -0
- package/dist/src/run-CTVGU7EK.js +127 -0
- package/dist/src/server-5OGXX6BF.js +220 -0
- package/dist/web/app/assets/__vite-browser-external-BN30sEqc.js +1 -0
- package/dist/web/app/assets/__vite-browser-external-BtQTJ51O.js +1 -0
- package/dist/web/app/assets/aula-method.js +1 -0
- package/dist/web/app/assets/aula-voice-worker-DymX5vwM.js +52 -0
- package/dist/web/app/assets/aula.core-BtiPQSZi.wasm +0 -0
- package/dist/web/app/assets/aula.core5-YhDIb7Me.wasm +0 -0
- package/dist/web/app/assets/aula.js +1 -0
- package/dist/web/app/assets/build-worker.js +696 -0
- package/dist/web/app/assets/esbuild-BaXVPFT2.wasm +0 -0
- 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/rolldown-runtime-BLXQ4ufn.js +1 -0
- package/dist/web/app/assets/src-CmWmmzpF.js +25 -0
- package/dist/web/app/index.html +15 -0
- package/package.json +27 -5
package/dist/src/cli.js
ADDED
|
@@ -0,0 +1,334 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import {
|
|
3
|
+
run,
|
|
4
|
+
status
|
|
5
|
+
} from "./chunk-2XGNOG2U.js";
|
|
6
|
+
import {
|
|
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";
|
|
18
|
+
|
|
19
|
+
// src/cli.ts
|
|
20
|
+
import { spawn } from "node:child_process";
|
|
21
|
+
import { existsSync, watch } from "node:fs";
|
|
22
|
+
import * as fs from "node:fs/promises";
|
|
23
|
+
import os from "node:os";
|
|
24
|
+
import { createInterface } from "node:readline";
|
|
25
|
+
import path3 from "node:path";
|
|
26
|
+
|
|
27
|
+
// ../../node_modules/.pnpm/@beff+diy@0.0.36/node_modules/@beff/diy/dist/esm/capabilities.js
|
|
28
|
+
function create(serviceMap) {
|
|
29
|
+
return serviceMap;
|
|
30
|
+
}
|
|
31
|
+
function extend(capabilities2, extra) {
|
|
32
|
+
return Object.assign({}, capabilities2, extra);
|
|
33
|
+
}
|
|
34
|
+
function override(capabilities2, replacement) {
|
|
35
|
+
return { ...capabilities2, ...replacement };
|
|
36
|
+
}
|
|
37
|
+
function merge(...capabilitiesList) {
|
|
38
|
+
return Object.assign({}, ...capabilitiesList);
|
|
39
|
+
}
|
|
40
|
+
var Capabilities = {
|
|
41
|
+
/**
|
|
42
|
+
* Build the app's concrete services.
|
|
43
|
+
*
|
|
44
|
+
* @example
|
|
45
|
+
* ```ts
|
|
46
|
+
* const capabilities = Capabilities.create<AppCapability>({
|
|
47
|
+
* clock: { now: () => new Date() },
|
|
48
|
+
* fs,
|
|
49
|
+
* });
|
|
50
|
+
* ```
|
|
51
|
+
*/
|
|
52
|
+
create,
|
|
53
|
+
/**
|
|
54
|
+
* Add scoped services around an existing bag.
|
|
55
|
+
*
|
|
56
|
+
* @example
|
|
57
|
+
* ```ts
|
|
58
|
+
* const jobCapabilities = Capabilities.extend(
|
|
59
|
+
* capabilities,
|
|
60
|
+
* Capabilities.create<ProgressCapability>({ progress }),
|
|
61
|
+
* );
|
|
62
|
+
* ```
|
|
63
|
+
*/
|
|
64
|
+
extend,
|
|
65
|
+
/**
|
|
66
|
+
* Combine capability bags built by separate modules.
|
|
67
|
+
*
|
|
68
|
+
* @example
|
|
69
|
+
* ```ts
|
|
70
|
+
* const appCapabilities = Capabilities.merge(nodeCapabilities, databaseCapabilities);
|
|
71
|
+
* ```
|
|
72
|
+
*/
|
|
73
|
+
merge,
|
|
74
|
+
/**
|
|
75
|
+
* Replace services without changing the capability type.
|
|
76
|
+
*
|
|
77
|
+
* @example
|
|
78
|
+
* ```ts
|
|
79
|
+
* const quietCapabilities = Capabilities.override(capabilities, {
|
|
80
|
+
* logger: { info: () => undefined },
|
|
81
|
+
* });
|
|
82
|
+
* ```
|
|
83
|
+
*/
|
|
84
|
+
override
|
|
85
|
+
};
|
|
86
|
+
|
|
87
|
+
// src/locks.ts
|
|
88
|
+
import path from "node:path";
|
|
89
|
+
import { DatabaseSync } from "node:sqlite";
|
|
90
|
+
import { setTimeout as sleep } from "node:timers/promises";
|
|
91
|
+
var RETRY = 250;
|
|
92
|
+
var YIELD = 4 * RETRY;
|
|
93
|
+
var SQLITE_BUSY = 5;
|
|
94
|
+
function tryLock(file) {
|
|
95
|
+
const db = new DatabaseSync(file, { timeout: 0 });
|
|
96
|
+
try {
|
|
97
|
+
db.exec("BEGIN EXCLUSIVE");
|
|
98
|
+
return db;
|
|
99
|
+
} catch (e) {
|
|
100
|
+
db.close();
|
|
101
|
+
if (e instanceof Error && "errcode" in e && e.errcode === SQLITE_BUSY) return null;
|
|
102
|
+
throw e;
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
function createLocks(capabilities2, file) {
|
|
106
|
+
const heavy = {
|
|
107
|
+
count: 0,
|
|
108
|
+
held: null,
|
|
109
|
+
waiting: false,
|
|
110
|
+
/** When this process last released it (clock milliseconds). */
|
|
111
|
+
released: null
|
|
112
|
+
};
|
|
113
|
+
const acquireHeavy = async () => {
|
|
114
|
+
await capabilities2.fs.mkdir(path.dirname(file), { recursive: true });
|
|
115
|
+
if (heavy.released !== null) {
|
|
116
|
+
const left = heavy.released + YIELD - capabilities2.clock.now();
|
|
117
|
+
if (left > 0) await sleep(left);
|
|
118
|
+
}
|
|
119
|
+
for (; ; ) {
|
|
120
|
+
const db = tryLock(file);
|
|
121
|
+
if (db !== null) {
|
|
122
|
+
if (heavy.waiting) capabilities2.log.err("Acquired lock 'heavy'");
|
|
123
|
+
return db;
|
|
124
|
+
}
|
|
125
|
+
if (!heavy.waiting) {
|
|
126
|
+
heavy.waiting = true;
|
|
127
|
+
capabilities2.log.err(`Waiting for lock 'heavy': ${file}`);
|
|
128
|
+
}
|
|
129
|
+
await sleep(RETRY);
|
|
130
|
+
}
|
|
131
|
+
};
|
|
132
|
+
return {
|
|
133
|
+
async heavy() {
|
|
134
|
+
let held;
|
|
135
|
+
do {
|
|
136
|
+
held = heavy.held ??= acquireHeavy();
|
|
137
|
+
await held;
|
|
138
|
+
} while (heavy.held !== held);
|
|
139
|
+
heavy.count += 1;
|
|
140
|
+
let released = false;
|
|
141
|
+
return async () => {
|
|
142
|
+
if (released) return;
|
|
143
|
+
released = true;
|
|
144
|
+
heavy.count -= 1;
|
|
145
|
+
if (heavy.count > 0) return;
|
|
146
|
+
heavy.held = null;
|
|
147
|
+
heavy.waiting = false;
|
|
148
|
+
(await held).close();
|
|
149
|
+
heavy.released = capabilities2.clock.now();
|
|
150
|
+
};
|
|
151
|
+
}
|
|
152
|
+
};
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
// src/render.ts
|
|
156
|
+
import { fileURLToPath } from "node:url";
|
|
157
|
+
var CHILD = fileURLToPath(
|
|
158
|
+
new URL(import.meta.url.endsWith(".ts") ? "render-child.ts" : "render-child.js", import.meta.url)
|
|
159
|
+
);
|
|
160
|
+
function createRender(capabilities2, node) {
|
|
161
|
+
const job = async (kind, value) => {
|
|
162
|
+
const ran = await run(capabilities2, node, [CHILD, kind, JSON.stringify(value)]);
|
|
163
|
+
if (ran.code !== 0) throw new Error(ran.stderr.trim() || `render ${value.lottie} failed (${status(ran)})`);
|
|
164
|
+
return ran.stdout;
|
|
165
|
+
};
|
|
166
|
+
return {
|
|
167
|
+
async pictures(pictures) {
|
|
168
|
+
return (await job("pictures", pictures)).split("\n").filter(Boolean);
|
|
169
|
+
},
|
|
170
|
+
async clip(clip) {
|
|
171
|
+
await job("clip", clip);
|
|
172
|
+
}
|
|
173
|
+
};
|
|
174
|
+
}
|
|
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
|
+
|
|
235
|
+
// src/aula-voice.ts
|
|
236
|
+
function options(capabilities2, fetch2, models2) {
|
|
237
|
+
return {
|
|
238
|
+
fetch: fetch2,
|
|
239
|
+
models: models2,
|
|
240
|
+
downloading: (file) => {
|
|
241
|
+
capabilities2.log.err(`Downloading ${file} of aula-voice`);
|
|
242
|
+
}
|
|
243
|
+
};
|
|
244
|
+
}
|
|
245
|
+
function createAulaVoice(capabilities2, fetch2, models2) {
|
|
246
|
+
return aulaVoice(capabilities2, options(capabilities2, fetch2, models2));
|
|
247
|
+
}
|
|
248
|
+
function aulaVoiceWeights(capabilities2, fetch2, models2) {
|
|
249
|
+
return () => aulaVoiceWeightFile(capabilities2, options(capabilities2, fetch2, models2));
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
// src/tokens.ts
|
|
253
|
+
function createTokens() {
|
|
254
|
+
return textTokens();
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
// src/cli.ts
|
|
258
|
+
process.stdout.on("error", (e) => {
|
|
259
|
+
if (e.code !== "EPIPE") throw e;
|
|
260
|
+
});
|
|
261
|
+
var base = Capabilities.create({
|
|
262
|
+
clock: { now: () => performance.now(), timeout: (seconds) => AbortSignal.timeout(Math.ceil(seconds * 1e3)) },
|
|
263
|
+
env: { variables: process.env, temp: os.tmpdir(), parallelism: os.availableParallelism() },
|
|
264
|
+
fs: { ...fs, existsSync },
|
|
265
|
+
log: {
|
|
266
|
+
out: (line) => process.stdout.write(`${line}
|
|
267
|
+
`),
|
|
268
|
+
write: (text) => process.stdout.write(text),
|
|
269
|
+
err: (line) => process.stderr.write(`${line}
|
|
270
|
+
`)
|
|
271
|
+
},
|
|
272
|
+
spawn
|
|
273
|
+
});
|
|
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"));
|
|
278
|
+
var render = createRender(base, process.execPath);
|
|
279
|
+
var models = path3.join(os.homedir(), ".cache/aula/models");
|
|
280
|
+
var narrator = createAulaVoice(base, fetch, models);
|
|
281
|
+
var capabilities = Capabilities.extend(
|
|
282
|
+
base,
|
|
283
|
+
Capabilities.create({
|
|
284
|
+
locks,
|
|
285
|
+
narrator,
|
|
286
|
+
render
|
|
287
|
+
})
|
|
288
|
+
);
|
|
289
|
+
var cwd = process.cwd();
|
|
290
|
+
async function main(argv) {
|
|
291
|
+
const [command, ...rest] = argv;
|
|
292
|
+
if (command === void 0) throw new Error(USAGE);
|
|
293
|
+
if (isHelp(command)) {
|
|
294
|
+
capabilities.log.out(USAGE);
|
|
295
|
+
return 0;
|
|
296
|
+
}
|
|
297
|
+
const args = parse(rest, optionsOf(command));
|
|
298
|
+
if (command === "web") {
|
|
299
|
+
const { serve } = await import("./server-5OGXX6BF.js");
|
|
300
|
+
const stop = new AbortController();
|
|
301
|
+
for (const signal of ["SIGINT", "SIGTERM"]) process.once(signal, () => stop.abort());
|
|
302
|
+
const web = Capabilities.create({
|
|
303
|
+
weights: aulaVoiceWeights(base, fetch, models),
|
|
304
|
+
watch: (folder2, changed) => {
|
|
305
|
+
if (!existsSync(folder2)) return { close: () => void 0 };
|
|
306
|
+
const watcher = watch(folder2, () => changed());
|
|
307
|
+
watcher.on("error", () => changed());
|
|
308
|
+
return watcher;
|
|
309
|
+
}
|
|
310
|
+
});
|
|
311
|
+
await serve(Capabilities.extend(capabilities, web), { ...webOptions(cwd, args), stop: stop.signal });
|
|
312
|
+
return 0;
|
|
313
|
+
}
|
|
314
|
+
if (command === "tokens") {
|
|
315
|
+
const { tokens, tokensArgs } = await import("./commands-M246OWYJ.js");
|
|
316
|
+
tokensArgs(args.positional);
|
|
317
|
+
const tokensOf = createTokens();
|
|
318
|
+
return await tokens(capabilities, tokensOf, createInterface({ input: process.stdin, crlfDelay: Infinity })) ? 0 : 1;
|
|
319
|
+
}
|
|
320
|
+
const { folder, rest: after } = folderArgs(cwd, command, args);
|
|
321
|
+
const project = await loadProject(capabilities, cwd, folder);
|
|
322
|
+
return await run2(capabilities, cwd, command, project, after) ? 0 : 1;
|
|
323
|
+
}
|
|
324
|
+
try {
|
|
325
|
+
process.exitCode = await main(process.argv.slice(2));
|
|
326
|
+
} catch (e) {
|
|
327
|
+
await printDiagnostics(
|
|
328
|
+
capabilities,
|
|
329
|
+
cwd,
|
|
330
|
+
diagnosticsOf(e, host(capabilities, cwd)),
|
|
331
|
+
(text) => capabilities.log.err(text.trimEnd())
|
|
332
|
+
);
|
|
333
|
+
process.exitCode = 1;
|
|
334
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import {
|
|
2
|
+
bundle,
|
|
3
|
+
check,
|
|
4
|
+
exportVideo,
|
|
5
|
+
preview,
|
|
6
|
+
script,
|
|
7
|
+
timeline,
|
|
8
|
+
tokens,
|
|
9
|
+
tokensArgs
|
|
10
|
+
} from "./chunk-QWNBVWUQ.js";
|
|
11
|
+
import "./chunk-GFCJYE75.js";
|
|
12
|
+
import "./chunk-2XGNOG2U.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";
|
|
18
|
+
export {
|
|
19
|
+
bundle,
|
|
20
|
+
check,
|
|
21
|
+
exportVideo,
|
|
22
|
+
preview,
|
|
23
|
+
script,
|
|
24
|
+
timeline,
|
|
25
|
+
tokens,
|
|
26
|
+
tokensArgs
|
|
27
|
+
};
|