@micdrop/web 1.2.0 → 1.3.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 CHANGED
@@ -44,6 +44,8 @@ export default defineConfig({
44
44
 
45
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
46
 
47
+ The runtime is the WebAssembly build, half the size of the full one, unless `@micdrop/smart-turn` is installed, which runs on the graphics card. `micdrop({ webgpu: true })` keeps the full build in any case.
48
+
47
49
  ## Usage
48
50
 
49
51
  ```ts
package/dist/vite.d.mts CHANGED
@@ -11,11 +11,25 @@ import { Plugin } from 'vite';
11
11
  * `@micdrop/smart-turn/web` gets the same runtime, its checkpoint stays where
12
12
  * `setSmartTurnOptions` points.
13
13
  *
14
+ * Silero only runs on WebAssembly, so the runtime is the WebAssembly build,
15
+ * half the size of the full one. Smart Turn runs on the graphics card when
16
+ * the browser offers it, so the full build is kept when `@micdrop/smart-turn`
17
+ * is installed. Every import of the runtime gets the same build, so an app
18
+ * never loads two of them.
19
+ *
14
20
  * @example
15
21
  * import { micdrop } from '@micdrop/web/vite'
16
22
  *
17
23
  * export default defineConfig({ plugins: [micdrop()] })
18
24
  */
19
- declare function micdrop(): Plugin;
25
+ declare function micdrop(options?: MicdropViteOptions): Plugin;
26
+ interface MicdropViteOptions {
27
+ /**
28
+ * Keeps the build of the ONNX runtime that runs on the graphics card, twice
29
+ * the size of the WebAssembly one. Only Smart Turn uses it, so it defaults
30
+ * to whether `@micdrop/smart-turn` is installed.
31
+ */
32
+ webgpu?: boolean;
33
+ }
20
34
 
21
- export { micdrop };
35
+ export { type MicdropViteOptions, micdrop };
package/dist/vite.d.ts CHANGED
@@ -11,11 +11,25 @@ import { Plugin } from 'vite';
11
11
  * `@micdrop/smart-turn/web` gets the same runtime, its checkpoint stays where
12
12
  * `setSmartTurnOptions` points.
13
13
  *
14
+ * Silero only runs on WebAssembly, so the runtime is the WebAssembly build,
15
+ * half the size of the full one. Smart Turn runs on the graphics card when
16
+ * the browser offers it, so the full build is kept when `@micdrop/smart-turn`
17
+ * is installed. Every import of the runtime gets the same build, so an app
18
+ * never loads two of them.
19
+ *
14
20
  * @example
15
21
  * import { micdrop } from '@micdrop/web/vite'
16
22
  *
17
23
  * export default defineConfig({ plugins: [micdrop()] })
18
24
  */
19
- declare function micdrop(): Plugin;
25
+ declare function micdrop(options?: MicdropViteOptions): Plugin;
26
+ interface MicdropViteOptions {
27
+ /**
28
+ * Keeps the build of the ONNX runtime that runs on the graphics card, twice
29
+ * the size of the WebAssembly one. Only Smart Turn uses it, so it defaults
30
+ * to whether `@micdrop/smart-turn` is installed.
31
+ */
32
+ webgpu?: boolean;
33
+ }
20
34
 
21
- export { micdrop };
35
+ export { type MicdropViteOptions, micdrop };
package/dist/vite.js CHANGED
@@ -1,7 +1,9 @@
1
1
  "use strict";
2
+ var __create = Object.create;
2
3
  var __defProp = Object.defineProperty;
3
4
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
5
  var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
5
7
  var __hasOwnProp = Object.prototype.hasOwnProperty;
6
8
  var __export = (target, all) => {
7
9
  for (var name in all)
@@ -15,6 +17,14 @@ var __copyProps = (to, from, except, desc) => {
15
17
  }
16
18
  return to;
17
19
  };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
18
28
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
29
 
20
30
  // src/vite.ts
@@ -29,24 +39,39 @@ var getImportMetaUrl = () => typeof document === "undefined" ? new URL(`file:${_
29
39
  var importMetaUrl = /* @__PURE__ */ getImportMetaUrl();
30
40
 
31
41
  // src/vite.ts
42
+ var import_node_module = require("module");
43
+ var import_node_path = __toESM(require("path"));
44
+ var import_node_process = __toESM(require("process"));
32
45
  var import_node_url = require("url");
33
46
  var SILERO_ID = "@micdrop/web/silero";
34
47
  var SMART_TURN_ID = "@micdrop/smart-turn/web";
35
48
  var VIRTUAL_SILERO = "\0micdrop:silero";
36
49
  var VIRTUAL_SMART_TURN = "\0micdrop:smart-turn";
37
- function micdrop() {
50
+ function micdrop(options = {}) {
38
51
  const sileroModel = (0, import_node_url.fileURLToPath)(
39
52
  new URL("../assets/silero_vad_v5.onnx", importMetaUrl)
40
53
  ).replace(/\\/g, "/");
41
54
  return {
42
55
  name: "micdrop",
43
56
  enforce: "pre",
44
- config() {
57
+ config(config) {
58
+ const webgpu = options.webgpu ?? isInstalled(
59
+ "@micdrop/smart-turn",
60
+ import_node_path.default.resolve(config.root ?? import_node_process.default.cwd())
61
+ );
45
62
  return {
63
+ resolve: {
64
+ alias: webgpu ? [] : [
65
+ {
66
+ find: /^onnxruntime-web$/,
67
+ replacement: "onnxruntime-web/wasm"
68
+ }
69
+ ]
70
+ },
46
71
  optimizeDeps: {
47
72
  // Pre-bundling moves the runtime away from its WebAssembly files,
48
73
  // which it looks up relative to its own address
49
- exclude: ["onnxruntime-web"]
74
+ exclude: ["onnxruntime-web", "onnxruntime-web/wasm"]
50
75
  }
51
76
  };
52
77
  },
@@ -80,6 +105,14 @@ function micdrop() {
80
105
  }
81
106
  };
82
107
  }
108
+ function isInstalled(name, root) {
109
+ try {
110
+ (0, import_node_module.createRequire)(import_node_path.default.join(root, "package.json")).resolve(name);
111
+ return true;
112
+ } catch {
113
+ return false;
114
+ }
115
+ }
83
116
  // Annotate the CommonJS export names for ESM import in node:
84
117
  0 && (module.exports = {
85
118
  micdrop
package/dist/vite.js.map CHANGED
@@ -1 +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":[]}
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 { createRequire } from 'node:module'\nimport path from 'node:path'\nimport process from 'node:process'\nimport { 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 * Silero only runs on WebAssembly, so the runtime is the WebAssembly build,\n * half the size of the full one. Smart Turn runs on the graphics card when\n * the browser offers it, so the full build is kept when `@micdrop/smart-turn`\n * is installed. Every import of the runtime gets the same build, so an app\n * never loads two of them.\n *\n * @example\n * import { micdrop } from '@micdrop/web/vite'\n *\n * export default defineConfig({ plugins: [micdrop()] })\n */\nexport function micdrop(options: MicdropViteOptions = {}): 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(config) {\n const webgpu =\n options.webgpu ??\n isInstalled(\n '@micdrop/smart-turn',\n path.resolve(config.root ?? process.cwd())\n )\n return {\n resolve: {\n alias: webgpu\n ? []\n : [\n {\n find: /^onnxruntime-web$/,\n replacement: 'onnxruntime-web/wasm',\n },\n ],\n },\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', 'onnxruntime-web/wasm'],\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\nexport interface MicdropViteOptions {\n /**\n * Keeps the build of the ONNX runtime that runs on the graphics card, twice\n * the size of the WebAssembly one. Only Smart Turn uses it, so it defaults\n * to whether `@micdrop/smart-turn` is installed.\n */\n webgpu?: boolean\n}\n\n/** Whether the app at `root` can import the package */\nfunction isInstalled(name: string, root: string): boolean {\n try {\n createRequire(path.join(root, 'package.json')).resolve(name)\n return true\n } catch {\n return false\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,yBAA8B;AAC9B,uBAAiB;AACjB,0BAAoB;AACpB,sBAA8B;AAG9B,IAAM,YAAY;AAClB,IAAM,gBAAgB;AACtB,IAAM,iBAAiB;AACvB,IAAM,qBAAqB;AAwBpB,SAAS,QAAQ,UAA8B,CAAC,GAAW;AAChE,QAAM,kBAAc;AAAA,IAClB,IAAI,IAAI,gCAAgC,aAAe;AAAA,EACzD,EAAE,QAAQ,OAAO,GAAG;AAEpB,SAAO;AAAA,IACL,MAAM;AAAA,IACN,SAAS;AAAA,IAET,OAAO,QAAQ;AACb,YAAM,SACJ,QAAQ,UACR;AAAA,QACE;AAAA,QACA,iBAAAA,QAAK,QAAQ,OAAO,QAAQ,oBAAAC,QAAQ,IAAI,CAAC;AAAA,MAC3C;AACF,aAAO;AAAA,QACL,SAAS;AAAA,UACP,OAAO,SACH,CAAC,IACD;AAAA,YACE;AAAA,cACE,MAAM;AAAA,cACN,aAAa;AAAA,YACf;AAAA,UACF;AAAA,QACN;AAAA,QACA,cAAc;AAAA;AAAA;AAAA,UAGZ,SAAS,CAAC,mBAAmB,sBAAsB;AAAA,QACrD;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;AAYA,SAAS,YAAY,MAAc,MAAuB;AACxD,MAAI;AACF,0CAAc,iBAAAD,QAAK,KAAK,MAAM,cAAc,CAAC,EAAE,QAAQ,IAAI;AAC3D,WAAO;AAAA,EACT,QAAQ;AACN,WAAO;AAAA,EACT;AACF;","names":["path","process"]}
package/dist/vite.mjs CHANGED
@@ -1,22 +1,37 @@
1
1
  // src/vite.ts
2
+ import { createRequire } from "module";
3
+ import path from "path";
4
+ import process from "process";
2
5
  import { fileURLToPath } from "url";
3
6
  var SILERO_ID = "@micdrop/web/silero";
4
7
  var SMART_TURN_ID = "@micdrop/smart-turn/web";
5
8
  var VIRTUAL_SILERO = "\0micdrop:silero";
6
9
  var VIRTUAL_SMART_TURN = "\0micdrop:smart-turn";
7
- function micdrop() {
10
+ function micdrop(options = {}) {
8
11
  const sileroModel = fileURLToPath(
9
12
  new URL("../assets/silero_vad_v5.onnx", import.meta.url)
10
13
  ).replace(/\\/g, "/");
11
14
  return {
12
15
  name: "micdrop",
13
16
  enforce: "pre",
14
- config() {
17
+ config(config) {
18
+ const webgpu = options.webgpu ?? isInstalled(
19
+ "@micdrop/smart-turn",
20
+ path.resolve(config.root ?? process.cwd())
21
+ );
15
22
  return {
23
+ resolve: {
24
+ alias: webgpu ? [] : [
25
+ {
26
+ find: /^onnxruntime-web$/,
27
+ replacement: "onnxruntime-web/wasm"
28
+ }
29
+ ]
30
+ },
16
31
  optimizeDeps: {
17
32
  // Pre-bundling moves the runtime away from its WebAssembly files,
18
33
  // which it looks up relative to its own address
19
- exclude: ["onnxruntime-web"]
34
+ exclude: ["onnxruntime-web", "onnxruntime-web/wasm"]
20
35
  }
21
36
  };
22
37
  },
@@ -50,6 +65,14 @@ function micdrop() {
50
65
  }
51
66
  };
52
67
  }
68
+ function isInstalled(name, root) {
69
+ try {
70
+ createRequire(path.join(root, "package.json")).resolve(name);
71
+ return true;
72
+ } catch {
73
+ return false;
74
+ }
75
+ }
53
76
  export {
54
77
  micdrop
55
78
  };
package/dist/vite.mjs.map CHANGED
@@ -1 +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":[]}
1
+ {"version":3,"sources":["../src/vite.ts"],"sourcesContent":["import { createRequire } from 'node:module'\nimport path from 'node:path'\nimport process from 'node:process'\nimport { 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 * Silero only runs on WebAssembly, so the runtime is the WebAssembly build,\n * half the size of the full one. Smart Turn runs on the graphics card when\n * the browser offers it, so the full build is kept when `@micdrop/smart-turn`\n * is installed. Every import of the runtime gets the same build, so an app\n * never loads two of them.\n *\n * @example\n * import { micdrop } from '@micdrop/web/vite'\n *\n * export default defineConfig({ plugins: [micdrop()] })\n */\nexport function micdrop(options: MicdropViteOptions = {}): 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(config) {\n const webgpu =\n options.webgpu ??\n isInstalled(\n '@micdrop/smart-turn',\n path.resolve(config.root ?? process.cwd())\n )\n return {\n resolve: {\n alias: webgpu\n ? []\n : [\n {\n find: /^onnxruntime-web$/,\n replacement: 'onnxruntime-web/wasm',\n },\n ],\n },\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', 'onnxruntime-web/wasm'],\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\nexport interface MicdropViteOptions {\n /**\n * Keeps the build of the ONNX runtime that runs on the graphics card, twice\n * the size of the WebAssembly one. Only Smart Turn uses it, so it defaults\n * to whether `@micdrop/smart-turn` is installed.\n */\n webgpu?: boolean\n}\n\n/** Whether the app at `root` can import the package */\nfunction isInstalled(name: string, root: string): boolean {\n try {\n createRequire(path.join(root, 'package.json')).resolve(name)\n return true\n } catch {\n return false\n }\n}\n"],"mappings":";AAAA,SAAS,qBAAqB;AAC9B,OAAO,UAAU;AACjB,OAAO,aAAa;AACpB,SAAS,qBAAqB;AAG9B,IAAM,YAAY;AAClB,IAAM,gBAAgB;AACtB,IAAM,iBAAiB;AACvB,IAAM,qBAAqB;AAwBpB,SAAS,QAAQ,UAA8B,CAAC,GAAW;AAChE,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,OAAO,QAAQ;AACb,YAAM,SACJ,QAAQ,UACR;AAAA,QACE;AAAA,QACA,KAAK,QAAQ,OAAO,QAAQ,QAAQ,IAAI,CAAC;AAAA,MAC3C;AACF,aAAO;AAAA,QACL,SAAS;AAAA,UACP,OAAO,SACH,CAAC,IACD;AAAA,YACE;AAAA,cACE,MAAM;AAAA,cACN,aAAa;AAAA,YACf;AAAA,UACF;AAAA,QACN;AAAA,QACA,cAAc;AAAA;AAAA;AAAA,UAGZ,SAAS,CAAC,mBAAmB,sBAAsB;AAAA,QACrD;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;AAYA,SAAS,YAAY,MAAc,MAAuB;AACxD,MAAI;AACF,kBAAc,KAAK,KAAK,MAAM,cAAc,CAAC,EAAE,QAAQ,IAAI;AAC3D,WAAO;AAAA,EACT,QAAQ;AACN,WAAO;AAAA,EACT;AACF;","names":[]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@micdrop/web",
3
- "version": "1.2.0",
3
+ "version": "1.3.0",
4
4
  "description": "🖐️🎤 Micdrop: real-time voice conversations with AI, in the browser",
5
5
  "author": "Godefroy de Compreignac",
6
6
  "license": "MIT",