@sidevoice/engine 0.0.0 → 0.4.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.
@@ -0,0 +1,447 @@
1
+ /* tslint:disable */
2
+ /* eslint-disable */
3
+
4
+ /** What every promise of the engine rejects with: the engine's stable code and its parameters, and, for a call a
5
+ * remote provider refused, what the provider said (`detail`: its own code and message), to show as it is. */
6
+ export interface EngineError extends Error { code: string; params: Record<string, number>; detail?: string; }
7
+ /** Why a build does not run here: a stable code and its numbers (`needs`, `has`) when there are any. */
8
+ export interface Reason { code: string; params: { needs?: number; has?: number }; }
9
+ export interface Voice { id: string; name?: string; languages: string[]; gender?: "female" | "male"; }
10
+ export interface ModelBuild {
11
+ id: string; backend: string; accelerator?: string; precision: string; downloadBytes: number; memoryMb: number;
12
+ available: boolean; reasons: Reason[]; installed: boolean;
13
+ }
14
+ /** The speeds a model takes, 1 being its normal pace. A model with no `speed` takes none. */
15
+ export interface SpeedRange { min: number; max: number; }
16
+ /** A model as a catalogue lists it, whichever: what every model has. */
17
+ export interface ModelInfo {
18
+ id: string; capabilities: ("stt" | "tts" | "vad" | "end-of-turn")[]; languages: string[];
19
+ voices: Voice[]; speed?: SpeedRange;
20
+ }
21
+ /** A model of the local catalogue: its family, size, licence, builds ranked, what is installed and when it was
22
+ * last loaded. */
23
+ export interface LocalModelInfo extends ModelInfo {
24
+ family: string; parametersM: number; license: string; installed: boolean;
25
+ /** When it was last loaded, in milliseconds since the epoch; absent when it is not installed or not loaded since. */
26
+ lastUsedAt?: number;
27
+ builds: ModelBuild[]; recommendedBuild?: string;
28
+ }
29
+ /** A model of a remote provider, as listed. */
30
+ export interface RemoteModelInfo extends ModelInfo {}
31
+ /** A model ready to use, from a catalogue's `load`: either hands out the same capabilities. */
32
+ export type Model = LocalModel | RemoteModel;
33
+ /** A place models come from: what the local catalogue and each provider's have in common (`id`, `name`, `status()`,
34
+ * `models(capability?)`, `refresh()`, `load(model)`). Each lists and loads its own types; nothing tells them apart but
35
+ * which catalogue was asked. */
36
+ export type Catalog = LocalCatalog | RemoteCatalog;
37
+ /** How a catalogue stands: why it is not current (absent when it is), whether its models are the last kept, and what
38
+ * the provider said when it last refused, for a developer to read. */
39
+ export interface CatalogStatus { reason?: Reason; stale: boolean; detail?: string; }
40
+ /** How far an install has got: files done of all, and the bytes of the file being downloaded. */
41
+ export interface Progress { files: number; done: number; received: number; size?: number; }
42
+ export interface Audio { samples: Float32Array; sampleRate: number; }
43
+ /** How a voice activity stream decides what is speech; each left out takes its default (0.5, 500 ms, 250 ms). */
44
+ export interface VadOptions { threshold?: number; minSilenceMs?: number; minSpeechMs?: number; }
45
+ /** One window of a stream: where it ends (in samples), whether the stream is in speech, the model's probability. */
46
+ export interface VadFrame { end: number; speech: boolean; probability?: number; }
47
+ /** Speech confirmed at `at`, or speech that ran from `start` to just before `end`: positions in samples. */
48
+ export type VadEvent = { type: "speech-start"; at: number } | { type: "speech-end"; start: number; end: number };
49
+ export interface VadOutput { frames: VadFrame[]; events: VadEvent[]; }
50
+
51
+
52
+
53
+ /**
54
+ * A model, local or remote, as an end-of-turn classifier.
55
+ */
56
+ export class EndOfTurn {
57
+ private constructor();
58
+ free(): void;
59
+ [Symbol.dispose](): void;
60
+ /**
61
+ * The probability, from 0 to 1, that the turn in `audio` (mono samples at `sampleRate` Hz, from its start to now)
62
+ * is complete; the engine keeps the last `seconds` and resamples them.
63
+ */
64
+ probability(audio: Float32Array, sampleRate: number): Promise<number>;
65
+ /**
66
+ * How many seconds of the end of a turn the model hears: earlier audio does not count.
67
+ */
68
+ readonly seconds: number;
69
+ }
70
+
71
+ /**
72
+ * The local catalogue, for JavaScript.
73
+ */
74
+ export class LocalCatalog {
75
+ private constructor();
76
+ free(): void;
77
+ [Symbol.dispose](): void;
78
+ /**
79
+ * The model `model`, loaded as `WebEngine.load` does with no build (installing it first and telling
80
+ * `onProgress`; `signal` aborts it).
81
+ */
82
+ load(model: string, onProgress: (progress: Progress) => void, signal?: AbortSignal | null): Promise<LocalModel>;
83
+ /**
84
+ * Its models, those of `capability` alone when given (`"stt"`, `"tts"`, `"vad"`, `"end-of-turn"`), each with its
85
+ * builds ranked, what is installed and when it was last loaded (`lastUsedAt`); rejects with `invalid-capability`
86
+ * for any other.
87
+ */
88
+ models(capability: "stt" | "tts" | "vad" | "end-of-turn"): Promise<LocalModelInfo[]>;
89
+ /**
90
+ * Nothing to read again: compiled in. Its status.
91
+ */
92
+ refresh(): Promise<CatalogStatus>;
93
+ /**
94
+ * How it stands: always current.
95
+ */
96
+ status(): Promise<CatalogStatus>;
97
+ /**
98
+ * Its id: `"local"`.
99
+ */
100
+ readonly id: string;
101
+ /**
102
+ * Absent: the app names the local catalogue.
103
+ */
104
+ readonly name: string | undefined;
105
+ }
106
+
107
+ /**
108
+ * A local model in memory, for JavaScript. It and the `Stt` and `Tts` it hands out each keep the model in memory:
109
+ * freeing them all (`free()`, or letting them be collected) unloads it.
110
+ */
111
+ export class LocalModel {
112
+ private constructor();
113
+ free(): void;
114
+ [Symbol.dispose](): void;
115
+ /**
116
+ * The model as an end-of-turn classifier, if it is one.
117
+ */
118
+ asEndOfTurn(): EndOfTurn | undefined;
119
+ /**
120
+ * The model as speech to text, if it is one.
121
+ */
122
+ asStt(): Stt | undefined;
123
+ /**
124
+ * The model as text to speech, if it is one.
125
+ */
126
+ asTts(): Tts | undefined;
127
+ /**
128
+ * The model as a voice activity detector, if it is one.
129
+ */
130
+ asVad(): Vad | undefined;
131
+ /**
132
+ * What it can do: `"stt"`, `"tts"`, `"vad"`, `"end-of-turn"`.
133
+ */
134
+ capabilities(): ("stt" | "tts" | "vad" | "end-of-turn")[];
135
+ /**
136
+ * The id of the build that was loaded.
137
+ */
138
+ readonly build: string;
139
+ /**
140
+ * The model's id.
141
+ */
142
+ readonly id: string;
143
+ }
144
+
145
+ /**
146
+ * A remote provider's catalogue, for JavaScript.
147
+ */
148
+ export class RemoteCatalog {
149
+ private constructor();
150
+ free(): void;
151
+ [Symbol.dispose](): void;
152
+ /**
153
+ * The model `model`, as listed: it calls the provider each time it is used. `onProgress` is never called (nothing
154
+ * is installed); `signal` aborts it.
155
+ */
156
+ load(model: string, onProgress: (progress: Progress) => void, signal?: AbortSignal | null): Promise<RemoteModel>;
157
+ /**
158
+ * Its models as listed, those of `capability` alone when given; rejects with `invalid-capability` for any other.
159
+ */
160
+ models(capability: "stt" | "tts" | "vad" | "end-of-turn"): Promise<RemoteModelInfo[]>;
161
+ /**
162
+ * Reads it again now, whatever its age: its status after.
163
+ */
164
+ refresh(): Promise<CatalogStatus>;
165
+ /**
166
+ * How it stands: `{ reason?, stale, detail? }`, listing the provider first if its listing is missing or old.
167
+ */
168
+ status(): Promise<CatalogStatus>;
169
+ /**
170
+ * Its id: the provider's.
171
+ */
172
+ readonly id: string;
173
+ /**
174
+ * The provider's name ("OpenAI").
175
+ */
176
+ readonly name: string | undefined;
177
+ }
178
+
179
+ /**
180
+ * A remote provider's model, for JavaScript: each call on what it hands out goes to the provider.
181
+ */
182
+ export class RemoteModel {
183
+ private constructor();
184
+ free(): void;
185
+ [Symbol.dispose](): void;
186
+ /**
187
+ * The model as an end-of-turn classifier, if it is one.
188
+ */
189
+ asEndOfTurn(): EndOfTurn | undefined;
190
+ /**
191
+ * The model as speech to text, if it is one.
192
+ */
193
+ asStt(): Stt | undefined;
194
+ /**
195
+ * The model as text to speech, if it is one.
196
+ */
197
+ asTts(): Tts | undefined;
198
+ /**
199
+ * The model as a voice activity detector, if it is one.
200
+ */
201
+ asVad(): Vad | undefined;
202
+ /**
203
+ * What it can do: `"stt"`, `"tts"`, `"vad"`, `"end-of-turn"`.
204
+ */
205
+ capabilities(): ("stt" | "tts" | "vad" | "end-of-turn")[];
206
+ /**
207
+ * The provider's id of the model.
208
+ */
209
+ readonly id: string;
210
+ /**
211
+ * The provider's id.
212
+ */
213
+ readonly provider: string;
214
+ }
215
+
216
+ /**
217
+ * A model, local or remote, as speech to text.
218
+ */
219
+ export class Stt {
220
+ private constructor();
221
+ free(): void;
222
+ [Symbol.dispose](): void;
223
+ /**
224
+ * What is said in `audio` (mono samples at `sampleRate` Hz, one whole turn; the engine resamples it), in
225
+ * `language` (a BCP 47 tag), or in the one the model detects when left out.
226
+ */
227
+ transcribe(audio: Float32Array, sampleRate: number, language?: string | null): Promise<string>;
228
+ }
229
+
230
+ /**
231
+ * A model, local or remote, as text to speech.
232
+ */
233
+ export class Tts {
234
+ private constructor();
235
+ free(): void;
236
+ [Symbol.dispose](): void;
237
+ /**
238
+ * `text` spoken with `voice` (one of `voices()`), in `language` (a BCP 47 tag) for a model that speaks several,
239
+ * at `speed` (1 when left out): `{ samples, sampleRate }`, at the model's own rate.
240
+ */
241
+ speak(text: string, voice: string, language?: string | null, speed?: number | null): Promise<Audio>;
242
+ /**
243
+ * The voices it speaks with: `{ id, languages, gender? }`.
244
+ */
245
+ voices(): Promise<Voice[]>;
246
+ }
247
+
248
+ /**
249
+ * A model, local or remote, as a voice activity detector.
250
+ */
251
+ export class Vad {
252
+ private constructor();
253
+ free(): void;
254
+ [Symbol.dispose](): void;
255
+ /**
256
+ * A new stream, from sample 0 and with no speech, deciding with `options` (each left out takes its default).
257
+ * Rejects with `invalid-vad-options` for options out of their bounds or of the wrong type.
258
+ */
259
+ stream(options: VadOptions): Promise<VadStream>;
260
+ }
261
+
262
+ /**
263
+ * One stream of audio through a voice activity detector: feed it mono samples at `sampleRate` as they come, in pieces
264
+ * of any length. It keeps the model in memory until it is freed. Calls on it wait for one another.
265
+ */
266
+ export class VadStream {
267
+ private constructor();
268
+ free(): void;
269
+ [Symbol.dispose](): void;
270
+ /**
271
+ * Takes the next `samples` and runs the model on every whole window it now has: `{ frames, events }`.
272
+ */
273
+ accept(samples: Float32Array): Promise<VadOutput>;
274
+ /**
275
+ * Ends the stream's audio: the speech in progress, if any, as its `speech-end` event (else `undefined`); the
276
+ * stream then starts over from sample 0.
277
+ */
278
+ finish(): Promise<VadEvent | undefined>;
279
+ /**
280
+ * Starts over from sample 0, forgetting any speech in progress.
281
+ */
282
+ reset(): Promise<void>;
283
+ /**
284
+ * The rate the stream takes, in Hz: the model's own. It is not resampled.
285
+ */
286
+ readonly sampleRate: number;
287
+ /**
288
+ * How many samples one window, one frame, holds.
289
+ */
290
+ readonly window: number;
291
+ }
292
+
293
+ /**
294
+ * The engine, for JavaScript.
295
+ */
296
+ export class WebEngine {
297
+ private constructor();
298
+ free(): void;
299
+ [Symbol.dispose](): void;
300
+ /**
301
+ * The ids of the backends in this build.
302
+ */
303
+ backends(): string[];
304
+ /**
305
+ * The catalogue `id` (`"local"`, `"openai"`, `"elevenlabs"`); throws `catalog-not-found` for any other.
306
+ */
307
+ catalog(id: string): LocalCatalog | RemoteCatalog;
308
+ /**
309
+ * Every catalogue of this engine: the `LocalCatalog` first, then each provider's `RemoteCatalog`, by id. Both have
310
+ * `id`, `name`, `status()`, `models(capability?)`, `refresh()` and `load(model)`; each lists and loads its own
311
+ * types.
312
+ */
313
+ catalogs(): (LocalCatalog | RemoteCatalog)[];
314
+ /**
315
+ * Asks the host for its capabilities once, and builds the engine on the bundled catalogue. The host may also have
316
+ * `credential(provider)`, which returns (or resolves to) the key of a remote provider (`"openai"`, `"elevenlabs"`)
317
+ * or `null`: the engine asks it each time a provider is listed or a remote model called, and keeps no key.
318
+ * Rejects with `host-capabilities` when the host's `capabilities()` fails, `host-capabilities-<field>` when what it
319
+ * reports is malformed.
320
+ */
321
+ static create(host: any): Promise<WebEngine>;
322
+ /**
323
+ * Installs `build` of `model` (the recommended one when left out), telling `onProgress` as it goes; `signal`
324
+ * aborts it, and the promise rejects with `cancelled`, leaving nothing half downloaded.
325
+ */
326
+ install(model: string, build: string | null | undefined, onProgress: (progress: Progress) => void, signal?: AbortSignal | null): Promise<void>;
327
+ /**
328
+ * Loads `build` of `model` (an installed one that runs here, else the recommended one, when left out),
329
+ * installing it first if it is not, as [`WebEngine::install`] does. The model stays in memory while a
330
+ * `LocalModel` of its build lives, or an `Stt` or `Tts` one handed out: freeing them all (`free()`, or letting
331
+ * them be collected) unloads it.
332
+ */
333
+ load(model: string, build: string | null | undefined, onProgress: (progress: Progress) => void, signal?: AbortSignal | null): Promise<LocalModel>;
334
+ /**
335
+ * The local catalogue: its models are `LocalModelInfo`s (builds, install state) and it loads `LocalModel`s.
336
+ */
337
+ localCatalog(): LocalCatalog;
338
+ /**
339
+ * The remote provider `id`: its models are `RemoteModelInfo`s and it loads `RemoteModel`s; throws
340
+ * `catalog-not-found` for an id that is no provider.
341
+ */
342
+ remoteCatalog(id: string): RemoteCatalog;
343
+ /**
344
+ * Removes `build` of `model` (every build of it when left out), except files another build uses; rejects with
345
+ * `build-not-found`, or `model-in-use` while one of those builds is loaded; it waits for installs and loads in
346
+ * progress.
347
+ */
348
+ uninstall(model: string, build?: string | null): Promise<void>;
349
+ }
350
+
351
+ export type InitInput = RequestInfo | URL | Response | BufferSource | WebAssembly.Module;
352
+
353
+ export interface InitOutput {
354
+ readonly memory: WebAssembly.Memory;
355
+ readonly __wbg_endofturn_free: (a: number, b: number) => void;
356
+ readonly __wbg_localcatalog_free: (a: number, b: number) => void;
357
+ readonly __wbg_localmodel_free: (a: number, b: number) => void;
358
+ readonly __wbg_remotecatalog_free: (a: number, b: number) => void;
359
+ readonly __wbg_remotemodel_free: (a: number, b: number) => void;
360
+ readonly __wbg_stt_free: (a: number, b: number) => void;
361
+ readonly __wbg_tts_free: (a: number, b: number) => void;
362
+ readonly __wbg_vad_free: (a: number, b: number) => void;
363
+ readonly __wbg_vadstream_free: (a: number, b: number) => void;
364
+ readonly __wbg_webengine_free: (a: number, b: number) => void;
365
+ readonly endofturn_probability: (a: number, b: number, c: number, d: number) => any;
366
+ readonly endofturn_seconds: (a: number) => number;
367
+ readonly localcatalog_id: (a: number) => [number, number];
368
+ readonly localcatalog_load: (a: number, b: number, c: number, d: number, e: number) => any;
369
+ readonly localcatalog_models: (a: number, b: number, c: number) => any;
370
+ readonly localcatalog_name: (a: number) => [number, number];
371
+ readonly localcatalog_refresh: (a: number) => any;
372
+ readonly localcatalog_status: (a: number) => any;
373
+ readonly localmodel_asEndOfTurn: (a: number) => number;
374
+ readonly localmodel_asStt: (a: number) => number;
375
+ readonly localmodel_asTts: (a: number) => number;
376
+ readonly localmodel_asVad: (a: number) => number;
377
+ readonly localmodel_build: (a: number) => [number, number];
378
+ readonly localmodel_capabilities: (a: number) => [number, number];
379
+ readonly localmodel_id: (a: number) => [number, number];
380
+ readonly remotecatalog_id: (a: number) => [number, number];
381
+ readonly remotecatalog_load: (a: number, b: number, c: number, d: number, e: number) => any;
382
+ readonly remotecatalog_models: (a: number, b: number, c: number) => any;
383
+ readonly remotecatalog_name: (a: number) => [number, number];
384
+ readonly remotecatalog_refresh: (a: number) => any;
385
+ readonly remotecatalog_status: (a: number) => any;
386
+ readonly remotemodel_asEndOfTurn: (a: number) => number;
387
+ readonly remotemodel_asStt: (a: number) => number;
388
+ readonly remotemodel_asTts: (a: number) => number;
389
+ readonly remotemodel_asVad: (a: number) => number;
390
+ readonly remotemodel_capabilities: (a: number) => [number, number];
391
+ readonly remotemodel_id: (a: number) => [number, number];
392
+ readonly remotemodel_provider: (a: number) => [number, number];
393
+ readonly stt_transcribe: (a: number, b: number, c: number, d: number, e: number, f: number) => any;
394
+ readonly tts_speak: (a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number) => any;
395
+ readonly tts_voices: (a: number) => any;
396
+ readonly vad_stream: (a: number, b: number) => any;
397
+ readonly vadstream_accept: (a: number, b: number, c: number) => any;
398
+ readonly vadstream_finish: (a: number) => any;
399
+ readonly vadstream_reset: (a: number) => any;
400
+ readonly vadstream_sampleRate: (a: number) => number;
401
+ readonly vadstream_window: (a: number) => number;
402
+ readonly webengine_backends: (a: number) => [number, number];
403
+ readonly webengine_catalog: (a: number, b: number, c: number) => [number, number, number];
404
+ readonly webengine_catalogs: (a: number) => any;
405
+ readonly webengine_create: (a: any) => any;
406
+ readonly webengine_install: (a: number, b: number, c: number, d: number, e: number, f: number, g: number) => any;
407
+ readonly webengine_load: (a: number, b: number, c: number, d: number, e: number, f: number, g: number) => any;
408
+ readonly webengine_localCatalog: (a: number) => number;
409
+ readonly webengine_remoteCatalog: (a: number, b: number, c: number) => [number, number, number];
410
+ readonly webengine_uninstall: (a: number, b: number, c: number, d: number, e: number) => any;
411
+ readonly wasm_bindgen_63a46d96b29ae508___convert__closures_____invoke___alloc_508e33bd5656020b___string__String__js_sys_9a9f93f03cc98e8d___Promise__true_: (a: number, b: number, c: number, d: number) => any;
412
+ readonly wasm_bindgen_63a46d96b29ae508___convert__closures_____invoke___js_sys_9a9f93f03cc98e8d___Function_fn_wasm_bindgen_63a46d96b29ae508___JsValue_____wasm_bindgen_63a46d96b29ae508___sys__Undefined___js_sys_9a9f93f03cc98e8d___Function_fn_wasm_bindgen_63a46d96b29ae508___JsValue_____wasm_bindgen_63a46d96b29ae508___sys__Undefined_______true_: (a: number, b: number, c: any, d: any) => void;
413
+ readonly wasm_bindgen_63a46d96b29ae508___convert__closures_____invoke___wasm_bindgen_63a46d96b29ae508___JsValue__core_ed718c3d60ebd546___result__Result_____wasm_bindgen_63a46d96b29ae508___JsError___true_: (a: number, b: number, c: any) => [number, number];
414
+ readonly wasm_bindgen_63a46d96b29ae508___convert__closures_____invoke_______true_: (a: number, b: number) => void;
415
+ readonly __wbindgen_malloc_command_export: (a: number, b: number) => number;
416
+ readonly __wbindgen_realloc_command_export: (a: number, b: number, c: number, d: number) => number;
417
+ readonly __wbindgen_exn_store_command_export: (a: number) => void;
418
+ readonly __externref_table_alloc_command_export: () => number;
419
+ readonly __wbindgen_externrefs: WebAssembly.Table;
420
+ readonly __wbindgen_destroy_closure_command_export: (a: number, b: number) => void;
421
+ readonly __wbindgen_free_command_export: (a: number, b: number, c: number) => void;
422
+ readonly __externref_drop_slice_command_export: (a: number, b: number) => void;
423
+ readonly __externref_table_dealloc_command_export: (a: number) => void;
424
+ readonly __wbindgen_start: () => void;
425
+ }
426
+
427
+ export type SyncInitInput = BufferSource | WebAssembly.Module;
428
+
429
+ /**
430
+ * Instantiates the given `module`, which can either be bytes or
431
+ * a precompiled `WebAssembly.Module`.
432
+ *
433
+ * @param {{ module: SyncInitInput }} module - Passing `SyncInitInput` directly is deprecated.
434
+ *
435
+ * @returns {InitOutput}
436
+ */
437
+ export function initSync(module: { module: SyncInitInput } | SyncInitInput): InitOutput;
438
+
439
+ /**
440
+ * If `module_or_path` is {RequestInfo} or {URL}, makes a request and
441
+ * for everything else, calls `WebAssembly.instantiate` directly.
442
+ *
443
+ * @param {{ module_or_path: InitInput | Promise<InitInput> }} module_or_path - Passing `InitInput` directly is deprecated.
444
+ *
445
+ * @returns {Promise<InitOutput>}
446
+ */
447
+ export default function __wbg_init (module_or_path?: { module_or_path: InitInput | Promise<InitInput> } | InitInput | Promise<InitInput>): Promise<InitOutput>;