@beff/aula 0.1.1 → 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.
@@ -213,7 +213,7 @@ export function wait(): Animation;
213
213
  export function settle(anims: Array<Animation>): void;
214
214
  export function constants(): EngineConstants;
215
215
  export function scriptMarkdown(title: string, texts: Array<ChapterText>): string;
216
- export function narrationScript(title: string, texts: Array<ChapterText>): Array<Array<ScriptCue>>;
216
+ export function narrationScript(title: string, lexicon: Array<LexiconEntry>, texts: Array<ChapterText>): Array<Array<ScriptCue>>;
217
217
  /**
218
218
  * @throws {Error & { payload: Diagnostic }} The error of the result, as the `payload` of the thrown error.
219
219
  */
@@ -228,7 +228,8 @@ export function fps(): number;
228
228
  /**
229
229
  * @throws {Error & { payload: Diagnostic }} The error of the result, as the `payload` of the thrown error.
230
230
  */
231
- export function phonemize(text: string): string;
231
+ export function phonemize(text: string, lexicon: Array<LexiconEntry>): string;
232
+ export function checkLexicon(place: Location, entries: Array<LexiconEntry>): Array<Diagnostic>;
232
233
  /**
233
234
  * @throws {Error & { payload: Diagnostic }} The error of the result, as the `payload` of the thrown error.
234
235
  */
@@ -539,6 +540,23 @@ export interface NarrationWait {
539
540
  sample: number,
540
541
  samples: number,
541
542
  }
543
+ export type Pronunciation = PronunciationWords | PronunciationPhonemes;
544
+ export interface PronunciationWords {
545
+ tag: 'words',
546
+ val: string,
547
+ }
548
+ export interface PronunciationPhonemes {
549
+ tag: 'phonemes',
550
+ val: string,
551
+ }
552
+ export interface SayPart {
553
+ text: string,
554
+ reading?: Pronunciation,
555
+ }
556
+ export interface LexiconEntry {
557
+ word: string,
558
+ reading: Pronunciation,
559
+ }
542
560
  /**
543
561
  * # Variants
544
562
  *
@@ -551,6 +569,7 @@ export interface NarrationWait {
551
569
  export type CueKind = "title" | "heading" | "paragraph";
552
570
  export interface ScriptCue {
553
571
  text: string,
572
+ spoken: string,
554
573
  kind: CueKind,
555
574
  place?: string,
556
575
  leadIn: number,
@@ -664,7 +683,8 @@ export class Chapter implements Disposable {
664
683
  /**
665
684
  * @throws {Error & { payload: Diagnostic }} The error of the result, as the `payload` of the thrown error.
666
685
  */
667
- say(place: Location, text: string): void;
686
+ say(place: Location, parts: Array<SayPart>): void;
687
+ lexicon(entries: Array<LexiconEntry>): void;
668
688
  /**
669
689
  * @throws {Error & { payload: Diagnostic }} The error of the result, as the `payload` of the thrown error.
670
690
  */
@@ -38,6 +38,7 @@ export interface Note {
38
38
  export interface Say {
39
39
  place: Location,
40
40
  text: string,
41
+ spoken: string,
41
42
  }
42
43
  export interface Move {
43
44
  place: Location,
package/dist/index.d.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  export * as m from "./manim.ts";
2
- export { defineChapter, defineProject, isProjectDefinition, paragraph, say, show, tagText } from "./engine.ts";
3
- export { checkChapter, readChapter, renderChapter, renderScene } from "./run.ts";
4
- export type { Card, ChapterDefinition, ChapterFields, ChapterRun, CheckedChapter, CheckedParagraph, Check, Finding, Heading, Notes, OpenMove, Leaf, SceneRun, Untimed, ProjectDefinition, ProjectFields, Instant, Row, Screen, Shown, } from "./engine.ts";
2
+ export { defineChapter, defineProject, isProjectDefinition, paragraph, pronounce, say, show, tagText, } from "./engine.ts";
3
+ export { checkChapter, checkLexicon, readChapter, renderChapter, renderScene } from "./run.ts";
4
+ export type { Card, ChapterDefinition, ChapterFields, ChapterRun, CheckedChapter, CheckedParagraph, Check, Finding, Heading, Notes, OpenMove, Leaf, Pronounce, Reading, SceneRun, Untimed, ProjectDefinition, ProjectFields, Instant, Row, Screen, Shown, } from "./engine.ts";
5
5
  export type { ChapterResult, Host, ReadOptions, RenderOptions, StackFrame } from "./run.ts";
6
+ export type { Lexicon } from "./lexicon.ts";
package/dist/index.js CHANGED
@@ -7,5 +7,5 @@
7
7
  // readChapter, checkChapter and renderChapter run a chapter, as the CLI and the web app do.
8
8
  // renderScene runs a Manim construct, with no narration.
9
9
  export * as m from "./manim.js";
10
- export { defineChapter, defineProject, isProjectDefinition, paragraph, say, show, tagText } from "./engine.js";
11
- export { checkChapter, readChapter, renderChapter, renderScene } from "./run.js";
10
+ export { defineChapter, defineProject, isProjectDefinition, paragraph, pronounce, say, show, tagText, } from "./engine.js";
11
+ export { checkChapter, checkLexicon, readChapter, renderChapter, renderScene } from "./run.js";
@@ -0,0 +1,10 @@
1
+ import type { Reading } from "./engine.ts";
2
+ import type { LexiconEntry } from "./generated/interfaces/aula-engine-engine.js";
3
+ /** The project lexicon: each key is a written word, and each value is its reading, the same
4
+ * object that `pronounce` takes. A kit exports one, and a project spreads it into its own. */
5
+ export type Lexicon = Readonly<Record<string, Reading>>;
6
+ /** The entries of `lexicon` in the engine's form, in the order of the object. An entry whose
7
+ * reading has the wrong form is left out: `badReadings` gives its key. */
8
+ export declare function lexiconEntries(lexicon: Lexicon): LexiconEntry[];
9
+ /** The keys of `lexicon` whose reading is not `{ say: string }` or `{ phonemes: string }`. */
10
+ export declare function badReadings(lexicon: Lexicon): string[];
@@ -0,0 +1,23 @@
1
+ /** A reading in the engine's form, or undefined when it is not `{ say: string }` or
2
+ * `{ phonemes: string }` (a value from JavaScript with no types). */
3
+ function rawReading(reading) {
4
+ if (typeof reading !== "object" || reading === null || Object.keys(reading).length !== 1)
5
+ return undefined;
6
+ if ("say" in reading && typeof reading.say === "string")
7
+ return { tag: "words", val: reading.say };
8
+ if ("phonemes" in reading && typeof reading.phonemes === "string")
9
+ return { tag: "phonemes", val: reading.phonemes };
10
+ return undefined;
11
+ }
12
+ /** The entries of `lexicon` in the engine's form, in the order of the object. An entry whose
13
+ * reading has the wrong form is left out: `badReadings` gives its key. */
14
+ export function lexiconEntries(lexicon) {
15
+ return Object.entries(lexicon).flatMap(([word, reading]) => {
16
+ const raw = rawReading(reading);
17
+ return raw === undefined ? [] : [{ word, reading: raw }];
18
+ });
19
+ }
20
+ /** The keys of `lexicon` whose reading is not `{ say: string }` or `{ phonemes: string }`. */
21
+ export function badReadings(lexicon) {
22
+ return Object.entries(lexicon).flatMap(([word, reading]) => (rawReading(reading) === undefined ? [word] : []));
23
+ }
package/dist/run.d.ts CHANGED
@@ -59,14 +59,20 @@ export interface ReadOptions {
59
59
  }
60
60
  /** Reads chapter `index` (from 1) of `project`: its text and its text problems, with no move
61
61
  * run. The paragraph checks run only when the chapter is checked (`checkChapter`). */
62
- export declare function readChapter(project: Pick<ProjectDefinition, "title" | "chapters">, index: number, options?: ReadOptions): ChapterResult<ChapterText>;
62
+ export declare function readChapter(project: Pick<ProjectDefinition, "title" | "chapters" | "lexicon">, index: number, options?: ReadOptions): ChapterResult<ChapterText>;
63
63
  /** Checks chapter `index` (0 is the title card) of `project`, as `aula check` does: it runs
64
64
  * the moves in list order with no clock and no narration, and gives the text problems, the
65
65
  * engine's checks of the picture after each animation, the kit findings and the paragraph
66
66
  * checks. With sync by construction, no check depends on the length of a `say`. */
67
- export declare function checkChapter(project: Pick<ProjectDefinition, "title" | "chapters" | "theme" | "card">, index: number, options?: ReadOptions): ChapterResult<{
67
+ export declare function checkChapter(project: Pick<ProjectDefinition, "title" | "chapters" | "lexicon" | "theme" | "card">, index: number, options?: ReadOptions): ChapterResult<{
68
68
  diagnostics: Diagnostic[];
69
69
  }>;
70
+ /** The problems of the project lexicon (`defineProject({ lexicon })`), at the `defineProject`
71
+ * call: a key that is not one word, a reading that is not `{ say: string }` or
72
+ * `{ phonemes: string }`, an empty `say` reading, and a phoneme that is not in Kokoro's token
73
+ * table. `aula check` gives them once for the project. A chapter leaves out an entry with a
74
+ * problem. */
75
+ export declare function checkLexicon(project: Pick<ProjectDefinition, "lexicon" | "call">, options?: ReadOptions): Diagnostic[];
70
76
  /** How aula draws a chapter against a narration. */
71
77
  export interface RenderOptions extends ReadOptions {
72
78
  /** The narration of this chapter: a cue for its heading and for each paragraph. */
@@ -78,4 +84,4 @@ export interface RenderOptions extends ReadOptions {
78
84
  /** Draws chapter `index` (0 is the title card) of `project` on its narration: its Lottie, its
79
85
  * length in frames, the waits of the narration and the warnings at the moves that the
80
86
  * narration waits for. */
81
- export declare function renderChapter(project: Pick<ProjectDefinition, "title" | "chapters" | "theme" | "card">, index: number, options: RenderOptions): ChapterResult<ChapterRun>;
87
+ export declare function renderChapter(project: Pick<ProjectDefinition, "title" | "chapters" | "lexicon" | "theme" | "card">, index: number, options: RenderOptions): ChapterResult<ChapterRun>;
package/dist/run.js CHANGED
@@ -2,9 +2,10 @@ import { checkRows, checkTitle, drawRows, drawTitle, readRows } from "./engine.j
2
2
  import { card as defaultCard } from "./card.js";
3
3
  import { theme as defaultTheme } from "./theme.js";
4
4
  import { AulaError } from "./errors.js";
5
- import { isComponentError } from "./load.js";
5
+ import { engine, isComponentError } from "./load.js";
6
6
  import { hasPending, takePending } from "./host.js";
7
7
  import { runUserCode } from "./user-code.js";
8
+ import { badReadings, lexiconEntries } from "./lexicon.js";
8
9
  export { importUserModule } from "./user-code.js";
9
10
  export { renderScene } from "./engine.js";
10
11
  /** Frames per second of the Lottie files: the engine's rate (`engine.fps()`, which
@@ -192,6 +193,7 @@ function slotOf(project, chapter, index, host) {
192
193
  source,
193
194
  file: host.name(source) ?? source,
194
195
  frames: (e) => host.frames(e),
196
+ lexicon: lexiconEntries(project.lexicon),
195
197
  };
196
198
  }
197
199
  /** Reads chapter `index` (from 1) of `project`: its text and its text problems, with no move
@@ -222,6 +224,21 @@ export function checkChapter(project, index, options = {}) {
222
224
  const slot = slotOf(project, chapter, index, host);
223
225
  return attempt(slot.source, host, () => checkRows(chapter, theme, card, slot, (p) => host.exists(p)));
224
226
  }
227
+ /** The problems of the project lexicon (`defineProject({ lexicon })`), at the `defineProject`
228
+ * call: a key that is not one word, a reading that is not `{ say: string }` or
229
+ * `{ phonemes: string }`, an empty `say` reading, and a phoneme that is not in Kokoro's token
230
+ * table. `aula check` gives them once for the project. A chapter leaves out an entry with a
231
+ * problem. */
232
+ export function checkLexicon(project, options = {}) {
233
+ const host = options.host ?? NODE;
234
+ const frame = definedAt(project, host);
235
+ const location = { file: host.name(frame.file) ?? frame.file, line: frame.line, col: frame.col };
236
+ const shapes = badReadings(project.lexicon).map((word) => error(`lexicon: the reading of ${JSON.stringify(word)} is not { say: string } or { phonemes: string }`, {
237
+ location,
238
+ hint: 'give the reading as { say: "words" } or { phonemes: "fˈQnimz" }, as for pronounce',
239
+ }));
240
+ return [...shapes, ...engine.checkLexicon(location, lexiconEntries(project.lexicon))];
241
+ }
225
242
  /** Draws chapter `index` (0 is the title card) of `project` on its narration: its Lottie, its
226
243
  * length in frames, the waits of the narration and the warnings at the moves that the
227
244
  * narration waits for. */
package/dist/text.d.ts CHANGED
@@ -1,15 +1,22 @@
1
+ import { type Lexicon } from "./lexicon.ts";
1
2
  import type { Diagnostic, Location, ChapterText } from "./generated/interfaces/aula-engine-types.js";
2
3
  import type { Narration, ParagraphFrames, ScriptCue, SpokenCue } from "./generated/interfaces/aula-engine-engine.js";
3
4
  export type { Diagnostic, Location, ChapterText };
4
5
  export type { Frame, Move, ParagraphText, Related, Say, Severity } from "./generated/interfaces/aula-engine-types.js";
5
6
  export type { CueKind, Narration, NarrationCue, NarrationWait, NarrationWord, ParagraphFrames, ScriptCue, SpokenCue, SpokenWord, } from "./generated/interfaces/aula-engine-engine.js";
6
7
  export type { Theme } from "./theme.ts";
8
+ export type { Lexicon } from "./lexicon.ts";
7
9
  /** `# <title>` and each chapter's Markdown, with the chapter line of each heading and paragraph:
8
10
  * for people to read. */
9
11
  export declare function scriptMarkdown(title: string, texts: readonly ChapterText[]): string;
10
12
  /** The narration script, one list of cues for each chapter: the title card (the title), then
11
- * each chapter (its heading and paragraphs). */
12
- export declare function narrationScript(title: string, texts: readonly ChapterText[]): ScriptCue[][];
13
+ * each chapter (its heading and paragraphs). `project` is the project (`defineProject`), or its
14
+ * title and its lexicon: the spoken text of the title and of each heading has the readings of
15
+ * the project lexicon, as each `say` of `texts` has. */
16
+ export declare function narrationScript(project: {
17
+ readonly title: string;
18
+ readonly lexicon?: Lexicon;
19
+ }, texts: readonly ChapterText[]): ScriptCue[][];
13
20
  /** The narration of a chapter from its script `cues` and the speech of each cue (`spoken[i]`
14
21
  * speaks `cues[i]`), at `sampleRate`. The caller puts the
15
22
  * samples of each speech at the `speechStartFrame` of its cue. */
@@ -27,9 +34,12 @@ export declare function moveFrames(narration: Narration, text: ChapterText): Par
27
34
  export declare function estimateNarration(cues: readonly ScriptCue[]): Narration;
28
35
  /** The index of the paragraph that holds chapter line `line`. */
29
36
  export declare function paragraphAt(text: ChapterText, line: number): number | undefined;
30
- /** The phonemes of English text as Kokoro's British voices read it: misaki 0.9.4's British G2P
31
- * (crates/aula-g2p), with eSpeak NG for the words that its dictionaries do not have. The same
32
- * on every run, in Node and in the browser. Throws where misaki raises an error. */
33
- export declare function phonemize(text: string): string;
37
+ /** The phonemes of English text as Kokoro's British voices read it: the project lexicon
38
+ * `lexicon` (`defineProject({ lexicon })`), aula's pronunciation lexicon, then misaki 0.9.4's
39
+ * British G2P (crates/aula-g2p), with eSpeak NG for the words that its dictionaries do not
40
+ * have. The same on every run, in Node and in the browser. Test a reading of the project
41
+ * lexicon with it before the narration. An entry with a problem (`checkLexicon`) is left out.
42
+ * Throws where misaki raises an error. */
43
+ export declare function phonemize(text: string, lexicon?: Lexicon): string;
34
44
  /** The one plain-text form of a diagnostic. */
35
45
  export declare function renderDiagnostic(d: Diagnostic): string;
package/dist/text.js CHANGED
@@ -1,15 +1,18 @@
1
1
  // The engine's pure text rules (crates/aula-project): script, narration script, check,
2
2
  // timeline, narration estimate, and the one diagnostic text format.
3
3
  import { engine } from "./load.js";
4
+ import { lexiconEntries } from "./lexicon.js";
4
5
  /** `# <title>` and each chapter's Markdown, with the chapter line of each heading and paragraph:
5
6
  * for people to read. */
6
7
  export function scriptMarkdown(title, texts) {
7
8
  return engine.scriptMarkdown(title, [...texts]);
8
9
  }
9
10
  /** The narration script, one list of cues for each chapter: the title card (the title), then
10
- * each chapter (its heading and paragraphs). */
11
- export function narrationScript(title, texts) {
12
- return engine.narrationScript(title, [...texts]);
11
+ * each chapter (its heading and paragraphs). `project` is the project (`defineProject`), or its
12
+ * title and its lexicon: the spoken text of the title and of each heading has the readings of
13
+ * the project lexicon, as each `say` of `texts` has. */
14
+ export function narrationScript(project, texts) {
15
+ return engine.narrationScript(project.title, lexiconEntries(project.lexicon ?? {}), [...texts]);
13
16
  }
14
17
  /** The narration of a chapter from its script `cues` and the speech of each cue (`spoken[i]`
15
18
  * speaks `cues[i]`), at `sampleRate`. The caller puts the
@@ -40,11 +43,14 @@ export function estimateNarration(cues) {
40
43
  export function paragraphAt(text, line) {
41
44
  return engine.paragraphAt(text, line);
42
45
  }
43
- /** The phonemes of English text as Kokoro's British voices read it: misaki 0.9.4's British G2P
44
- * (crates/aula-g2p), with eSpeak NG for the words that its dictionaries do not have. The same
45
- * on every run, in Node and in the browser. Throws where misaki raises an error. */
46
- export function phonemize(text) {
47
- return engine.phonemize(text);
46
+ /** The phonemes of English text as Kokoro's British voices read it: the project lexicon
47
+ * `lexicon` (`defineProject({ lexicon })`), aula's pronunciation lexicon, then misaki 0.9.4's
48
+ * British G2P (crates/aula-g2p), with eSpeak NG for the words that its dictionaries do not
49
+ * have. The same on every run, in Node and in the browser. Test a reading of the project
50
+ * lexicon with it before the narration. An entry with a problem (`checkLexicon`) is left out.
51
+ * Throws where misaki raises an error. */
52
+ export function phonemize(text, lexicon = {}) {
53
+ return engine.phonemize(text, lexiconEntries(lexicon));
48
54
  }
49
55
  /** The one plain-text form of a diagnostic. */
50
56
  export function renderDiagnostic(d) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@beff/aula",
3
- "version": "0.1.1",
3
+ "version": "0.2.0",
4
4
  "type": "module",
5
5
  "description": "The aula engine for narrated explainer videos: the Manim CE API, defineChapter, its rows, readChapter and renderChapter over a Rust WebAssembly component. Chapters and kits import it; the aula command is @beff/aula-cli.",
6
6
  "license": "MIT AND GPL-3.0-or-later",