@micdrop/web 1.1.3 → 1.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.
- package/README.md +18 -1
- package/assets/silero_vad_v5.onnx +0 -0
- package/dist/silero.d.mts +8 -3
- package/dist/silero.d.ts +8 -3
- package/dist/silero.js +5 -2
- package/dist/silero.js.map +1 -1
- package/dist/silero.mjs +5 -2
- package/dist/silero.mjs.map +1 -1
- package/dist/vite.d.mts +21 -0
- package/dist/vite.d.ts +21 -0
- package/dist/vite.js +87 -0
- package/dist/vite.js.map +1 -0
- package/dist/vite.mjs +56 -0
- package/dist/vite.mjs.map +1 -0
- package/package.json +20 -4
package/README.md
CHANGED
|
@@ -28,6 +28,22 @@ npm install @micdrop/web
|
|
|
28
28
|
|
|
29
29
|
That's it 🎉 No configuration, no asset to copy.
|
|
30
30
|
|
|
31
|
+
### Vite plugin (strongly recommended)
|
|
32
|
+
|
|
33
|
+
If your app is built with Vite and uses Silero VAD or turn detection, add the plugin:
|
|
34
|
+
|
|
35
|
+
```ts
|
|
36
|
+
// vite.config.ts
|
|
37
|
+
import { micdrop } from '@micdrop/web/vite'
|
|
38
|
+
import { defineConfig } from 'vite'
|
|
39
|
+
|
|
40
|
+
export default defineConfig({
|
|
41
|
+
plugins: [micdrop()],
|
|
42
|
+
})
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
It ships the Silero model with your app and lets Vite emit the ONNX runtime WebAssembly from the version you installed. Without it, both are fetched from jsDelivr and unpkg when a call starts, and a CDN outage, a firewall or an ad blocker keeps voice detection from starting.
|
|
46
|
+
|
|
31
47
|
## Usage
|
|
32
48
|
|
|
33
49
|
```ts
|
|
@@ -43,7 +59,8 @@ Micdrop.on('StateChange', (state) => {
|
|
|
43
59
|
## Browser specifics
|
|
44
60
|
|
|
45
61
|
- `import '@micdrop/web/silero'` adds the Silero voice detection, and only then does the ONNX runtime enter your bundle
|
|
46
|
-
- `
|
|
62
|
+
- `@micdrop/web/vite` bundles the Silero model and the ONNX runtime files with your app, see above
|
|
63
|
+
- `setSileroOptions({ model, wasmPath })` serves the Silero model and the ONNX runtime from your own domain with another bundler
|
|
47
64
|
- `getSpeakerOutput()` gives the node the assistant voice comes out of, to analyse or process it
|
|
48
65
|
- `audioContext` is the shared `AudioContext`
|
|
49
66
|
|
|
Binary file
|
package/dist/silero.d.mts
CHANGED
|
@@ -5,8 +5,12 @@ declare const DEFAULT_SILERO_MODEL_URL = "https://cdn.jsdelivr.net/npm/@ricky012
|
|
|
5
5
|
interface OnnxSileroOptions {
|
|
6
6
|
/** Address of the Silero v5 model, or the bytes of it */
|
|
7
7
|
model?: string | ArrayBuffer;
|
|
8
|
-
/**
|
|
9
|
-
|
|
8
|
+
/**
|
|
9
|
+
* Where the ONNX runtime loads its WebAssembly files from. `false` leaves
|
|
10
|
+
* them to the runtime, which finds them next to itself once a bundler has
|
|
11
|
+
* emitted them, as the `@micdrop/web/vite` plugin does.
|
|
12
|
+
*/
|
|
13
|
+
wasmPath?: string | false;
|
|
10
14
|
}
|
|
11
15
|
/**
|
|
12
16
|
* Runs the Silero model in the browser, on the ONNX WebAssembly runtime.
|
|
@@ -34,7 +38,8 @@ declare function queueOnnxRun<T>(run: () => Promise<T>): Promise<T>;
|
|
|
34
38
|
|
|
35
39
|
/**
|
|
36
40
|
* Says where the Silero model comes from, to serve it from your own domain
|
|
37
|
-
* rather than from a CDN, or to hand over its bytes directly.
|
|
41
|
+
* rather than from a CDN, or to hand over its bytes directly. Merged into the
|
|
42
|
+
* options already set, so it keeps what the `@micdrop/web/vite` plugin chose.
|
|
38
43
|
* @param next - Address or bytes of the model, and of the ONNX runtime
|
|
39
44
|
*/
|
|
40
45
|
declare function setSileroOptions(next: OnnxSileroOptions): void;
|
package/dist/silero.d.ts
CHANGED
|
@@ -5,8 +5,12 @@ declare const DEFAULT_SILERO_MODEL_URL = "https://cdn.jsdelivr.net/npm/@ricky012
|
|
|
5
5
|
interface OnnxSileroOptions {
|
|
6
6
|
/** Address of the Silero v5 model, or the bytes of it */
|
|
7
7
|
model?: string | ArrayBuffer;
|
|
8
|
-
/**
|
|
9
|
-
|
|
8
|
+
/**
|
|
9
|
+
* Where the ONNX runtime loads its WebAssembly files from. `false` leaves
|
|
10
|
+
* them to the runtime, which finds them next to itself once a bundler has
|
|
11
|
+
* emitted them, as the `@micdrop/web/vite` plugin does.
|
|
12
|
+
*/
|
|
13
|
+
wasmPath?: string | false;
|
|
10
14
|
}
|
|
11
15
|
/**
|
|
12
16
|
* Runs the Silero model in the browser, on the ONNX WebAssembly runtime.
|
|
@@ -34,7 +38,8 @@ declare function queueOnnxRun<T>(run: () => Promise<T>): Promise<T>;
|
|
|
34
38
|
|
|
35
39
|
/**
|
|
36
40
|
* Says where the Silero model comes from, to serve it from your own domain
|
|
37
|
-
* rather than from a CDN, or to hand over its bytes directly.
|
|
41
|
+
* rather than from a CDN, or to hand over its bytes directly. Merged into the
|
|
42
|
+
* options already set, so it keeps what the `@micdrop/web/vite` plugin chose.
|
|
38
43
|
* @param next - Address or bytes of the model, and of the ONNX runtime
|
|
39
44
|
*/
|
|
40
45
|
declare function setSileroOptions(next: OnnxSileroOptions): void;
|
package/dist/silero.js
CHANGED
|
@@ -65,7 +65,10 @@ var OnnxSileroModel = class {
|
|
|
65
65
|
}
|
|
66
66
|
async load() {
|
|
67
67
|
if (this.session) return;
|
|
68
|
-
|
|
68
|
+
const wasmPath = this.options.wasmPath ?? DEFAULT_WASM_PATH;
|
|
69
|
+
if (wasmPath !== false) {
|
|
70
|
+
ort.env.wasm.wasmPaths = wasmPath;
|
|
71
|
+
}
|
|
69
72
|
const source = this.options.model ?? DEFAULT_SILERO_MODEL_URL;
|
|
70
73
|
let bytes;
|
|
71
74
|
if (typeof source === "string") {
|
|
@@ -103,7 +106,7 @@ function newState() {
|
|
|
103
106
|
// src/silero.ts
|
|
104
107
|
var options = {};
|
|
105
108
|
function setSileroOptions(next) {
|
|
106
|
-
options = next;
|
|
109
|
+
options = { ...options, ...next };
|
|
107
110
|
}
|
|
108
111
|
(0, import_client2.setSileroModelLoader)(async () => {
|
|
109
112
|
const model = new OnnxSileroModel(options);
|
package/dist/silero.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/silero.ts","../src/vad/OnnxSileroModel.ts","../src/vad/onnxQueue.ts"],"sourcesContent":["import { setSileroModelLoader } from '@micdrop/client'\nimport { OnnxSileroModel, OnnxSileroOptions } from './vad/OnnxSileroModel'\n\nexport * from './vad/OnnxSileroModel'\nexport * from './vad/onnxQueue'\n\nlet options: OnnxSileroOptions = {}\n\n/**\n * Says where the Silero model comes from, to serve it from your own domain\n * rather than from a CDN, or to hand over its bytes directly.\n * @param next - Address or bytes of the model, and of the ONNX runtime\n */\nexport function setSileroOptions(next: OnnxSileroOptions) {\n options = next\n}\n\n// The ONNX runtime weighs more than the rest of Micdrop put together, so it\n// only enters the bundle of an app that imports this file\nsetSileroModelLoader(async () => {\n const model = new OnnxSileroModel(options)\n await model.load()\n return model\n})\n","import { SileroModel, SILERO_SAMPLE_RATE } from '@micdrop/client'\nimport * as ort from 'onnxruntime-web'\nimport { queueOnnxRun } from './onnxQueue'\n\n/** Where the model is fetched from, when the app does not provide it */\nexport const DEFAULT_SILERO_MODEL_URL =\n 'https://cdn.jsdelivr.net/npm/@ricky0123/vad-web@0.0.30/dist/silero_vad_v5.onnx'\n\n// onnxruntime-web@1.23 is not hosted on jsdelivr (its dist exceeds the CDN size\n// limit, so every file 404s). unpkg serves it, so the wasm backend comes from\n// there instead.\nconst DEFAULT_WASM_PATH = 'https://unpkg.com/onnxruntime-web@1.23.2/dist/'\n\nexport interface OnnxSileroOptions {\n /** Address of the Silero v5 model, or the bytes of it */\n model?: string | ArrayBuffer\n
|
|
1
|
+
{"version":3,"sources":["../src/silero.ts","../src/vad/OnnxSileroModel.ts","../src/vad/onnxQueue.ts"],"sourcesContent":["import { setSileroModelLoader } from '@micdrop/client'\nimport { OnnxSileroModel, OnnxSileroOptions } from './vad/OnnxSileroModel'\n\nexport * from './vad/OnnxSileroModel'\nexport * from './vad/onnxQueue'\n\nlet options: OnnxSileroOptions = {}\n\n/**\n * Says where the Silero model comes from, to serve it from your own domain\n * rather than from a CDN, or to hand over its bytes directly. Merged into the\n * options already set, so it keeps what the `@micdrop/web/vite` plugin chose.\n * @param next - Address or bytes of the model, and of the ONNX runtime\n */\nexport function setSileroOptions(next: OnnxSileroOptions) {\n options = { ...options, ...next }\n}\n\n// The ONNX runtime weighs more than the rest of Micdrop put together, so it\n// only enters the bundle of an app that imports this file\nsetSileroModelLoader(async () => {\n const model = new OnnxSileroModel(options)\n await model.load()\n return model\n})\n","import { SileroModel, SILERO_SAMPLE_RATE } from '@micdrop/client'\nimport * as ort from 'onnxruntime-web'\nimport { queueOnnxRun } from './onnxQueue'\n\n/** Where the model is fetched from, when the app does not provide it */\nexport const DEFAULT_SILERO_MODEL_URL =\n 'https://cdn.jsdelivr.net/npm/@ricky0123/vad-web@0.0.30/dist/silero_vad_v5.onnx'\n\n// onnxruntime-web@1.23 is not hosted on jsdelivr (its dist exceeds the CDN size\n// limit, so every file 404s). unpkg serves it, so the wasm backend comes from\n// there instead.\nconst DEFAULT_WASM_PATH = 'https://unpkg.com/onnxruntime-web@1.23.2/dist/'\n\nexport interface OnnxSileroOptions {\n /** Address of the Silero v5 model, or the bytes of it */\n model?: string | ArrayBuffer\n /**\n * Where the ONNX runtime loads its WebAssembly files from. `false` leaves\n * them to the runtime, which finds them next to itself once a bundler has\n * emitted them, as the `@micdrop/web/vite` plugin does.\n */\n wasmPath?: string | false\n}\n\nlet loading: Promise<ArrayBuffer> | undefined\n\n/**\n * Runs the Silero model in the browser, on the ONNX WebAssembly runtime.\n *\n * The state machine that turns its answers into turns lives in\n * `@micdrop/client`, this only scores windows of audio.\n */\nexport class OnnxSileroModel implements SileroModel {\n private session: ort.InferenceSession | undefined\n private state: ort.Tensor\n private sampleRate: ort.Tensor\n\n constructor(private options: OnnxSileroOptions = {}) {\n this.state = newState()\n this.sampleRate = new ort.Tensor('int64', [BigInt(SILERO_SAMPLE_RATE)])\n }\n\n async load() {\n if (this.session) return\n\n const wasmPath = this.options.wasmPath ?? DEFAULT_WASM_PATH\n if (wasmPath !== false) {\n ort.env.wasm.wasmPaths = wasmPath\n }\n\n const source = this.options.model ?? DEFAULT_SILERO_MODEL_URL\n let bytes: ArrayBuffer\n if (typeof source === 'string') {\n // Fetched once per page, the model is a couple of megabytes\n loading =\n loading ?? fetch(source).then((response) => response.arrayBuffer())\n bytes = await loading\n } else {\n bytes = source\n }\n\n this.session = await ort.InferenceSession.create(bytes)\n }\n\n async process(frame: Float32Array): Promise<number> {\n if (!this.session) await this.load()\n\n const output = await queueOnnxRun(() =>\n this.session!.run({\n input: new ort.Tensor('float32', frame, [1, frame.length]),\n state: this.state,\n sr: this.sampleRate,\n })\n )\n\n this.state = output.stateN as ort.Tensor\n return (output.output.data as Float32Array)[0]\n }\n\n reset() {\n this.state = newState()\n }\n\n async release() {\n await this.session?.release()\n this.session = undefined\n }\n}\n\n/** The memory the model carries from one window to the next, emptied */\nfunction newState(): ort.Tensor {\n return new ort.Tensor('float32', new Float32Array(2 * 128), [2, 1, 128])\n}\n","/**\n * Runs one inference at a time, whichever model asks.\n *\n * The ONNX runtime keeps a single active session for the whole WebAssembly\n * module, so two models cannot be in flight together. A model running on the\n * graphics card yields while it waits for the device, and a detector scoring\n * its next window on top of it makes both fail, one with `Session already\n * started` and the other with `Session mismatch`.\n *\n * The queue lives on the global scope so every Micdrop model takes the same\n * turns, `@micdrop/smart-turn` included, which ships separately and holds the\n * same few lines.\n */\nconst globalScope = globalThis as typeof globalThis & {\n micdropOnnxQueue?: Promise<unknown>\n}\n\n/**\n * Waits for the models ahead in the queue, then runs\n * @param run - The inference to run once the runtime is free\n */\nexport function queueOnnxRun<T>(run: () => Promise<T>): Promise<T> {\n const started = (globalScope.micdropOnnxQueue ?? Promise.resolve()).then(\n run,\n run\n )\n // A failed run still lets the next one through\n globalScope.micdropOnnxQueue = started.catch(() => undefined)\n return started\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAAAA,iBAAqC;;;ACArC,oBAAgD;AAChD,UAAqB;;;ACYrB,IAAM,cAAc;AAQb,SAAS,aAAgB,KAAmC;AACjE,QAAM,WAAW,YAAY,oBAAoB,QAAQ,QAAQ,GAAG;AAAA,IAClE;AAAA,IACA;AAAA,EACF;AAEA,cAAY,mBAAmB,QAAQ,MAAM,MAAM,MAAS;AAC5D,SAAO;AACT;;;ADxBO,IAAM,2BACX;AAKF,IAAM,oBAAoB;AAa1B,IAAI;AAQG,IAAM,kBAAN,MAA6C;AAAA,EAKlD,YAAoBC,WAA6B,CAAC,GAAG;AAAjC,mBAAAA;AAClB,SAAK,QAAQ,SAAS;AACtB,SAAK,aAAa,IAAQ,WAAO,SAAS,CAAC,OAAO,gCAAkB,CAAC,CAAC;AAAA,EACxE;AAAA,EAEA,MAAM,OAAO;AACX,QAAI,KAAK,QAAS;AAElB,UAAM,WAAW,KAAK,QAAQ,YAAY;AAC1C,QAAI,aAAa,OAAO;AACtB,MAAI,QAAI,KAAK,YAAY;AAAA,IAC3B;AAEA,UAAM,SAAS,KAAK,QAAQ,SAAS;AACrC,QAAI;AACJ,QAAI,OAAO,WAAW,UAAU;AAE9B,gBACE,WAAW,MAAM,MAAM,EAAE,KAAK,CAAC,aAAa,SAAS,YAAY,CAAC;AACpE,cAAQ,MAAM;AAAA,IAChB,OAAO;AACL,cAAQ;AAAA,IACV;AAEA,SAAK,UAAU,MAAU,qBAAiB,OAAO,KAAK;AAAA,EACxD;AAAA,EAEA,MAAM,QAAQ,OAAsC;AAClD,QAAI,CAAC,KAAK,QAAS,OAAM,KAAK,KAAK;AAEnC,UAAM,SAAS,MAAM;AAAA,MAAa,MAChC,KAAK,QAAS,IAAI;AAAA,QAChB,OAAO,IAAQ,WAAO,WAAW,OAAO,CAAC,GAAG,MAAM,MAAM,CAAC;AAAA,QACzD,OAAO,KAAK;AAAA,QACZ,IAAI,KAAK;AAAA,MACX,CAAC;AAAA,IACH;AAEA,SAAK,QAAQ,OAAO;AACpB,WAAQ,OAAO,OAAO,KAAsB,CAAC;AAAA,EAC/C;AAAA,EAEA,QAAQ;AACN,SAAK,QAAQ,SAAS;AAAA,EACxB;AAAA,EAEA,MAAM,UAAU;AACd,UAAM,KAAK,SAAS,QAAQ;AAC5B,SAAK,UAAU;AAAA,EACjB;AACF;AAGA,SAAS,WAAuB;AAC9B,SAAO,IAAQ,WAAO,WAAW,IAAI,aAAa,IAAI,GAAG,GAAG,CAAC,GAAG,GAAG,GAAG,CAAC;AACzE;;;ADtFA,IAAI,UAA6B,CAAC;AAQ3B,SAAS,iBAAiB,MAAyB;AACxD,YAAU,EAAE,GAAG,SAAS,GAAG,KAAK;AAClC;AAAA,IAIA,qCAAqB,YAAY;AAC/B,QAAM,QAAQ,IAAI,gBAAgB,OAAO;AACzC,QAAM,MAAM,KAAK;AACjB,SAAO;AACT,CAAC;","names":["import_client","options"]}
|
package/dist/silero.mjs
CHANGED
|
@@ -28,7 +28,10 @@ var OnnxSileroModel = class {
|
|
|
28
28
|
}
|
|
29
29
|
async load() {
|
|
30
30
|
if (this.session) return;
|
|
31
|
-
|
|
31
|
+
const wasmPath = this.options.wasmPath ?? DEFAULT_WASM_PATH;
|
|
32
|
+
if (wasmPath !== false) {
|
|
33
|
+
ort.env.wasm.wasmPaths = wasmPath;
|
|
34
|
+
}
|
|
32
35
|
const source = this.options.model ?? DEFAULT_SILERO_MODEL_URL;
|
|
33
36
|
let bytes;
|
|
34
37
|
if (typeof source === "string") {
|
|
@@ -66,7 +69,7 @@ function newState() {
|
|
|
66
69
|
// src/silero.ts
|
|
67
70
|
var options = {};
|
|
68
71
|
function setSileroOptions(next) {
|
|
69
|
-
options = next;
|
|
72
|
+
options = { ...options, ...next };
|
|
70
73
|
}
|
|
71
74
|
setSileroModelLoader(async () => {
|
|
72
75
|
const model = new OnnxSileroModel(options);
|
package/dist/silero.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/silero.ts","../src/vad/OnnxSileroModel.ts","../src/vad/onnxQueue.ts"],"sourcesContent":["import { setSileroModelLoader } from '@micdrop/client'\nimport { OnnxSileroModel, OnnxSileroOptions } from './vad/OnnxSileroModel'\n\nexport * from './vad/OnnxSileroModel'\nexport * from './vad/onnxQueue'\n\nlet options: OnnxSileroOptions = {}\n\n/**\n * Says where the Silero model comes from, to serve it from your own domain\n * rather than from a CDN, or to hand over its bytes directly.\n * @param next - Address or bytes of the model, and of the ONNX runtime\n */\nexport function setSileroOptions(next: OnnxSileroOptions) {\n options = next\n}\n\n// The ONNX runtime weighs more than the rest of Micdrop put together, so it\n// only enters the bundle of an app that imports this file\nsetSileroModelLoader(async () => {\n const model = new OnnxSileroModel(options)\n await model.load()\n return model\n})\n","import { SileroModel, SILERO_SAMPLE_RATE } from '@micdrop/client'\nimport * as ort from 'onnxruntime-web'\nimport { queueOnnxRun } from './onnxQueue'\n\n/** Where the model is fetched from, when the app does not provide it */\nexport const DEFAULT_SILERO_MODEL_URL =\n 'https://cdn.jsdelivr.net/npm/@ricky0123/vad-web@0.0.30/dist/silero_vad_v5.onnx'\n\n// onnxruntime-web@1.23 is not hosted on jsdelivr (its dist exceeds the CDN size\n// limit, so every file 404s). unpkg serves it, so the wasm backend comes from\n// there instead.\nconst DEFAULT_WASM_PATH = 'https://unpkg.com/onnxruntime-web@1.23.2/dist/'\n\nexport interface OnnxSileroOptions {\n /** Address of the Silero v5 model, or the bytes of it */\n model?: string | ArrayBuffer\n
|
|
1
|
+
{"version":3,"sources":["../src/silero.ts","../src/vad/OnnxSileroModel.ts","../src/vad/onnxQueue.ts"],"sourcesContent":["import { setSileroModelLoader } from '@micdrop/client'\nimport { OnnxSileroModel, OnnxSileroOptions } from './vad/OnnxSileroModel'\n\nexport * from './vad/OnnxSileroModel'\nexport * from './vad/onnxQueue'\n\nlet options: OnnxSileroOptions = {}\n\n/**\n * Says where the Silero model comes from, to serve it from your own domain\n * rather than from a CDN, or to hand over its bytes directly. Merged into the\n * options already set, so it keeps what the `@micdrop/web/vite` plugin chose.\n * @param next - Address or bytes of the model, and of the ONNX runtime\n */\nexport function setSileroOptions(next: OnnxSileroOptions) {\n options = { ...options, ...next }\n}\n\n// The ONNX runtime weighs more than the rest of Micdrop put together, so it\n// only enters the bundle of an app that imports this file\nsetSileroModelLoader(async () => {\n const model = new OnnxSileroModel(options)\n await model.load()\n return model\n})\n","import { SileroModel, SILERO_SAMPLE_RATE } from '@micdrop/client'\nimport * as ort from 'onnxruntime-web'\nimport { queueOnnxRun } from './onnxQueue'\n\n/** Where the model is fetched from, when the app does not provide it */\nexport const DEFAULT_SILERO_MODEL_URL =\n 'https://cdn.jsdelivr.net/npm/@ricky0123/vad-web@0.0.30/dist/silero_vad_v5.onnx'\n\n// onnxruntime-web@1.23 is not hosted on jsdelivr (its dist exceeds the CDN size\n// limit, so every file 404s). unpkg serves it, so the wasm backend comes from\n// there instead.\nconst DEFAULT_WASM_PATH = 'https://unpkg.com/onnxruntime-web@1.23.2/dist/'\n\nexport interface OnnxSileroOptions {\n /** Address of the Silero v5 model, or the bytes of it */\n model?: string | ArrayBuffer\n /**\n * Where the ONNX runtime loads its WebAssembly files from. `false` leaves\n * them to the runtime, which finds them next to itself once a bundler has\n * emitted them, as the `@micdrop/web/vite` plugin does.\n */\n wasmPath?: string | false\n}\n\nlet loading: Promise<ArrayBuffer> | undefined\n\n/**\n * Runs the Silero model in the browser, on the ONNX WebAssembly runtime.\n *\n * The state machine that turns its answers into turns lives in\n * `@micdrop/client`, this only scores windows of audio.\n */\nexport class OnnxSileroModel implements SileroModel {\n private session: ort.InferenceSession | undefined\n private state: ort.Tensor\n private sampleRate: ort.Tensor\n\n constructor(private options: OnnxSileroOptions = {}) {\n this.state = newState()\n this.sampleRate = new ort.Tensor('int64', [BigInt(SILERO_SAMPLE_RATE)])\n }\n\n async load() {\n if (this.session) return\n\n const wasmPath = this.options.wasmPath ?? DEFAULT_WASM_PATH\n if (wasmPath !== false) {\n ort.env.wasm.wasmPaths = wasmPath\n }\n\n const source = this.options.model ?? DEFAULT_SILERO_MODEL_URL\n let bytes: ArrayBuffer\n if (typeof source === 'string') {\n // Fetched once per page, the model is a couple of megabytes\n loading =\n loading ?? fetch(source).then((response) => response.arrayBuffer())\n bytes = await loading\n } else {\n bytes = source\n }\n\n this.session = await ort.InferenceSession.create(bytes)\n }\n\n async process(frame: Float32Array): Promise<number> {\n if (!this.session) await this.load()\n\n const output = await queueOnnxRun(() =>\n this.session!.run({\n input: new ort.Tensor('float32', frame, [1, frame.length]),\n state: this.state,\n sr: this.sampleRate,\n })\n )\n\n this.state = output.stateN as ort.Tensor\n return (output.output.data as Float32Array)[0]\n }\n\n reset() {\n this.state = newState()\n }\n\n async release() {\n await this.session?.release()\n this.session = undefined\n }\n}\n\n/** The memory the model carries from one window to the next, emptied */\nfunction newState(): ort.Tensor {\n return new ort.Tensor('float32', new Float32Array(2 * 128), [2, 1, 128])\n}\n","/**\n * Runs one inference at a time, whichever model asks.\n *\n * The ONNX runtime keeps a single active session for the whole WebAssembly\n * module, so two models cannot be in flight together. A model running on the\n * graphics card yields while it waits for the device, and a detector scoring\n * its next window on top of it makes both fail, one with `Session already\n * started` and the other with `Session mismatch`.\n *\n * The queue lives on the global scope so every Micdrop model takes the same\n * turns, `@micdrop/smart-turn` included, which ships separately and holds the\n * same few lines.\n */\nconst globalScope = globalThis as typeof globalThis & {\n micdropOnnxQueue?: Promise<unknown>\n}\n\n/**\n * Waits for the models ahead in the queue, then runs\n * @param run - The inference to run once the runtime is free\n */\nexport function queueOnnxRun<T>(run: () => Promise<T>): Promise<T> {\n const started = (globalScope.micdropOnnxQueue ?? Promise.resolve()).then(\n run,\n run\n )\n // A failed run still lets the next one through\n globalScope.micdropOnnxQueue = started.catch(() => undefined)\n return started\n}\n"],"mappings":";AAAA,SAAS,4BAA4B;;;ACArC,SAAsB,0BAA0B;AAChD,YAAY,SAAS;;;ACYrB,IAAM,cAAc;AAQb,SAAS,aAAgB,KAAmC;AACjE,QAAM,WAAW,YAAY,oBAAoB,QAAQ,QAAQ,GAAG;AAAA,IAClE;AAAA,IACA;AAAA,EACF;AAEA,cAAY,mBAAmB,QAAQ,MAAM,MAAM,MAAS;AAC5D,SAAO;AACT;;;ADxBO,IAAM,2BACX;AAKF,IAAM,oBAAoB;AAa1B,IAAI;AAQG,IAAM,kBAAN,MAA6C;AAAA,EAKlD,YAAoBA,WAA6B,CAAC,GAAG;AAAjC,mBAAAA;AAClB,SAAK,QAAQ,SAAS;AACtB,SAAK,aAAa,IAAQ,WAAO,SAAS,CAAC,OAAO,kBAAkB,CAAC,CAAC;AAAA,EACxE;AAAA,EAEA,MAAM,OAAO;AACX,QAAI,KAAK,QAAS;AAElB,UAAM,WAAW,KAAK,QAAQ,YAAY;AAC1C,QAAI,aAAa,OAAO;AACtB,MAAI,QAAI,KAAK,YAAY;AAAA,IAC3B;AAEA,UAAM,SAAS,KAAK,QAAQ,SAAS;AACrC,QAAI;AACJ,QAAI,OAAO,WAAW,UAAU;AAE9B,gBACE,WAAW,MAAM,MAAM,EAAE,KAAK,CAAC,aAAa,SAAS,YAAY,CAAC;AACpE,cAAQ,MAAM;AAAA,IAChB,OAAO;AACL,cAAQ;AAAA,IACV;AAEA,SAAK,UAAU,MAAU,qBAAiB,OAAO,KAAK;AAAA,EACxD;AAAA,EAEA,MAAM,QAAQ,OAAsC;AAClD,QAAI,CAAC,KAAK,QAAS,OAAM,KAAK,KAAK;AAEnC,UAAM,SAAS,MAAM;AAAA,MAAa,MAChC,KAAK,QAAS,IAAI;AAAA,QAChB,OAAO,IAAQ,WAAO,WAAW,OAAO,CAAC,GAAG,MAAM,MAAM,CAAC;AAAA,QACzD,OAAO,KAAK;AAAA,QACZ,IAAI,KAAK;AAAA,MACX,CAAC;AAAA,IACH;AAEA,SAAK,QAAQ,OAAO;AACpB,WAAQ,OAAO,OAAO,KAAsB,CAAC;AAAA,EAC/C;AAAA,EAEA,QAAQ;AACN,SAAK,QAAQ,SAAS;AAAA,EACxB;AAAA,EAEA,MAAM,UAAU;AACd,UAAM,KAAK,SAAS,QAAQ;AAC5B,SAAK,UAAU;AAAA,EACjB;AACF;AAGA,SAAS,WAAuB;AAC9B,SAAO,IAAQ,WAAO,WAAW,IAAI,aAAa,IAAI,GAAG,GAAG,CAAC,GAAG,GAAG,GAAG,CAAC;AACzE;;;ADtFA,IAAI,UAA6B,CAAC;AAQ3B,SAAS,iBAAiB,MAAyB;AACxD,YAAU,EAAE,GAAG,SAAS,GAAG,KAAK;AAClC;AAIA,qBAAqB,YAAY;AAC/B,QAAM,QAAQ,IAAI,gBAAgB,OAAO;AACzC,QAAM,MAAM,KAAK;AACjB,SAAO;AACT,CAAC;","names":["options"]}
|
package/dist/vite.d.mts
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { Plugin } from 'vite';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Bundles the files the voice models load at runtime, so a call never depends
|
|
5
|
+
* on a public CDN being reachable.
|
|
6
|
+
*
|
|
7
|
+
* Without it, `@micdrop/web/silero` fetches the Silero model from jsDelivr and
|
|
8
|
+
* the ONNX runtime from unpkg, which an outage, a firewall or an ad blocker
|
|
9
|
+
* can keep from loading. With it, the model ships with the app and the ONNX
|
|
10
|
+
* runtime finds its WebAssembly next to itself, both emitted by Vite.
|
|
11
|
+
* `@micdrop/smart-turn/web` gets the same runtime, its checkpoint stays where
|
|
12
|
+
* `setSmartTurnOptions` points.
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* import { micdrop } from '@micdrop/web/vite'
|
|
16
|
+
*
|
|
17
|
+
* export default defineConfig({ plugins: [micdrop()] })
|
|
18
|
+
*/
|
|
19
|
+
declare function micdrop(): Plugin;
|
|
20
|
+
|
|
21
|
+
export { micdrop };
|
package/dist/vite.d.ts
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { Plugin } from 'vite';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Bundles the files the voice models load at runtime, so a call never depends
|
|
5
|
+
* on a public CDN being reachable.
|
|
6
|
+
*
|
|
7
|
+
* Without it, `@micdrop/web/silero` fetches the Silero model from jsDelivr and
|
|
8
|
+
* the ONNX runtime from unpkg, which an outage, a firewall or an ad blocker
|
|
9
|
+
* can keep from loading. With it, the model ships with the app and the ONNX
|
|
10
|
+
* runtime finds its WebAssembly next to itself, both emitted by Vite.
|
|
11
|
+
* `@micdrop/smart-turn/web` gets the same runtime, its checkpoint stays where
|
|
12
|
+
* `setSmartTurnOptions` points.
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* import { micdrop } from '@micdrop/web/vite'
|
|
16
|
+
*
|
|
17
|
+
* export default defineConfig({ plugins: [micdrop()] })
|
|
18
|
+
*/
|
|
19
|
+
declare function micdrop(): Plugin;
|
|
20
|
+
|
|
21
|
+
export { micdrop };
|
package/dist/vite.js
ADDED
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/vite.ts
|
|
21
|
+
var vite_exports = {};
|
|
22
|
+
__export(vite_exports, {
|
|
23
|
+
micdrop: () => micdrop
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(vite_exports);
|
|
26
|
+
|
|
27
|
+
// ../../node_modules/.pnpm/tsup@8.5.1_typescript@5.9.3/node_modules/tsup/assets/cjs_shims.js
|
|
28
|
+
var getImportMetaUrl = () => typeof document === "undefined" ? new URL(`file:${__filename}`).href : document.currentScript && document.currentScript.tagName.toUpperCase() === "SCRIPT" ? document.currentScript.src : new URL("main.js", document.baseURI).href;
|
|
29
|
+
var importMetaUrl = /* @__PURE__ */ getImportMetaUrl();
|
|
30
|
+
|
|
31
|
+
// src/vite.ts
|
|
32
|
+
var import_node_url = require("url");
|
|
33
|
+
var SILERO_ID = "@micdrop/web/silero";
|
|
34
|
+
var SMART_TURN_ID = "@micdrop/smart-turn/web";
|
|
35
|
+
var VIRTUAL_SILERO = "\0micdrop:silero";
|
|
36
|
+
var VIRTUAL_SMART_TURN = "\0micdrop:smart-turn";
|
|
37
|
+
function micdrop() {
|
|
38
|
+
const sileroModel = (0, import_node_url.fileURLToPath)(
|
|
39
|
+
new URL("../assets/silero_vad_v5.onnx", importMetaUrl)
|
|
40
|
+
).replace(/\\/g, "/");
|
|
41
|
+
return {
|
|
42
|
+
name: "micdrop",
|
|
43
|
+
enforce: "pre",
|
|
44
|
+
config() {
|
|
45
|
+
return {
|
|
46
|
+
optimizeDeps: {
|
|
47
|
+
// Pre-bundling moves the runtime away from its WebAssembly files,
|
|
48
|
+
// which it looks up relative to its own address
|
|
49
|
+
exclude: ["onnxruntime-web"]
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
},
|
|
53
|
+
// The app keeps importing `@micdrop/web/silero`, and gets a module that
|
|
54
|
+
// sets the bundled options before handing over the real one. Imports from
|
|
55
|
+
// dependencies and from the wrappers themselves go through untouched.
|
|
56
|
+
resolveId(id, importer) {
|
|
57
|
+
if (!importer || importer.startsWith("\0")) return null;
|
|
58
|
+
if (importer.includes("/node_modules/")) return null;
|
|
59
|
+
if (id === SILERO_ID) return VIRTUAL_SILERO;
|
|
60
|
+
if (id === SMART_TURN_ID) return VIRTUAL_SMART_TURN;
|
|
61
|
+
return null;
|
|
62
|
+
},
|
|
63
|
+
load(id) {
|
|
64
|
+
if (id === VIRTUAL_SILERO) {
|
|
65
|
+
return [
|
|
66
|
+
`import { setSileroOptions } from '${SILERO_ID}'`,
|
|
67
|
+
`import model from ${JSON.stringify(`${sileroModel}?url`)}`,
|
|
68
|
+
`setSileroOptions({ model, wasmPath: false })`,
|
|
69
|
+
`export * from '${SILERO_ID}'`
|
|
70
|
+
].join("\n");
|
|
71
|
+
}
|
|
72
|
+
if (id === VIRTUAL_SMART_TURN) {
|
|
73
|
+
return [
|
|
74
|
+
`import { setSmartTurnOptions } from '${SMART_TURN_ID}'`,
|
|
75
|
+
`setSmartTurnOptions({ wasmPath: false })`,
|
|
76
|
+
`export * from '${SMART_TURN_ID}'`
|
|
77
|
+
].join("\n");
|
|
78
|
+
}
|
|
79
|
+
return null;
|
|
80
|
+
}
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
84
|
+
0 && (module.exports = {
|
|
85
|
+
micdrop
|
|
86
|
+
});
|
|
87
|
+
//# sourceMappingURL=vite.js.map
|
package/dist/vite.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/vite.ts","../../../node_modules/.pnpm/tsup@8.5.1_typescript@5.9.3/node_modules/tsup/assets/cjs_shims.js"],"sourcesContent":["import { fileURLToPath } from 'node:url'\nimport type { Plugin } from 'vite'\n\nconst SILERO_ID = '@micdrop/web/silero'\nconst SMART_TURN_ID = '@micdrop/smart-turn/web'\nconst VIRTUAL_SILERO = '\\0micdrop:silero'\nconst VIRTUAL_SMART_TURN = '\\0micdrop:smart-turn'\n\n/**\n * Bundles the files the voice models load at runtime, so a call never depends\n * on a public CDN being reachable.\n *\n * Without it, `@micdrop/web/silero` fetches the Silero model from jsDelivr and\n * the ONNX runtime from unpkg, which an outage, a firewall or an ad blocker\n * can keep from loading. With it, the model ships with the app and the ONNX\n * runtime finds its WebAssembly next to itself, both emitted by Vite.\n * `@micdrop/smart-turn/web` gets the same runtime, its checkpoint stays where\n * `setSmartTurnOptions` points.\n *\n * @example\n * import { micdrop } from '@micdrop/web/vite'\n *\n * export default defineConfig({ plugins: [micdrop()] })\n */\nexport function micdrop(): Plugin {\n const sileroModel = fileURLToPath(\n new URL('../assets/silero_vad_v5.onnx', import.meta.url)\n ).replace(/\\\\/g, '/')\n\n return {\n name: 'micdrop',\n enforce: 'pre',\n\n config() {\n return {\n optimizeDeps: {\n // Pre-bundling moves the runtime away from its WebAssembly files,\n // which it looks up relative to its own address\n exclude: ['onnxruntime-web'],\n },\n }\n },\n\n // The app keeps importing `@micdrop/web/silero`, and gets a module that\n // sets the bundled options before handing over the real one. Imports from\n // dependencies and from the wrappers themselves go through untouched.\n resolveId(id, importer) {\n if (!importer || importer.startsWith('\\0')) return null\n if (importer.includes('/node_modules/')) return null\n if (id === SILERO_ID) return VIRTUAL_SILERO\n if (id === SMART_TURN_ID) return VIRTUAL_SMART_TURN\n return null\n },\n\n load(id) {\n if (id === VIRTUAL_SILERO) {\n return [\n `import { setSileroOptions } from '${SILERO_ID}'`,\n `import model from ${JSON.stringify(`${sileroModel}?url`)}`,\n `setSileroOptions({ model, wasmPath: false })`,\n `export * from '${SILERO_ID}'`,\n ].join('\\n')\n }\n if (id === VIRTUAL_SMART_TURN) {\n return [\n `import { setSmartTurnOptions } from '${SMART_TURN_ID}'`,\n `setSmartTurnOptions({ wasmPath: false })`,\n `export * from '${SMART_TURN_ID}'`,\n ].join('\\n')\n }\n return null\n },\n }\n}\n","// Shim globals in cjs bundle\n// There's a weird bug that esbuild will always inject importMetaUrl\n// if we export it as `const importMetaUrl = ... __filename ...`\n// But using a function will not cause this issue\n\nconst getImportMetaUrl = () => \n typeof document === \"undefined\" \n ? new URL(`file:${__filename}`).href \n : (document.currentScript && document.currentScript.tagName.toUpperCase() === 'SCRIPT') \n ? document.currentScript.src \n : new URL(\"main.js\", document.baseURI).href;\n\nexport const importMetaUrl = /* @__PURE__ */ getImportMetaUrl()\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACKA,IAAM,mBAAmB,MACvB,OAAO,aAAa,cAChB,IAAI,IAAI,QAAQ,UAAU,EAAE,EAAE,OAC7B,SAAS,iBAAiB,SAAS,cAAc,QAAQ,YAAY,MAAM,WAC1E,SAAS,cAAc,MACvB,IAAI,IAAI,WAAW,SAAS,OAAO,EAAE;AAEtC,IAAM,gBAAgC,iCAAiB;;;ADZ9D,sBAA8B;AAG9B,IAAM,YAAY;AAClB,IAAM,gBAAgB;AACtB,IAAM,iBAAiB;AACvB,IAAM,qBAAqB;AAkBpB,SAAS,UAAkB;AAChC,QAAM,kBAAc;AAAA,IAClB,IAAI,IAAI,gCAAgC,aAAe;AAAA,EACzD,EAAE,QAAQ,OAAO,GAAG;AAEpB,SAAO;AAAA,IACL,MAAM;AAAA,IACN,SAAS;AAAA,IAET,SAAS;AACP,aAAO;AAAA,QACL,cAAc;AAAA;AAAA;AAAA,UAGZ,SAAS,CAAC,iBAAiB;AAAA,QAC7B;AAAA,MACF;AAAA,IACF;AAAA;AAAA;AAAA;AAAA,IAKA,UAAU,IAAI,UAAU;AACtB,UAAI,CAAC,YAAY,SAAS,WAAW,IAAI,EAAG,QAAO;AACnD,UAAI,SAAS,SAAS,gBAAgB,EAAG,QAAO;AAChD,UAAI,OAAO,UAAW,QAAO;AAC7B,UAAI,OAAO,cAAe,QAAO;AACjC,aAAO;AAAA,IACT;AAAA,IAEA,KAAK,IAAI;AACP,UAAI,OAAO,gBAAgB;AACzB,eAAO;AAAA,UACL,qCAAqC,SAAS;AAAA,UAC9C,qBAAqB,KAAK,UAAU,GAAG,WAAW,MAAM,CAAC;AAAA,UACzD;AAAA,UACA,kBAAkB,SAAS;AAAA,QAC7B,EAAE,KAAK,IAAI;AAAA,MACb;AACA,UAAI,OAAO,oBAAoB;AAC7B,eAAO;AAAA,UACL,wCAAwC,aAAa;AAAA,UACrD;AAAA,UACA,kBAAkB,aAAa;AAAA,QACjC,EAAE,KAAK,IAAI;AAAA,MACb;AACA,aAAO;AAAA,IACT;AAAA,EACF;AACF;","names":[]}
|
package/dist/vite.mjs
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
// src/vite.ts
|
|
2
|
+
import { fileURLToPath } from "url";
|
|
3
|
+
var SILERO_ID = "@micdrop/web/silero";
|
|
4
|
+
var SMART_TURN_ID = "@micdrop/smart-turn/web";
|
|
5
|
+
var VIRTUAL_SILERO = "\0micdrop:silero";
|
|
6
|
+
var VIRTUAL_SMART_TURN = "\0micdrop:smart-turn";
|
|
7
|
+
function micdrop() {
|
|
8
|
+
const sileroModel = fileURLToPath(
|
|
9
|
+
new URL("../assets/silero_vad_v5.onnx", import.meta.url)
|
|
10
|
+
).replace(/\\/g, "/");
|
|
11
|
+
return {
|
|
12
|
+
name: "micdrop",
|
|
13
|
+
enforce: "pre",
|
|
14
|
+
config() {
|
|
15
|
+
return {
|
|
16
|
+
optimizeDeps: {
|
|
17
|
+
// Pre-bundling moves the runtime away from its WebAssembly files,
|
|
18
|
+
// which it looks up relative to its own address
|
|
19
|
+
exclude: ["onnxruntime-web"]
|
|
20
|
+
}
|
|
21
|
+
};
|
|
22
|
+
},
|
|
23
|
+
// The app keeps importing `@micdrop/web/silero`, and gets a module that
|
|
24
|
+
// sets the bundled options before handing over the real one. Imports from
|
|
25
|
+
// dependencies and from the wrappers themselves go through untouched.
|
|
26
|
+
resolveId(id, importer) {
|
|
27
|
+
if (!importer || importer.startsWith("\0")) return null;
|
|
28
|
+
if (importer.includes("/node_modules/")) return null;
|
|
29
|
+
if (id === SILERO_ID) return VIRTUAL_SILERO;
|
|
30
|
+
if (id === SMART_TURN_ID) return VIRTUAL_SMART_TURN;
|
|
31
|
+
return null;
|
|
32
|
+
},
|
|
33
|
+
load(id) {
|
|
34
|
+
if (id === VIRTUAL_SILERO) {
|
|
35
|
+
return [
|
|
36
|
+
`import { setSileroOptions } from '${SILERO_ID}'`,
|
|
37
|
+
`import model from ${JSON.stringify(`${sileroModel}?url`)}`,
|
|
38
|
+
`setSileroOptions({ model, wasmPath: false })`,
|
|
39
|
+
`export * from '${SILERO_ID}'`
|
|
40
|
+
].join("\n");
|
|
41
|
+
}
|
|
42
|
+
if (id === VIRTUAL_SMART_TURN) {
|
|
43
|
+
return [
|
|
44
|
+
`import { setSmartTurnOptions } from '${SMART_TURN_ID}'`,
|
|
45
|
+
`setSmartTurnOptions({ wasmPath: false })`,
|
|
46
|
+
`export * from '${SMART_TURN_ID}'`
|
|
47
|
+
].join("\n");
|
|
48
|
+
}
|
|
49
|
+
return null;
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
export {
|
|
54
|
+
micdrop
|
|
55
|
+
};
|
|
56
|
+
//# sourceMappingURL=vite.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/vite.ts"],"sourcesContent":["import { fileURLToPath } from 'node:url'\nimport type { Plugin } from 'vite'\n\nconst SILERO_ID = '@micdrop/web/silero'\nconst SMART_TURN_ID = '@micdrop/smart-turn/web'\nconst VIRTUAL_SILERO = '\\0micdrop:silero'\nconst VIRTUAL_SMART_TURN = '\\0micdrop:smart-turn'\n\n/**\n * Bundles the files the voice models load at runtime, so a call never depends\n * on a public CDN being reachable.\n *\n * Without it, `@micdrop/web/silero` fetches the Silero model from jsDelivr and\n * the ONNX runtime from unpkg, which an outage, a firewall or an ad blocker\n * can keep from loading. With it, the model ships with the app and the ONNX\n * runtime finds its WebAssembly next to itself, both emitted by Vite.\n * `@micdrop/smart-turn/web` gets the same runtime, its checkpoint stays where\n * `setSmartTurnOptions` points.\n *\n * @example\n * import { micdrop } from '@micdrop/web/vite'\n *\n * export default defineConfig({ plugins: [micdrop()] })\n */\nexport function micdrop(): Plugin {\n const sileroModel = fileURLToPath(\n new URL('../assets/silero_vad_v5.onnx', import.meta.url)\n ).replace(/\\\\/g, '/')\n\n return {\n name: 'micdrop',\n enforce: 'pre',\n\n config() {\n return {\n optimizeDeps: {\n // Pre-bundling moves the runtime away from its WebAssembly files,\n // which it looks up relative to its own address\n exclude: ['onnxruntime-web'],\n },\n }\n },\n\n // The app keeps importing `@micdrop/web/silero`, and gets a module that\n // sets the bundled options before handing over the real one. Imports from\n // dependencies and from the wrappers themselves go through untouched.\n resolveId(id, importer) {\n if (!importer || importer.startsWith('\\0')) return null\n if (importer.includes('/node_modules/')) return null\n if (id === SILERO_ID) return VIRTUAL_SILERO\n if (id === SMART_TURN_ID) return VIRTUAL_SMART_TURN\n return null\n },\n\n load(id) {\n if (id === VIRTUAL_SILERO) {\n return [\n `import { setSileroOptions } from '${SILERO_ID}'`,\n `import model from ${JSON.stringify(`${sileroModel}?url`)}`,\n `setSileroOptions({ model, wasmPath: false })`,\n `export * from '${SILERO_ID}'`,\n ].join('\\n')\n }\n if (id === VIRTUAL_SMART_TURN) {\n return [\n `import { setSmartTurnOptions } from '${SMART_TURN_ID}'`,\n `setSmartTurnOptions({ wasmPath: false })`,\n `export * from '${SMART_TURN_ID}'`,\n ].join('\\n')\n }\n return null\n },\n }\n}\n"],"mappings":";AAAA,SAAS,qBAAqB;AAG9B,IAAM,YAAY;AAClB,IAAM,gBAAgB;AACtB,IAAM,iBAAiB;AACvB,IAAM,qBAAqB;AAkBpB,SAAS,UAAkB;AAChC,QAAM,cAAc;AAAA,IAClB,IAAI,IAAI,gCAAgC,YAAY,GAAG;AAAA,EACzD,EAAE,QAAQ,OAAO,GAAG;AAEpB,SAAO;AAAA,IACL,MAAM;AAAA,IACN,SAAS;AAAA,IAET,SAAS;AACP,aAAO;AAAA,QACL,cAAc;AAAA;AAAA;AAAA,UAGZ,SAAS,CAAC,iBAAiB;AAAA,QAC7B;AAAA,MACF;AAAA,IACF;AAAA;AAAA;AAAA;AAAA,IAKA,UAAU,IAAI,UAAU;AACtB,UAAI,CAAC,YAAY,SAAS,WAAW,IAAI,EAAG,QAAO;AACnD,UAAI,SAAS,SAAS,gBAAgB,EAAG,QAAO;AAChD,UAAI,OAAO,UAAW,QAAO;AAC7B,UAAI,OAAO,cAAe,QAAO;AACjC,aAAO;AAAA,IACT;AAAA,IAEA,KAAK,IAAI;AACP,UAAI,OAAO,gBAAgB;AACzB,eAAO;AAAA,UACL,qCAAqC,SAAS;AAAA,UAC9C,qBAAqB,KAAK,UAAU,GAAG,WAAW,MAAM,CAAC;AAAA,UACzD;AAAA,UACA,kBAAkB,SAAS;AAAA,QAC7B,EAAE,KAAK,IAAI;AAAA,MACb;AACA,UAAI,OAAO,oBAAoB;AAC7B,eAAO;AAAA,UACL,wCAAwC,aAAa;AAAA,UACrD;AAAA,UACA,kBAAkB,aAAa;AAAA,QACjC,EAAE,KAAK,IAAI;AAAA,MACb;AACA,aAAO;AAAA,IACT;AAAA,EACF;AACF;","names":[]}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@micdrop/web",
|
|
3
|
-
"version": "1.
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "1.2.0",
|
|
4
|
+
"description": "🖐️🎤 Micdrop: real-time voice conversations with AI, in the browser",
|
|
5
5
|
"author": "Godefroy de Compreignac",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"main": "dist/index.js",
|
|
@@ -15,7 +15,8 @@
|
|
|
15
15
|
"prepublishOnly": "npm run build"
|
|
16
16
|
},
|
|
17
17
|
"files": [
|
|
18
|
-
"dist"
|
|
18
|
+
"dist",
|
|
19
|
+
"assets"
|
|
19
20
|
],
|
|
20
21
|
"repository": {
|
|
21
22
|
"type": "git",
|
|
@@ -36,10 +37,20 @@
|
|
|
36
37
|
"@micdrop/client": "^3.4.0",
|
|
37
38
|
"onnxruntime-web": "^1.23.2"
|
|
38
39
|
},
|
|
40
|
+
"peerDependencies": {
|
|
41
|
+
"vite": ">=5.0.0"
|
|
42
|
+
},
|
|
43
|
+
"peerDependenciesMeta": {
|
|
44
|
+
"vite": {
|
|
45
|
+
"optional": true
|
|
46
|
+
}
|
|
47
|
+
},
|
|
39
48
|
"devDependencies": {
|
|
49
|
+
"@types/node": "^22.19.13",
|
|
40
50
|
"esbuild-raw-plugin": "^0.3.1",
|
|
41
51
|
"tsup": "^8.5.1",
|
|
42
|
-
"typescript": "^5.9.3"
|
|
52
|
+
"typescript": "^5.9.3",
|
|
53
|
+
"vite": "^7.3.1"
|
|
43
54
|
},
|
|
44
55
|
"exports": {
|
|
45
56
|
".": {
|
|
@@ -51,6 +62,11 @@
|
|
|
51
62
|
"types": "./dist/silero.d.ts",
|
|
52
63
|
"import": "./dist/silero.mjs",
|
|
53
64
|
"require": "./dist/silero.js"
|
|
65
|
+
},
|
|
66
|
+
"./vite": {
|
|
67
|
+
"types": "./dist/vite.d.ts",
|
|
68
|
+
"import": "./dist/vite.mjs",
|
|
69
|
+
"require": "./dist/vite.js"
|
|
54
70
|
}
|
|
55
71
|
}
|
|
56
72
|
}
|