@minimoji/heads 0.0.0-stage → 19.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE-SDK +41 -0
- package/THIRD_PARTY_NOTICES.md +44 -0
- package/emote-bursts/anger.png +0 -0
- package/emote-bursts/bang.png +0 -0
- package/emote-bursts/bolt.png +0 -0
- package/emote-bursts/cloud.png +0 -0
- package/emote-bursts/drop.png +0 -0
- package/emote-bursts/flame.png +0 -0
- package/emote-bursts/ha.png +0 -0
- package/emote-bursts/heart.png +0 -0
- package/emote-bursts/puff.png +0 -0
- package/emote-bursts/sparkle.png +0 -0
- package/emote-bursts/star.png +0 -0
- package/emote-bursts/thought-empty.png +0 -0
- package/emote-bursts/thought.png +0 -0
- package/emote-bursts/z.png +0 -0
- package/engine/bubble-captions.d.ts +17 -0
- package/engine/clip.d.ts +86 -0
- package/engine/line.d.ts +172 -0
- package/minimoji-heads-bursts.js +2 -0
- package/minimoji-heads.d.ts +307 -0
- package/minimoji-heads.js +3736 -0
- package/package.json +31 -4
- package/parts/beret.bin +0 -0
- package/parts/bucket.bin +0 -0
- package/parts/cap.bin +0 -0
- package/parts/flatCap.bin +0 -0
- package/parts/sculptedAfro.bin +0 -0
- package/parts/sculptedBob.bin +0 -0
- package/parts/sculptedCrop.bin +0 -0
- package/parts/sculptedCurls.bin +0 -0
- package/parts/sculptedHighBun.bin +0 -0
- package/parts/sculptedPigtails.bin +0 -0
- package/parts/sculptedQuiff.bin +0 -0
- package/parts/sculptedSidePart.bin +0 -0
- package/parts/sculptedSpaceBuns.bin +0 -0
- package/parts/sculptedTopKnot.bin +0 -0
- package/parts/sculptedWaves.bin +0 -0
- package/README.md +0 -3
|
@@ -0,0 +1,307 @@
|
|
|
1
|
+
// @minimoji/heads: Mini avatar heads for a page with no React or bundler of its own, three.js inside.
|
|
2
|
+
// The line and clip types are the engine's own (./engine/line, ./engine/clip); the stage's are minimal.
|
|
3
|
+
// `mountHeadPerformance(el, { interactive: true, onPoke })` lets a pointer poke a head and drag it; `stage.react(name?)` plays a reaction from code.
|
|
4
|
+
import type { SpeechLine, sampleLine } from './engine/line';
|
|
5
|
+
import type { ClipCache } from './engine/clip';
|
|
6
|
+
|
|
7
|
+
export { buildLine, validateLine, sampleLine, captionWindow, lineWords, createLinePlayer, applySpeechCue, LINE_VERSION } from './engine/line';
|
|
8
|
+
export type { SpeechLine, LineCue, LineWord, LineCaption, LineAudio, AuthoredCue, CueAt, LookTarget, CueStage } from './engine/line';
|
|
9
|
+
/** directing a head: a cue track with no line (a game's NPC, a party host) on its own clock; `cueStage(life)` plays it on one head's life */
|
|
10
|
+
export { playCues, cueStage, TAG_CUES, LOOK_HOLD } from './engine/line';
|
|
11
|
+
/** a line's captions sized for a speech bubble, one at a time (a presenter deck): sentence-sized, not captionWindow's 4-word phrases */
|
|
12
|
+
export { capsFromLine, captionAt, wordTime, BUBBLE_CAPTION_CHARS } from './engine/line';
|
|
13
|
+
export type { BubbleCaption } from './engine/line';
|
|
14
|
+
/** the share of the viewport's shorter side that turns the eyes all the way in `lookTargetFor` */
|
|
15
|
+
export const LOOK_SPAN: number;
|
|
16
|
+
/** a look cue's `{ x, y }` (-1..1, + right / up) for an element on the page, from the head's anchor */
|
|
17
|
+
export function lookTargetFor(el: Element | { left: number; top: number; width: number; height: number }, anchorEl: Element | { left: number; top: number; width: number; height: number }, opts?: { span?: number }): { x: number; y: number };
|
|
18
|
+
export { createClipCache, decodeAudio, isClip, clipSource, audioBufferMedia } from './engine/clip';
|
|
19
|
+
export type { SpeechClip, ClipCache } from './engine/clip';
|
|
20
|
+
|
|
21
|
+
/** a character by id (`agent` is D.A.S.H.; the catalogue is `CHARACTERS` in `@minimoji/react/characters`) */
|
|
22
|
+
export interface CharacterChoice { id: string; [option: string]: unknown }
|
|
23
|
+
|
|
24
|
+
export interface HeadPerformanceOptions {
|
|
25
|
+
/** the avatar document: the same JSON the service and the Swift Kit take */
|
|
26
|
+
avatar?: object;
|
|
27
|
+
character?: CharacterChoice | null;
|
|
28
|
+
/** several heads in one stage, each placed over its element */
|
|
29
|
+
tiles?: Array<{ id: string; avatar?: object; character: CharacterChoice | null; bakedHead?: PreparedBakedHead | null; element: Element }> | null;
|
|
30
|
+
/** draw a baked head (a bake's GLB, see `prepareBakedHead`) instead of building `avatar`/`character` */
|
|
31
|
+
bakedHead?: PreparedBakedHead | null;
|
|
32
|
+
reduceMotion?: boolean;
|
|
33
|
+
/** where the idle gaze hears the pointer: the container by default, `window` to follow it anywhere */
|
|
34
|
+
pointerTarget?: EventTarget | null;
|
|
35
|
+
/** a solo stage reports where its head's top sits at rest (css px from the container's top) */
|
|
36
|
+
onHeadTop?: ((headTop: number) => void) | null;
|
|
37
|
+
/** let a pointer poke the heads and drag them. Off by default (no listener is attached); `true` turns both on.
|
|
38
|
+
* Only a head's skull counts: a press anywhere else falls through to the page. A poke works idle, paused, before Play
|
|
39
|
+
* and mid-line (lip-sync carries on under it) and never stops the line itself: do that from `onPoke` */
|
|
40
|
+
interactive?: boolean | Interactive | null;
|
|
41
|
+
/** a poke played a reaction (`id`: the tile's, or 'solo') */
|
|
42
|
+
onPoke?: ((event: { reaction: Reaction; id: string }) => void) | null;
|
|
43
|
+
onDragStart?: ((event: { id: string }) => void) | null;
|
|
44
|
+
/** `distance`: how far the pointer went, css px; `flung`: released fast enough to play `dizzy` */
|
|
45
|
+
onDragEnd?: ((event: { id: string; distance: number; flung: boolean }) => void) | null;
|
|
46
|
+
/** the comic stickers that pop when a head's mood changes (any strength, as `<MinimojiHead bursts>` and the Kit); default true */
|
|
47
|
+
bursts?: boolean;
|
|
48
|
+
/** false: face only. No comic stickers and none of the rig's effect plates (tears, sparkles, steam, sleep Zs, notes,
|
|
49
|
+
* a screen face's effects); expressions, blush, lip sync (sound arcs and lines too) and head motion are untouched. Default true. Overrides
|
|
50
|
+
* `bursts`; applies to recipe heads, baked heads and every tile in this stage */
|
|
51
|
+
decorations?: boolean;
|
|
52
|
+
/** the head's still until it draws: a `mountHeadPoster` handle (mount it before fetching a bake) or the still's src.
|
|
53
|
+
* It gives way on the first frame; it stays, sharp, if mounting throws. */
|
|
54
|
+
poster?: HeadPoster | string | null;
|
|
55
|
+
/** a screen face's (D.A.S.H.'s) CRT look, scanlines and glass following the mood: 0 off, 1 (the default), 2 loud. A head of skin ignores it */
|
|
56
|
+
crt?: 0 | 1 | 2;
|
|
57
|
+
/** what the head shows for an agent: 'thinking' | 'working' | 'needsYou' | 'waiting' | 'done' | 'errored' | 'asleep'.
|
|
58
|
+
* D.A.S.H.'s screen shows it (bake 19); any other head its own face and one held sticker (working: a keyboard).
|
|
59
|
+
* null (the default) leaves the head as it was */
|
|
60
|
+
agentState?: string | null;
|
|
61
|
+
/** a screen face's glass colour over every mood and agent state, `#rrggbb`; null leaves it */
|
|
62
|
+
screenColor?: string | null;
|
|
63
|
+
/** a packed character's colours by slot for the solo `bakedHead`, `{ trim: '#7a3cff' }` (see `prepared.slots`);
|
|
64
|
+
* throws on an unknown slot or a head with no slot map */
|
|
65
|
+
colors?: Readonly<Record<string, string>> | null;
|
|
66
|
+
/** RECORD FRAME BY FRAME (video export): a stepped clock from `createManualClock({ seed })`. The stage runs no loop of
|
|
67
|
+
* its own and reads no wall clock or pointer: nothing advances and nothing draws until `stage.step(dt)`, each step
|
|
68
|
+
* is one frame advanced by exactly `dt`, and the same seed and calls draw the same frames. `frame`/`idleFrame` only
|
|
69
|
+
* set what the next step draws. A `poster` stays until `stage.ready` resolves, then leaves at once (no fade, no
|
|
70
|
+
* puff). Off by default */
|
|
71
|
+
clock?: ManualClock | null;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/** A STEPPED CLOCK for recording a head frame by frame. Mount the stage on it, `await stage.ready`, then `stage.step(1 / 30)`
|
|
75
|
+
* once per video frame: every clock the head has moves by exactly that much and one frame is drawn, however long the
|
|
76
|
+
* recorder takes between steps. A voiced performance on a stepped stage plays no sound: mux the audio yourself */
|
|
77
|
+
export interface ManualClock {
|
|
78
|
+
readonly manual: true;
|
|
79
|
+
readonly seed: number;
|
|
80
|
+
/** seconds: the sum of every step */
|
|
81
|
+
now(): number;
|
|
82
|
+
readonly time: number;
|
|
83
|
+
readonly steps: number;
|
|
84
|
+
/** move every clock by `dt` seconds (finite, ≥ 0) and draw one frame on every stage on this clock; answers the time */
|
|
85
|
+
step(dt: number): number;
|
|
86
|
+
/** resolves once nothing held on this clock is still loading (a stage's sculpted parts and stickers, a voiced
|
|
87
|
+
* performance's line being loaded or built). Rejects when a held load failed: an Error naming each (`failed` lists
|
|
88
|
+
* them), reported once, so a retry reads a clean `ready`. Wait for it before every step if a line can be selected
|
|
89
|
+
* while you record: the line then starts on the same step every run */
|
|
90
|
+
readonly ready: Promise<void>;
|
|
91
|
+
/** a seeded random source of its own for `salt` */
|
|
92
|
+
random(salt?: string): () => number;
|
|
93
|
+
/** run `fn` on every step; answers the unsubscribe */
|
|
94
|
+
onStep(fn: (dt: number, time: number) => void): () => void;
|
|
95
|
+
/** have `ready` wait for a load of yours too (and reject, naming `what`, if it fails); answers the promise as given */
|
|
96
|
+
hold<T>(promise: Promise<T>, what?: string): Promise<T>;
|
|
97
|
+
}
|
|
98
|
+
/** a stepped clock. `seed` deals the dice of every head on it (default 1): when it blinks, where the eyes glance, which
|
|
99
|
+
* emote of a mood plays, a poke's reaction. Two recordings match only with the same seed: derive it from a stable id
|
|
100
|
+
* for the content (a deck's id, a slide's id plus a speaker), never from `location`, a URL or a served path (a server
|
|
101
|
+
* that serves each run under a fresh prefix gives every run other blinks) */
|
|
102
|
+
export function createManualClock(options?: { seed?: number }): ManualClock;
|
|
103
|
+
|
|
104
|
+
/** a poke's answer: a face held a moment and a short move on the head (no sound: play your own from `onPoke`) */
|
|
105
|
+
export type Reaction = 'oof' | 'ah' | 'flinch' | 'giggle' | 'dizzy';
|
|
106
|
+
export interface Interactive {
|
|
107
|
+
/** a tap on a head plays a reaction, never the same one twice in a row; `reactions` replaces the pool (unknown names warn once and are skipped) */
|
|
108
|
+
poke?: boolean | { reactions?: Reaction[] };
|
|
109
|
+
/** a head follows a drag on a rubber band (approaching `maxPx`, 80 css px), tilts toward the pull and springs back with a wobble; a fling plays `dizzy` */
|
|
110
|
+
drag?: boolean | { maxPx?: number };
|
|
111
|
+
/** each head's element becomes a button with this accessible name (Enter or Space pokes it). Default "Poke the avatar" */
|
|
112
|
+
label?: string;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
export interface HeadPerformanceStage {
|
|
116
|
+
/** play a reaction now, cutting in over one already playing: a name, or with none one from the pool; `id` picks a tile.
|
|
117
|
+
* Works with `interactive` off too. Answers what played, or null (an unknown name warns once and plays nothing) */
|
|
118
|
+
react(name?: Reaction | null, id?: string): Reaction | null;
|
|
119
|
+
/** a look cue on the stage: the eyes on `{ x, y }` (-1..1), aside ('away') or back to the viewer (null) for `hold` seconds; `id` picks a tile */
|
|
120
|
+
look(target: { x: number; y: number } | 'away' | null, hold: number, id?: string): void;
|
|
121
|
+
/** a face set quietly; `id` picks a tile. A change to a mood with stickers pops them (`bursts`), unless `catchUp`:
|
|
122
|
+
* the face held where a line jumped to (a seek, a stall), put back without its stickers */
|
|
123
|
+
setMood(mood: string, id?: string, catchUp?: boolean): void;
|
|
124
|
+
/** replace the stage's head(s) with one solo baked head (a tiled stage becomes solo) */
|
|
125
|
+
setBakedHead(prepared: PreparedBakedHead, options?: { colors?: Readonly<Record<string, string>> | null }): void;
|
|
126
|
+
/** recolour the solo baked head by colour slot, live (no reload); throws on an unknown slot, a colour that is not
|
|
127
|
+
* #rrggbb or a head with no slot map. A slot with no parts on this variant changes nothing */
|
|
128
|
+
setColors(colors: Readonly<Record<string, string>>): void;
|
|
129
|
+
/** what an agent is doing, on every head (see `agentState`); `color`/`glass` override the state's own colour */
|
|
130
|
+
setAgentState(state: string | null, opts?: { color?: string; glass?: number }): void;
|
|
131
|
+
/** light a screen face's glass in `hex` over every mood (`glass`: ≈.3 dark, 2.2 flooded); null hands it back */
|
|
132
|
+
setScreenColor(hex: string | null, opts?: { glass?: number }): void;
|
|
133
|
+
/** put a live source on a head (`setPerformance(await liveMic())`): its mouth is the head's while it talks, and the
|
|
134
|
+
* stage draws its own frames while one is set. null takes it off; `id` picks a tile */
|
|
135
|
+
setPerformance(source: LiveMicSession | { performance(t?: number): unknown } | ((t: number) => unknown) | null, id?: string): void;
|
|
136
|
+
/** resolves (to the stage) once every lazy load a frame depends on is in: the sculpted parts (and the head rebuilt
|
|
137
|
+
* with them), the sticker scripts (minimoji-heads-bursts.js) and their sprites. A stepped stage's rejects, naming
|
|
138
|
+
* them, when the sculpted parts failed (the head draws its fallback; the stage's ready and its clock's each report
|
|
139
|
+
* it once; stickers are decoration and never fail it); a live stage's always resolves. On a stepped stage
|
|
140
|
+
* the poster then leaves at once and the canvas holds the first frame, with no step (the head as mounted, at time 0);
|
|
141
|
+
* `step(0)` only redraws the frame as it stands: nothing moves, no line ticks, no dice are dealt */
|
|
142
|
+
readonly ready: Promise<HeadPerformanceStage>;
|
|
143
|
+
/** the stepped clock the stage runs on, or null */
|
|
144
|
+
readonly clock: ManualClock | null;
|
|
145
|
+
/** a stepped stage: move its clock (and every stage on it) by `dt` seconds and draw one frame. Throws on a live stage */
|
|
146
|
+
step(dt: number): void;
|
|
147
|
+
/** the frame just drawn as ImageData (device px): the head's canvas with its stickers behind and in front */
|
|
148
|
+
capture(): ImageData;
|
|
149
|
+
dispose(): void;
|
|
150
|
+
[member: string]: any;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
/** mount a head stage in `container`: media time during playback, one animation frame loop while idle */
|
|
154
|
+
export function mountHeadPerformance(container: HTMLElement, options?: HeadPerformanceOptions): HeadPerformanceStage;
|
|
155
|
+
|
|
156
|
+
/** a bake's binary glTF (`GET /avatars/<key>.glb` on the service, or bytes you hold), checked and parsed once by `prepareBakedHead`;
|
|
157
|
+
* data only (no images, textures, external buffers or code). A bad file rejects: there is never a stand-in head */
|
|
158
|
+
export interface BakedHeadSource {
|
|
159
|
+
format?: 'minimoji-head-glb';
|
|
160
|
+
/** http(s):// or a root-relative /path; relative, blob: and data: URLs are refused (pass bytes instead) */
|
|
161
|
+
url: string;
|
|
162
|
+
/** reject unless the file's SHA-256 is this (hex) */
|
|
163
|
+
sha256?: string;
|
|
164
|
+
/** reject unless this is the bundle's bake version (the file's own must match it too) */
|
|
165
|
+
version?: number;
|
|
166
|
+
bakeVersion?: number;
|
|
167
|
+
}
|
|
168
|
+
export interface PreparedBakedHead {
|
|
169
|
+
readonly format: 'minimoji-head-glb';
|
|
170
|
+
readonly version: number;
|
|
171
|
+
readonly sha256: string;
|
|
172
|
+
readonly byteLength: number;
|
|
173
|
+
readonly bounds: Readonly<{ w: number; h: number; cy: number; minY: number; maxY: number }>;
|
|
174
|
+
readonly faceNames: readonly string[];
|
|
175
|
+
/** a packed character's colour slots: slot → the parts wearing it in this file (an empty list: not on this
|
|
176
|
+
* variant). null on a head with no slot map (another bake, or a pack from before it): its colours are fixed */
|
|
177
|
+
readonly slots: Readonly<Record<string, readonly string[]>> | null;
|
|
178
|
+
/** frees the template; heads already mounted from it keep working. Idempotent */
|
|
179
|
+
dispose(): void;
|
|
180
|
+
}
|
|
181
|
+
export const BAKED_HEAD_FORMAT: 'minimoji-head-glb';
|
|
182
|
+
/** 32 MB: the most a baked head may weigh */
|
|
183
|
+
export const BAKED_HEAD_MAX_BYTES: number;
|
|
184
|
+
/** The oldest bake version a baked head may carry; files from this version up to the current bake load. */
|
|
185
|
+
export const BAKED_HEAD_MIN_VERSION: number;
|
|
186
|
+
/** fetch (same-origin credentials) or take bytes, validate and parse a baked head; mount it with `bakedHead` */
|
|
187
|
+
export function prepareBakedHead(source: string | BakedHeadSource | ArrayBuffer | ArrayBufferView, options?: {
|
|
188
|
+
sha256?: string; version?: number; bakeVersion?: number; maxBytes?: number;
|
|
189
|
+
fetch?: typeof globalThis.fetch; signal?: AbortSignal;
|
|
190
|
+
}): Promise<PreparedBakedHead>;
|
|
191
|
+
export const loadBakedHead: typeof prepareBakedHead;
|
|
192
|
+
/** `mountHeadPerformance` for one prepared baked head; throws (before any canvas) unless `bakedHead` is prepared */
|
|
193
|
+
export function mountBakedHeadPerformance(container: HTMLElement, options: Omit<HeadPerformanceOptions, 'avatar' | 'character' | 'tiles'> & { bakedHead: PreparedBakedHead }): HeadPerformanceStage;
|
|
194
|
+
|
|
195
|
+
/** a voiced performance: one owned media element per run; a selection is a `{ timeline, audio, duration }` or plain audio */
|
|
196
|
+
export function createVoicedPerformance(options: {
|
|
197
|
+
/** the element a run plays on. Required on a live stage. On a stepped stage it is optional and sets the timebase:
|
|
198
|
+
* given, the element's currentTime, paused and ended drive the line, as live (give a silent one for a recording,
|
|
199
|
+
* whose currentTime is your recorder's clock); left out, the line runs on the stage's clock with no element */
|
|
200
|
+
createMedia?: (url: string) => HTMLMediaElement;
|
|
201
|
+
/** a stepped stage's timebase, when you want to say it: 'media' (needs createMedia) or 'clock'. Default: 'media'
|
|
202
|
+
* when createMedia is given, else 'clock'. A live stage is always 'media'. Made on an object of your own to
|
|
203
|
+
* `attach` a stepped stage to: say 'clock' here to run on its clock with no element */
|
|
204
|
+
timebase?: 'media' | 'clock';
|
|
205
|
+
loadTimeline: (url: string, signal: AbortSignal) => Promise<unknown>;
|
|
206
|
+
/** the stage the calls go to (frame, reset, setMood, emote, gesture, look, brow): a stage, or an object of your own
|
|
207
|
+
* that forwards them. A stepped stage's clock and drive are read from it, or given with `attach(stage)` */
|
|
208
|
+
stage: unknown;
|
|
209
|
+
changed?: (state: unknown) => void;
|
|
210
|
+
claimVoice?: () => void;
|
|
211
|
+
clips?: ClipCache;
|
|
212
|
+
/** mute every element a run makes (and the live one); unset leaves the element as `createMedia` made it */
|
|
213
|
+
muted?: boolean;
|
|
214
|
+
/** 0..1 on every element a run makes (and the live one); unset leaves the element as `createMedia` made it */
|
|
215
|
+
volume?: number;
|
|
216
|
+
/** where plain audio with no words is transcribed */
|
|
217
|
+
transcribe?: { key: string; service: string } | null;
|
|
218
|
+
}): {
|
|
219
|
+
/** on a stepped stage, timebase 'clock': start the line on the stage's clock, with no media and no sound; each
|
|
220
|
+
* `stage.step(dt)` moves it by `dt`, and it ends (status `ended`) on the step that reaches its duration. Timebase
|
|
221
|
+
* 'media': as live (play() on your element; its currentTime is the line's time); the steps draw it */
|
|
222
|
+
play(): void;
|
|
223
|
+
/** the line's time now (seconds), on its timebase: drive your own captions or reveals from it */
|
|
224
|
+
readonly time: number;
|
|
225
|
+
/** is the line playing (not loading, paused, buffering, stopped or ended)? */
|
|
226
|
+
readonly playing: boolean;
|
|
227
|
+
/** which clock the line follows: 'media' (the element's currentTime) or 'clock' (a stepped stage's) */
|
|
228
|
+
readonly timebase: 'media' | 'clock';
|
|
229
|
+
pause(): void;
|
|
230
|
+
stop(): void;
|
|
231
|
+
/** load a line (held on a stepped stage's clock until it has landed, so `clock.ready` waits for it) */
|
|
232
|
+
select(next: unknown): Promise<void>;
|
|
233
|
+
prepare(next: unknown): Promise<SpeechLine>;
|
|
234
|
+
/** point the voice at a stepped stage's clock and drive: for a `stage` of your own (it still gets the calls) or a
|
|
235
|
+
* head mounted again (the line goes on from where it was). Throws unless `stage` is stepped */
|
|
236
|
+
attach(stage: HeadPerformanceStage): void;
|
|
237
|
+
/** mute or unmute the live element at once and every later run's (a muted head still talks: the clock is the element's) */
|
|
238
|
+
setMuted(muted: boolean): void;
|
|
239
|
+
/** the volume (0..1, clamped) of the live element at once and every later run's */
|
|
240
|
+
setVolume(volume: number): void;
|
|
241
|
+
[member: string]: any;
|
|
242
|
+
};
|
|
243
|
+
|
|
244
|
+
/** `sampleLine` under the website's older name */
|
|
245
|
+
export const sampleTimeline: typeof sampleLine;
|
|
246
|
+
|
|
247
|
+
/** the line player without React: what `useLine` in `@minimoji/react` runs */
|
|
248
|
+
export function createLineSession(opts?: {
|
|
249
|
+
onState?: (state: unknown) => void;
|
|
250
|
+
createAudio?: (url: string) => HTMLAudioElement;
|
|
251
|
+
onCue?: (cue: unknown, quiet: boolean) => void;
|
|
252
|
+
onEnd?: (generation: number, reason: 'ended' | 'stopped' | 'failed', error?: Error) => void;
|
|
253
|
+
clips?: ClipCache;
|
|
254
|
+
audioContext?: () => AudioContext;
|
|
255
|
+
/** a stepped clock (createManualClock): the line on its time, no sound */
|
|
256
|
+
clock?: ManualClock | null;
|
|
257
|
+
}): { say(line: unknown, opts?: object): number | null; prepare(clip: unknown): Promise<SpeechLine>; stop(): void; dispose(): void; [member: string]: any };
|
|
258
|
+
|
|
259
|
+
/** why a live mic failed: `denied`, `no-device`, `busy` (another app has it), `unsupported` (an http:// page, an old
|
|
260
|
+
* browser), `blocked` (audio kept off: not called from a gesture), `ended` (unplugged mid-talk), `failed` */
|
|
261
|
+
export interface LiveMicError extends Error { code: 'unsupported' | 'denied' | 'no-device' | 'busy' | 'blocked' | 'ended' | 'failed' }
|
|
262
|
+
export type LiveMicState = 'idle' | 'starting' | 'live';
|
|
263
|
+
export interface LiveMicOptions {
|
|
264
|
+
/** a mic from `navigator.mediaDevices.enumerateDevices()`; null (default): the system's */
|
|
265
|
+
deviceId?: string | null;
|
|
266
|
+
/** seconds the host delays its own playout of this voice for the mouth's sake (0: the speaker hears themselves) */
|
|
267
|
+
lookAhead?: number;
|
|
268
|
+
onState?: (state: LiveMicState) => void;
|
|
269
|
+
onError?: (error: LiveMicError) => void;
|
|
270
|
+
}
|
|
271
|
+
/** the mic, live, on a head's mouth: analysed in the page, nothing played, stored or sent */
|
|
272
|
+
export interface LiveMicSession {
|
|
273
|
+
/** open the mic (from a click): resolves true once live, false when `stop()` came first; rejects with a LiveMicError */
|
|
274
|
+
start(): Promise<boolean>;
|
|
275
|
+
stop(): void;
|
|
276
|
+
/** a performance snapshot for this frame: the mouth while you talk, inactive in the silences */
|
|
277
|
+
performance(t?: number): unknown;
|
|
278
|
+
/** how loud the voice is now, 0..1: a meter */
|
|
279
|
+
level(): number;
|
|
280
|
+
on(kind: 'state', fn: (state: LiveMicState) => void): () => void;
|
|
281
|
+
on(kind: 'error', fn: (error: LiveMicError) => void): () => void;
|
|
282
|
+
setDevice(deviceId: string | null): void;
|
|
283
|
+
readonly state: LiveMicState;
|
|
284
|
+
readonly live: boolean;
|
|
285
|
+
readonly path: 'worklet' | 'script-processor' | null;
|
|
286
|
+
}
|
|
287
|
+
/** TALK WITH YOUR VOICE: `const mic = await liveMic(); stage.setPerformance(mic);` from a click. Echo cancelling, noise
|
|
288
|
+
* suppression and auto gain on; the same live viseme analyser as MinimojiKit */
|
|
289
|
+
export function liveMic(opts?: LiveMicOptions): Promise<LiveMicSession>;
|
|
290
|
+
/** the session, not started */
|
|
291
|
+
export function createLiveMicSession(opts?: LiveMicOptions): LiveMicSession;
|
|
292
|
+
export const LIVE_MIC_CONSTRAINTS: Readonly<{ echoCancellation: true; noiseSuppression: true; autoGainControl: true }>;
|
|
293
|
+
|
|
294
|
+
/** The head's own loader without React: its still (soft, breathing) in `container`, under the stage's canvas. */
|
|
295
|
+
export interface HeadPoster {
|
|
296
|
+
readonly element: HTMLElement;
|
|
297
|
+
/** the head drew: the still fades and leaves the page (`instant`: at once, no fade or puff, as a stepped stage does) */
|
|
298
|
+
ready(options?: { instant?: boolean }): void;
|
|
299
|
+
/** the head will not draw: the still stays, sharp */
|
|
300
|
+
error(): void;
|
|
301
|
+
dispose(): void;
|
|
302
|
+
}
|
|
303
|
+
/** Show a head's still (GET /avatars/<key>.png?size=256) at once, before a bake is fetched; pass the handle to
|
|
304
|
+
* mountHeadPerformance's `poster`. Sets `data-minimoji` on the container (loading → ready or error). */
|
|
305
|
+
export function mountHeadPoster(container: HTMLElement, options: { src: string; puff?: string | null }): HeadPoster;
|
|
306
|
+
/** the loader's style sheet (mountHeadPoster adds it to the page once) */
|
|
307
|
+
export const POSTER_CSS: string;
|