@gjsify/vad 0.64.25 → 0.64.26-next.312

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
@@ -75,7 +75,7 @@ import { listModels, install, uninstall, modelCacheDir } from '@gjsify/vad';
75
75
  listModels(); // every entry with its availability, for a settings panel
76
76
  await install('silero-v4', { onProgress: (p) => console.log(p.received, p.total) });
77
77
  uninstall('silero-v4');
78
- modelCacheDir(); // ~/.cache/gjsify/speech-models, shared with the other speech packages
78
+ modelCacheDir(); // ~/.cache/gjsify/models/speech, shared with the other speech packages
79
79
  ```
80
80
 
81
81
  `VadOptions.model` takes a manifest id (`silero-v5`, `silero-v4`) or a path — anything containing a path separator is used as given, which is how you point at a model this manifest does not know. An id must already be cached: resolving must not start a download behind a synchronous constructor.
@@ -1 +1 @@
1
- import"./_virtual/_rolldown/runtime.js";const e=`silero-v5`,t=`https://github.com/k2-fsa/sherpa-onnx/releases/download/asr-models`,n=[{id:`silero-v5`,file:`silero_vad_v5.onnx`,url:`${t}/silero_vad_v5.onnx`,bytes:2313101,sha256:`6b99cbfd39246b6706f98ec13c7c50c6b299181f2474fa05cbc8046acc274396`,license:`MIT`,sampleRate:16e3,windowSize:512,description:`Silero VAD v5 (2.2 MiB) — the default. Takes input/state/sr; 16 kHz, 512-sample windows.`},{id:`silero-v4`,file:`silero_vad.onnx`,url:`${t}/silero_vad.onnx`,bytes:643854,sha256:`9e2449e1087496d8d4caba907f23e0bd3f78d91fa552479bb9c23ac09cbb1fd6`,license:`MIT`,sampleRate:16e3,windowSize:512,description:`Silero VAD v4 (0.6 MiB) — smaller and older. Only its 16 kHz branch is covered here.`}];function findVadModel(t=e){return n.find(e=>e.id===t)}function requireVadModel(t=e){let r=findVadModel(t);if(r===void 0)throw RangeError(`Unknown VAD model '${t}' — known ids: ${n.map(e=>e.id).join(`, `)}`);return r}export{e as DEFAULT_VAD_MODEL,n as VAD_MODELS,findVadModel,requireVadModel};
1
+ import"./_virtual/_rolldown/runtime.js";const e=`silero-v5`,t=`https://github.com/k2-fsa/sherpa-onnx/releases/download/asr-models`,n=[{id:`silero-v5`,file:`silero_vad_v5.onnx`,url:`${t}/silero_vad_v5.onnx`,bytes:2313101,sha256:`6b99cbfd39246b6706f98ec13c7c50c6b299181f2474fa05cbc8046acc274396`,license:`MIT`,redistributable:!0,sampleRate:16e3,windowSize:512,description:`Silero VAD v5 (2.2 MiB) — the default. Takes input/state/sr; 16 kHz, 512-sample windows.`},{id:`silero-v4`,file:`silero_vad.onnx`,url:`${t}/silero_vad.onnx`,bytes:643854,sha256:`9e2449e1087496d8d4caba907f23e0bd3f78d91fa552479bb9c23ac09cbb1fd6`,license:`MIT`,redistributable:!0,sampleRate:16e3,windowSize:512,description:`Silero VAD v4 (0.6 MiB) — smaller and older. Only its 16 kHz branch is covered here.`}];function findVadModel(t=e){return n.find(e=>e.id===t)}function requireVadModel(t=e){let r=findVadModel(t);if(r===void 0)throw RangeError(`Unknown VAD model '${t}' — known ids: ${n.map(e=>e.id).join(`, `)}`);return r}export{e as DEFAULT_VAD_MODEL,n as VAD_MODELS,findVadModel,requireVadModel};
package/lib/esm/models.js CHANGED
@@ -1 +1 @@
1
- import"./_virtual/_rolldown/runtime.js";import{hasVadBackend as e}from"./backend.js";import{DEFAULT_VAD_MODEL as t,VAD_MODELS as n,requireVadModel as r}from"./model-manifest.js";import i from"gi://GLib?version=2.0";import a from"gi://Gio?version=2.0";import o from"@gjsify/fetch";function modelCacheDir(){return i.build_filenamev([i.get_user_cache_dir(),`gjsify`,`speech-models`])}function modelPath(e=t){return i.build_filenamev([modelCacheDir(),r(e).file])}const s=new Map;function sizeOf(e){try{return a.File.new_for_path(e).query_info(a.FILE_ATTRIBUTE_STANDARD_SIZE,a.FileQueryInfoFlags.NONE,null).get_size()}catch{return null}}function isCached(e){return sizeOf(i.build_filenamev([modelCacheDir(),e.file]))===e.bytes}function sha256(e){let t=i.Checksum.new(i.ChecksumType.SHA256);t.update(e);let n=t.get_string();if(n===null)throw Error(`GLib.Checksum returned no digest`);return n.toLowerCase()}function available(n=t){let i=r(n);return e()?isCached(i)?`available`:s.has(i.id)?`downloading`:`downloadable`:`unavailable`}function listModels(){return n.map(e=>({entry:e,availability:available(e.id)}))}function installedModels(){return n.filter(isCached).map(e=>e.id)}async function download(e,t){let n=modelCacheDir(),r=i.build_filenamev([n,e.file]),s=await(t.fetchImpl??o)(e.url,{signal:t.signal,redirect:`follow`});if(!s.ok)throw Error(`Downloading ${e.id} from ${e.url} failed: HTTP ${s.status}`);let c=s.headers.get(`content-length`);if(c!==null&&Number(c)!==e.bytes)throw Error(`Downloading ${e.id} refused: ${e.url} declares ${c} bytes, the manifest says ${e.bytes}`);let l=new Uint8Array(await s.arrayBuffer());if(l.length!==e.bytes)throw Error(`Downloading ${e.id} failed: got ${l.length} bytes, expected ${e.bytes}`);let u=sha256(l);if(u!==e.sha256)throw Error(`Downloading ${e.id} failed: sha256 ${u}, expected ${e.sha256}`);i.mkdir_with_parents(n,493);let d=`${r}.part-${i.uuid_string_random()}`,f=a.File.new_for_path(d);try{f.replace_contents(l,null,!1,a.FileCreateFlags.REPLACE_DESTINATION,null),f.move(a.File.new_for_path(r),a.FileCopyFlags.OVERWRITE,null,null)}catch(e){try{f.delete(null)}catch{}throw e}return t.onProgress?.({modelId:e.id,received:e.bytes,total:e.bytes}),r}function install(n=t,a={}){let o;try{o=r(n)}catch(e){return Promise.reject(e)}if(!e())return Promise.reject(Error(`install('${o.id}'): no native VAD engine on this host, so a model would be unusable — gate on available() and show describeVadBackend() instead.`));let c=i.build_filenamev([modelCacheDir(),o.file]);if(!a.force&&isCached(o))return a.onProgress?.({modelId:o.id,received:o.bytes,total:o.bytes}),Promise.resolve(c);let l=s.get(o.id);if(l!==void 0)return l;let u=download(o,a).finally(()=>s.delete(o.id));return s.set(o.id,u),u}function uninstall(e=t){let n=r(e);try{return a.File.new_for_path(i.build_filenamev([modelCacheDir(),n.file])).delete(null)}catch{return!1}}function resolveModel(e=t){if(e.includes(`/`)||e.includes(`\\`))return e;let n=r(e),a=i.build_filenamev([modelCacheDir(),n.file]);if(!isCached(n))throw Error(`VAD model '${n.id}' is not cached (${a}) — await install('${n.id}') first, or pass a path to a model file. ${n.bytes} bytes from ${n.url}.`);return a}export{available,install,installedModels,listModels,modelCacheDir,modelPath,resolveModel,uninstall};
1
+ import"./_virtual/_rolldown/runtime.js";import{hasVadBackend as e}from"./backend.js";import{DEFAULT_VAD_MODEL as t,VAD_MODELS as n}from"./model-manifest.js";import{join as r}from"node:path";import{ModelStore as i,userCacheDir as a}from"@gjsify/model-store";const o=new i({capability:`speech`,models:n,defaultModel:t,legacyDirs:()=>[r(a(),`gjsify`,`speech-models`)]});function modelCacheDir(){return o.cacheDir}function modelPath(e=t){return o.cachePath(e)}function available(n=t){return o.require(n),e()?o.availability(n):`unavailable`}function listModels(){return n.map(e=>({entry:e,availability:available(e.id)}))}function installedModels(){return o.installed()}function install(n=t,r={}){let i;try{i=o.require(n)}catch(e){return Promise.reject(e)}if(!e())return Promise.reject(Error(`install('${i.id}'): no native VAD engine on this host, so a model would be unusable — gate on available() and show describeVadBackend() instead.`));let{onProgress:a}=r;return o.install(i.id,{signal:r.signal,force:r.force,fetch:r.fetchImpl,monitor:a===void 0?void 0:e=>e.addEventListener(`downloadprogress`,e=>{let{receivedBytes:t,totalBytes:n}=e;a({modelId:i.id,received:t,total:n})})})}function uninstall(e=t){o.require(e);try{return o.uninstall(e)}catch{return!1}}function resolveModel(e=t){if(e.includes(`/`)||e.includes(`\\`))return e;let n=o.require(e),r=o.locate(n.id);if(r===void 0)throw Error(`VAD model '${n.id}' is not cached (${o.cachePath(n.id)}) — await install('${n.id}') first, or pass a path to a model file. ${n.bytes} bytes from ${n.url}.`);return r.path}export{available,install,installedModels,listModels,modelCacheDir,modelPath,resolveModel,uninstall};
@@ -1,23 +1,12 @@
1
- /** One fetchable Silero VAD model. */
2
- export interface VadModelEntry {
3
- /** Stable id used by `available()`, `install()` and `VadOptions.model`. */
4
- readonly id: string;
5
- /** File name inside the cache directory. Upstream's own name, so a hand-placed file matches. */
6
- readonly file: string;
7
- /** Where it is fetched from. Upstream only — never a mirror of ours. */
8
- readonly url: string;
9
- /** Exact size in bytes. */
10
- readonly bytes: number;
11
- /** SHA-256 of the file, lowercase hex. */
12
- readonly sha256: string;
13
- /** SPDX id of the MODEL's licence, which is not this package's. */
14
- readonly license: string;
1
+ import type { ModelEntry } from '@gjsify/model-store';
2
+ /** One fetchable Silero VAD model. `id` is what `available()`, `install()` and `VadOptions.model` take. */
3
+ export interface VadModelEntry extends ModelEntry {
4
+ /** One line for a settings panel or a download prompt. */
5
+ readonly description: string;
15
6
  /** Sample rate this entry has been measured at. */
16
7
  readonly sampleRate: number;
17
8
  /** Samples per inference window at {@link sampleRate}. */
18
9
  readonly windowSize: number;
19
- /** One line for a settings panel or a download prompt. */
20
- readonly description: string;
21
10
  }
22
11
  /**
23
12
  * The default model. v5 is what ADR 0127 decision 10 names, and it is four
@@ -1,4 +1,4 @@
1
- import fetch from '@gjsify/fetch';
1
+ import { type FetchLike, type ModelAvailability } from '@gjsify/model-store';
2
2
  import { type VadModelEntry } from './model-manifest.js';
3
3
  /**
4
4
  * What `available()` answers, as the Web Speech on-device additions spell it:
@@ -8,10 +8,10 @@ import { type VadModelEntry } from './model-manifest.js';
8
8
  * • `downloadable` — the engine is here, the file is not; `install()` fetches it.
9
9
  * • `unavailable` — no native engine on this host, so no model helps.
10
10
  */
11
- export type VadModelAvailability = 'available' | 'downloading' | 'downloadable' | 'unavailable';
11
+ export type VadModelAvailability = ModelAvailability;
12
12
  export interface InstallProgress {
13
13
  readonly modelId: string;
14
- /** Bytes written so far. Jumps straight to `total` — see the header on buffering. */
14
+ /** Bytes written so far. */
15
15
  readonly received: number;
16
16
  /** The manifest's size for this model. */
17
17
  readonly total: number;
@@ -21,12 +21,12 @@ export interface InstallOptions {
21
21
  onProgress?: (progress: InstallProgress) => void;
22
22
  /** Abort the fetch. */
23
23
  signal?: AbortSignal;
24
- /** Override `fetch` from `@gjsify/fetch`. Tests only. */
25
- fetchImpl?: typeof fetch;
24
+ /** Override the global `fetch`. Tests only. */
25
+ fetchImpl?: FetchLike;
26
26
  /** Re-fetch and overwrite a cached file instead of returning it. */
27
27
  force?: boolean;
28
28
  }
29
- /** `GLib.get_user_cache_dir()/gjsify/speech-models` — shared with the other ADR 0127 packages. */
29
+ /** `<user cache>/gjsify/models/speech` — shared with the other ADR 0127 packages. */
30
30
  export declare function modelCacheDir(): string;
31
31
  /** Where `id` is cached, whether or not it exists yet. */
32
32
  export declare function modelPath(id?: string): string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gjsify/vad",
3
- "version": "0.64.25",
3
+ "version": "0.64.26-next.312",
4
4
  "description": "Voice activity detection for GJS: Silero on sherpa-onnx, reporting when speech starts and when a stretch of speech has ended after 300 ms of silence. Takes PCM from @gjsify/media-capture or any async iterable of chunks, and downloads its model on first use instead of bundling one.",
5
5
  "type": "module",
6
6
  "module": "lib/esm/index.js",
@@ -35,16 +35,17 @@
35
35
  "speech"
36
36
  ],
37
37
  "dependencies": {
38
- "@gjsify/fetch": "^0.64.25",
39
- "@gjsify/sherpa-native": "^0.64.25",
40
- "@gjsify/utils": "^0.64.25"
38
+ "@gjsify/model-store": "0.64.26-next.312",
39
+ "@gjsify/path": "0.64.26-next.312",
40
+ "@gjsify/sherpa-native": "0.64.26-next.312",
41
+ "@gjsify/utils": "0.64.26-next.312"
41
42
  },
42
43
  "devDependencies": {
43
44
  "@girs/gio-2.0": "5.4.0",
44
45
  "@girs/gjs": "5.4.0",
45
46
  "@girs/glib-2.0": "5.4.0",
46
- "@gjsify/cli": "^0.64.25",
47
- "@gjsify/unit": "^0.64.25",
47
+ "@gjsify/cli": "0.64.26-next.312",
48
+ "@gjsify/unit": "0.64.26-next.312",
48
49
  "@types/node": "^25.9.2",
49
50
  "typescript": "^6.0.3"
50
51
  },
@@ -76,5 +77,6 @@
76
77
  "bugs": {
77
78
  "url": "https://github.com/gjsify/gjsify/issues"
78
79
  },
79
- "homepage": "https://github.com/gjsify/gjsify/tree/main/packages/web/vad#readme"
80
+ "homepage": "https://github.com/gjsify/gjsify/tree/main/packages/web/vad#readme",
81
+ "gitHead": "75fa6155a8f1fa0f7e5d70c43418ae41ecac8c0e"
80
82
  }