@sidevoice/engine 0.0.0-stage → 0.3.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.
Binary file
@@ -0,0 +1,73 @@
1
+ /* tslint:disable */
2
+ /* eslint-disable */
3
+ export const memory: WebAssembly.Memory;
4
+ export const __wbg_endofturn_free: (a: number, b: number) => void;
5
+ export const __wbg_localcatalog_free: (a: number, b: number) => void;
6
+ export const __wbg_localmodel_free: (a: number, b: number) => void;
7
+ export const __wbg_remotecatalog_free: (a: number, b: number) => void;
8
+ export const __wbg_remotemodel_free: (a: number, b: number) => void;
9
+ export const __wbg_stt_free: (a: number, b: number) => void;
10
+ export const __wbg_tts_free: (a: number, b: number) => void;
11
+ export const __wbg_vad_free: (a: number, b: number) => void;
12
+ export const __wbg_vadstream_free: (a: number, b: number) => void;
13
+ export const __wbg_webengine_free: (a: number, b: number) => void;
14
+ export const endofturn_probability: (a: number, b: number, c: number, d: number) => any;
15
+ export const endofturn_seconds: (a: number) => number;
16
+ export const localcatalog_id: (a: number) => [number, number];
17
+ export const localcatalog_load: (a: number, b: number, c: number, d: number, e: number) => any;
18
+ export const localcatalog_models: (a: number, b: number, c: number) => any;
19
+ export const localcatalog_name: (a: number) => [number, number];
20
+ export const localcatalog_refresh: (a: number) => any;
21
+ export const localcatalog_status: (a: number) => any;
22
+ export const localmodel_asEndOfTurn: (a: number) => number;
23
+ export const localmodel_asStt: (a: number) => number;
24
+ export const localmodel_asTts: (a: number) => number;
25
+ export const localmodel_asVad: (a: number) => number;
26
+ export const localmodel_build: (a: number) => [number, number];
27
+ export const localmodel_capabilities: (a: number) => [number, number];
28
+ export const localmodel_id: (a: number) => [number, number];
29
+ export const remotecatalog_id: (a: number) => [number, number];
30
+ export const remotecatalog_load: (a: number, b: number, c: number, d: number, e: number) => any;
31
+ export const remotecatalog_models: (a: number, b: number, c: number) => any;
32
+ export const remotecatalog_name: (a: number) => [number, number];
33
+ export const remotecatalog_refresh: (a: number) => any;
34
+ export const remotecatalog_status: (a: number) => any;
35
+ export const remotemodel_asEndOfTurn: (a: number) => number;
36
+ export const remotemodel_asStt: (a: number) => number;
37
+ export const remotemodel_asTts: (a: number) => number;
38
+ export const remotemodel_asVad: (a: number) => number;
39
+ export const remotemodel_capabilities: (a: number) => [number, number];
40
+ export const remotemodel_id: (a: number) => [number, number];
41
+ export const remotemodel_provider: (a: number) => [number, number];
42
+ export const stt_transcribe: (a: number, b: number, c: number, d: number, e: number, f: number) => any;
43
+ export const tts_speak: (a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number) => any;
44
+ export const tts_voices: (a: number) => any;
45
+ export const vad_stream: (a: number, b: number) => any;
46
+ export const vadstream_accept: (a: number, b: number, c: number) => any;
47
+ export const vadstream_finish: (a: number) => any;
48
+ export const vadstream_reset: (a: number) => any;
49
+ export const vadstream_sampleRate: (a: number) => number;
50
+ export const vadstream_window: (a: number) => number;
51
+ export const webengine_backends: (a: number) => [number, number];
52
+ export const webengine_catalog: (a: number, b: number, c: number) => [number, number, number];
53
+ export const webengine_catalogs: (a: number) => any;
54
+ export const webengine_create: (a: any) => any;
55
+ export const webengine_install: (a: number, b: number, c: number, d: number, e: number, f: number, g: number) => any;
56
+ export const webengine_load: (a: number, b: number, c: number, d: number, e: number, f: number, g: number) => any;
57
+ export const webengine_localCatalog: (a: number) => number;
58
+ export const webengine_remoteCatalog: (a: number, b: number, c: number) => [number, number, number];
59
+ export const webengine_uninstall: (a: number, b: number, c: number, d: number, e: number) => any;
60
+ export const wasm_bindgen_63a46d96b29ae508___convert__closures_____invoke___alloc_508e33bd5656020b___string__String__js_sys_9a9f93f03cc98e8d___Promise__true_: (a: number, b: number, c: number, d: number) => any;
61
+ export const 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;
62
+ export const 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];
63
+ export const wasm_bindgen_63a46d96b29ae508___convert__closures_____invoke_______true_: (a: number, b: number) => void;
64
+ export const __wbindgen_malloc_command_export: (a: number, b: number) => number;
65
+ export const __wbindgen_realloc_command_export: (a: number, b: number, c: number, d: number) => number;
66
+ export const __wbindgen_exn_store_command_export: (a: number) => void;
67
+ export const __externref_table_alloc_command_export: () => number;
68
+ export const __wbindgen_externrefs: WebAssembly.Table;
69
+ export const __wbindgen_destroy_closure_command_export: (a: number, b: number) => void;
70
+ export const __wbindgen_free_command_export: (a: number, b: number, c: number) => void;
71
+ export const __externref_drop_slice_command_export: (a: number, b: number) => void;
72
+ export const __externref_table_dealloc_command_export: (a: number) => void;
73
+ export const __wbindgen_start: () => void;
@@ -0,0 +1 @@
1
+ export function importEspeak() { return import('espeak-ng'); }
@@ -0,0 +1 @@
1
+ export function importTransformers() { return import('@huggingface/transformers'); }
@@ -0,0 +1,21 @@
1
+
2
+ export async function detectLanguage(pipeline, Tensor, audio) {
3
+ const config = pipeline.model.generation_config ?? {};
4
+ const languages = Object.entries(config.lang_to_id ?? {});
5
+ if (config.is_multilingual === false || languages.length === 0) return null;
6
+ const { input_features } = await pipeline.processor(audio.subarray(0, 30 * 16000));
7
+ const start = new Tensor('int64', BigInt64Array.from([BigInt(config.decoder_start_token_id)]), [1, 1]);
8
+ const outputs = await pipeline.model({ input_features, decoder_input_ids: start });
9
+ try {
10
+ const logits = outputs.logits.to('float32');
11
+ const scores = logits.data.subarray(logits.data.length - logits.dims.at(-1));
12
+ let best = null;
13
+ for (const [token, id] of languages) {
14
+ if (best === null || scores[id] > scores[best[1]]) best = [token, id];
15
+ }
16
+ return best[0].replace(/^<\|/, '').replace(/\|>$/, '');
17
+ } finally {
18
+ input_features.dispose?.();
19
+ for (const value of Object.values(outputs)) value?.dispose?.();
20
+ }
21
+ }
@@ -0,0 +1,33 @@
1
+
2
+ export function serve(env, owner, open) {
3
+ const before = { fetch: env.fetch, useCustomCache: env.useCustomCache, customCache: env.customCache };
4
+ // The path after `<owner>/`: `m3/onnx/model.onnx` (a local path) or `m3/resolve/main/onnx/model.onnx` (a URL).
5
+ const ours = (key) => {
6
+ const text = String(key instanceof Request ? key.url : key);
7
+ const at = text.indexOf(owner + '/');
8
+ return at < 0 ? null : text.slice(at + owner.length + 1);
9
+ };
10
+ // Where a file that is not ours is cached: where transformers.js would have cached it.
11
+ const other = async () => {
12
+ if (before.useCustomCache) return before.customCache;
13
+ if (env.useBrowserCache && typeof caches !== 'undefined') {
14
+ try { return await caches.open(env.cacheKey); } catch { return null; }
15
+ }
16
+ return null;
17
+ };
18
+ env.customCache = {
19
+ async match(key) {
20
+ const path = ours(key);
21
+ if (path === null) return (await other())?.match(key);
22
+ const blob = await open(path);
23
+ if (!blob) return undefined;
24
+ return new Response(blob, { headers: { 'content-length': String(blob.size) } });
25
+ },
26
+ async put(key, response) {
27
+ if (ours(key) === null) return (await other())?.put(key, response);
28
+ },
29
+ };
30
+ env.useCustomCache = true;
31
+ env.fetch = (url, init) => ours(url) === null ? before.fetch(url, init) : Promise.resolve(new Response(null, { status: 404 }));
32
+ return () => Object.assign(env, before);
33
+ }
@@ -0,0 +1,8 @@
1
+
2
+ export function yieldToPage() {
3
+ return new Promise((resolve) => {
4
+ const channel = new MessageChannel();
5
+ channel.port1.onmessage = () => { channel.port1.close(); resolve(); };
6
+ channel.port2.postMessage(null);
7
+ });
8
+ }
@@ -0,0 +1,5 @@
1
+
2
+ export async function smartTurnRun(model, Tensor, name, features, mels, frames) {
3
+ const outputs = await model({ [name]: new Tensor('float32', features, [1, mels, frames]) });
4
+ return Object.values(outputs)[0].data[0];
5
+ }
@@ -0,0 +1,7 @@
1
+
2
+ export async function sileroRun(model, Tensor, input, state, rate) {
3
+ state ??= new Tensor('float32', new Float32Array(2 * 1 * 128), [2, 1, 128]);
4
+ const sr = new Tensor('int64', BigInt64Array.from([BigInt(rate)]), []);
5
+ const { output, stateN } = await model({ input: new Tensor('float32', input, [1, input.length]), sr, state });
6
+ return [output.data[0], stateN];
7
+ }
package/package.json CHANGED
@@ -1,6 +1,35 @@
1
1
  {
2
2
  "name": "@sidevoice/engine",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.3.1",
4
+ "description": "Sidevoice engine for the web: local voice models in the browser, as WebAssembly.",
5
+ "license": "Apache-2.0",
6
+ "type": "module",
7
+ "exports": {
8
+ ".": "./dist/sidevoice_engine.js"
9
+ },
10
+ "types": "./dist/sidevoice_engine.d.ts",
11
+ "files": [
12
+ "dist/",
13
+ "THIRD_PARTY_NOTICES.md"
14
+ ],
15
+ "keywords": [
16
+ "sidevoice",
17
+ "voice",
18
+ "speech",
19
+ "stt",
20
+ "tts",
21
+ "wasm"
22
+ ],
23
+ "homepage": "https://github.com/sidevoice/sidevoice-engine#readme",
24
+ "bugs": {
25
+ "url": "https://github.com/sidevoice/sidevoice-engine/issues"
26
+ },
27
+ "repository": {
28
+ "type": "git",
29
+ "url": "git+https://github.com/sidevoice/sidevoice-engine.git"
30
+ },
31
+ "dependencies": {
32
+ "@huggingface/transformers": "4.3.1",
33
+ "espeak-ng": "1.0.2"
34
+ }
35
+ }