deepfilternet3-assets 1.0.0 → 1.0.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.
package/README.md CHANGED
@@ -1,13 +1,13 @@
1
- # @mezon/deepfilternet3-assets
1
+ # deepfilternet3-assets
2
2
 
3
3
  DeepFilterNet3 WASM and model assets for noise suppression.
4
4
 
5
5
  ## Installation
6
6
 
7
7
  ```bash
8
- npm install @mezon/deepfilternet3-assets
8
+ npm install deepfilternet3-assets
9
9
  # or
10
- yarn add @mezon/deepfilternet3-assets
10
+ yarn add deepfilternet3-assets
11
11
  ```
12
12
 
13
13
  ## Contents
@@ -21,7 +21,7 @@ This package includes:
21
21
  ### Getting Asset Paths (Node.js)
22
22
 
23
23
  ```javascript
24
- const { getWasmPath, getModelPath, getAssetPaths } = require('@mezon/deepfilternet3-assets');
24
+ const { getWasmPath, getModelPath, getAssetPaths } = require('deepfilternet3-assets');
25
25
 
26
26
  // Get individual paths
27
27
  const wasmPath = getWasmPath();
@@ -36,7 +36,7 @@ const { wasm, model } = getAssetPaths();
36
36
  For web applications, you can use the relative paths:
37
37
 
38
38
  ```javascript
39
- const { WASM_RELATIVE_PATH, MODEL_RELATIVE_PATH } = require('@mezon/deepfilternet3-assets');
39
+ const { WASM_RELATIVE_PATH, MODEL_RELATIVE_PATH } = require('deepfilternet3-assets');
40
40
 
41
41
  // Then use with your bundler's asset handling
42
42
  // For example, with Webpack or Vite
@@ -48,7 +48,7 @@ You can copy these files to your static assets directory or CDN:
48
48
 
49
49
  ```javascript
50
50
  const fs = require('fs');
51
- const { getAssetPaths } = require('@mezon/deepfilternet3-assets');
51
+ const { getAssetPaths } = require('deepfilternet3-assets');
52
52
 
53
53
  const assets = getAssetPaths();
54
54
 
@@ -62,7 +62,7 @@ fs.copyFileSync(assets.model, './public/models/DeepFilterNet3_onnx.tar.gz');
62
62
  This package includes TypeScript type definitions:
63
63
 
64
64
  ```typescript
65
- import { getAssetPaths, WASM_RELATIVE_PATH, MODEL_RELATIVE_PATH } from '@mezon/deepfilternet3-assets';
65
+ import { getAssetPaths, WASM_RELATIVE_PATH, MODEL_RELATIVE_PATH } from 'deepfilternet3-assets';
66
66
 
67
67
  const { wasm, model } = getAssetPaths();
68
68
 
package/package.json CHANGED
@@ -1,11 +1,13 @@
1
1
  {
2
2
  "name": "deepfilternet3-assets",
3
- "version": "1.0.0",
3
+ "version": "1.0.1",
4
4
  "description": "DeepFilterNet3 WASM and model assets for noise suppression",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",
7
7
  "files": [
8
8
  "pkg/df_bg.wasm",
9
+ "pkg/df.js",
10
+ "pkg/df.d.ts",
9
11
  "models/DeepFilterNet3_onnx.tar.gz",
10
12
  "index.js",
11
13
  "index.d.ts",
package/pkg/df.d.ts ADDED
@@ -0,0 +1,96 @@
1
+ declare namespace wasm_bindgen {
2
+ /* tslint:disable */
3
+ /* eslint-disable */
4
+ /**
5
+ * Create a DeepFilterNet Model
6
+ *
7
+ * Args:
8
+ * - path: File path to a DeepFilterNet tar.gz onnx model
9
+ * - atten_lim: Attenuation limit in dB.
10
+ *
11
+ * Returns:
12
+ * - DF state doing the full processing: stft, DNN noise reduction, istft.
13
+ * @param {Uint8Array} model_bytes
14
+ * @param {number} atten_lim
15
+ * @returns {number}
16
+ */
17
+ export function df_create(model_bytes: Uint8Array, atten_lim: number): number;
18
+ /**
19
+ * Get DeepFilterNet frame size in samples.
20
+ * @param {number} st
21
+ * @returns {number}
22
+ */
23
+ export function df_get_frame_length(st: number): number;
24
+ /**
25
+ * @param {number} st
26
+ * @param {boolean} enabled
27
+ * @param {number} desired_output_rms
28
+ * @param {number} distortion_factor
29
+ * @param {number} snr_thresh
30
+ */
31
+ export function df_set_agc_params(st: number, enabled: boolean, desired_output_rms: number, distortion_factor: number, snr_thresh: number): void;
32
+ /**
33
+ * Set DeepFilterNet attenuation limit.
34
+ *
35
+ * Args:
36
+ * - lim_db: New attenuation limit in dB.
37
+ * @param {number} st
38
+ * @param {number} lim_db
39
+ */
40
+ export function df_set_atten_lim(st: number, lim_db: number): void;
41
+ /**
42
+ * Set DeepFilterNet post filter beta. A beta of 0 disables the post filter.
43
+ *
44
+ * Args:
45
+ * - beta: Post filter attenuation. Suitable range between 0.05 and 0;
46
+ * @param {number} st
47
+ * @param {number} beta
48
+ */
49
+ export function df_set_post_filter_beta(st: number, beta: number): void;
50
+ /**
51
+ * Processes a chunk of samples.
52
+ *
53
+ * Args:
54
+ * - df_state: Created via df_create()
55
+ * - input: Input buffer of length df_get_frame_length()
56
+ * - output: Output buffer of length df_get_frame_length()
57
+ *
58
+ * Returns:
59
+ * - Local SNR of the current frame.
60
+ * @param {number} st
61
+ * @param {Float32Array} input
62
+ * @returns {Float32Array}
63
+ */
64
+ export function df_process_frame(st: number, input: Float32Array): Float32Array;
65
+ /**
66
+ */
67
+ export class DFState {
68
+ free(): void;
69
+ }
70
+
71
+ }
72
+
73
+ declare type InitInput = RequestInfo | URL | Response | BufferSource | WebAssembly.Module;
74
+
75
+ declare interface InitOutput {
76
+ readonly memory: WebAssembly.Memory;
77
+ readonly __wbg_dfstate_free: (a: number) => void;
78
+ readonly df_create: (a: number, b: number, c: number) => number;
79
+ readonly df_get_frame_length: (a: number) => number;
80
+ readonly df_process_frame: (a: number, b: number, c: number) => number;
81
+ readonly df_set_agc_params: (a: number, b: number, c: number, d: number, e: number) => void;
82
+ readonly df_set_atten_lim: (a: number, b: number) => void;
83
+ readonly df_set_post_filter_beta: (a: number, b: number) => void;
84
+ readonly __wbindgen_malloc: (a: number, b: number) => number;
85
+ readonly __wbindgen_exn_store: (a: number) => void;
86
+ }
87
+
88
+ /**
89
+ * If `module_or_path` is {RequestInfo} or {URL}, makes a request and
90
+ * for everything else, calls `WebAssembly.instantiate` directly.
91
+ *
92
+ * @param {InitInput | Promise<InitInput>} module_or_path
93
+ *
94
+ * @returns {Promise<InitOutput>}
95
+ */
96
+ declare function wasm_bindgen (module_or_path?: InitInput | Promise<InitInput>): Promise<InitOutput>;
package/pkg/df.js ADDED
@@ -0,0 +1,408 @@
1
+ let wasm_bindgen;
2
+ (function() {
3
+ const __exports = {};
4
+ let script_src;
5
+ if (typeof document !== 'undefined' && document.currentScript !== null) {
6
+ script_src = new URL(document.currentScript.src, location.href).toString();
7
+ }
8
+ let wasm = undefined;
9
+
10
+ const heap = new Array(128).fill(undefined);
11
+
12
+ heap.push(undefined, null, true, false);
13
+
14
+ function getObject(idx) { return heap[idx]; }
15
+
16
+ let heap_next = heap.length;
17
+
18
+ function dropObject(idx) {
19
+ if (idx < 132) return;
20
+ heap[idx] = heap_next;
21
+ heap_next = idx;
22
+ }
23
+
24
+ function takeObject(idx) {
25
+ const ret = getObject(idx);
26
+ dropObject(idx);
27
+ return ret;
28
+ }
29
+
30
+ const cachedTextDecoder = (typeof TextDecoder !== 'undefined' ? new TextDecoder('utf-8', { ignoreBOM: true, fatal: true }) : { decode: () => { throw Error('TextDecoder not available') } } );
31
+
32
+ if (typeof TextDecoder !== 'undefined') { cachedTextDecoder.decode(); };
33
+
34
+ let cachedUint8Memory0 = null;
35
+
36
+ function getUint8Memory0() {
37
+ if (cachedUint8Memory0 === null || cachedUint8Memory0.byteLength === 0) {
38
+ cachedUint8Memory0 = new Uint8Array(wasm.memory.buffer);
39
+ }
40
+ return cachedUint8Memory0;
41
+ }
42
+
43
+ function getStringFromWasm0(ptr, len) {
44
+ ptr = ptr >>> 0;
45
+ return cachedTextDecoder.decode(getUint8Memory0().subarray(ptr, ptr + len));
46
+ }
47
+
48
+ function addHeapObject(obj) {
49
+ if (heap_next === heap.length) heap.push(heap.length + 1);
50
+ const idx = heap_next;
51
+ heap_next = heap[idx];
52
+
53
+ heap[idx] = obj;
54
+ return idx;
55
+ }
56
+
57
+ let WASM_VECTOR_LEN = 0;
58
+
59
+ function passArray8ToWasm0(arg, malloc) {
60
+ const ptr = malloc(arg.length * 1, 1) >>> 0;
61
+ getUint8Memory0().set(arg, ptr / 1);
62
+ WASM_VECTOR_LEN = arg.length;
63
+ return ptr;
64
+ }
65
+ /**
66
+ * Create a DeepFilterNet Model
67
+ *
68
+ * Args:
69
+ * - path: File path to a DeepFilterNet tar.gz onnx model
70
+ * - atten_lim: Attenuation limit in dB.
71
+ *
72
+ * Returns:
73
+ * - DF state doing the full processing: stft, DNN noise reduction, istft.
74
+ * @param {Uint8Array} model_bytes
75
+ * @param {number} atten_lim
76
+ * @returns {number}
77
+ */
78
+ __exports.df_create = function(model_bytes, atten_lim) {
79
+ const ptr0 = passArray8ToWasm0(model_bytes, wasm.__wbindgen_malloc);
80
+ const len0 = WASM_VECTOR_LEN;
81
+ const ret = wasm.df_create(ptr0, len0, atten_lim);
82
+ return ret >>> 0;
83
+ };
84
+
85
+ /**
86
+ * Get DeepFilterNet frame size in samples.
87
+ * @param {number} st
88
+ * @returns {number}
89
+ */
90
+ __exports.df_get_frame_length = function(st) {
91
+ const ret = wasm.df_get_frame_length(st);
92
+ return ret >>> 0;
93
+ };
94
+
95
+ /**
96
+ * @param {number} st
97
+ * @param {boolean} enabled
98
+ * @param {number} desired_output_rms
99
+ * @param {number} distortion_factor
100
+ * @param {number} snr_thresh
101
+ */
102
+ __exports.df_set_agc_params = function(st, enabled, desired_output_rms, distortion_factor, snr_thresh) {
103
+ wasm.df_set_agc_params(st, enabled, desired_output_rms, distortion_factor, snr_thresh);
104
+ };
105
+
106
+ /**
107
+ * Set DeepFilterNet attenuation limit.
108
+ *
109
+ * Args:
110
+ * - lim_db: New attenuation limit in dB.
111
+ * @param {number} st
112
+ * @param {number} lim_db
113
+ */
114
+ __exports.df_set_atten_lim = function(st, lim_db) {
115
+ wasm.df_set_atten_lim(st, lim_db);
116
+ };
117
+
118
+ /**
119
+ * Set DeepFilterNet post filter beta. A beta of 0 disables the post filter.
120
+ *
121
+ * Args:
122
+ * - beta: Post filter attenuation. Suitable range between 0.05 and 0;
123
+ * @param {number} st
124
+ * @param {number} beta
125
+ */
126
+ __exports.df_set_post_filter_beta = function(st, beta) {
127
+ wasm.df_set_post_filter_beta(st, beta);
128
+ };
129
+
130
+ let cachedFloat32Memory0 = null;
131
+
132
+ function getFloat32Memory0() {
133
+ if (cachedFloat32Memory0 === null || cachedFloat32Memory0.byteLength === 0) {
134
+ cachedFloat32Memory0 = new Float32Array(wasm.memory.buffer);
135
+ }
136
+ return cachedFloat32Memory0;
137
+ }
138
+
139
+ function passArrayF32ToWasm0(arg, malloc) {
140
+ const ptr = malloc(arg.length * 4, 4) >>> 0;
141
+ getFloat32Memory0().set(arg, ptr / 4);
142
+ WASM_VECTOR_LEN = arg.length;
143
+ return ptr;
144
+ }
145
+ /**
146
+ * Processes a chunk of samples.
147
+ *
148
+ * Args:
149
+ * - df_state: Created via df_create()
150
+ * - input: Input buffer of length df_get_frame_length()
151
+ * - output: Output buffer of length df_get_frame_length()
152
+ *
153
+ * Returns:
154
+ * - Local SNR of the current frame.
155
+ * @param {number} st
156
+ * @param {Float32Array} input
157
+ * @returns {Float32Array}
158
+ */
159
+ __exports.df_process_frame = function(st, input) {
160
+ const ptr0 = passArrayF32ToWasm0(input, wasm.__wbindgen_malloc);
161
+ const len0 = WASM_VECTOR_LEN;
162
+ const ret = wasm.df_process_frame(st, ptr0, len0);
163
+ return takeObject(ret);
164
+ };
165
+
166
+ function handleError(f, args) {
167
+ try {
168
+ return f.apply(this, args);
169
+ } catch (e) {
170
+ wasm.__wbindgen_exn_store(addHeapObject(e));
171
+ }
172
+ }
173
+
174
+ const DFStateFinalization = (typeof FinalizationRegistry === 'undefined')
175
+ ? { register: () => {}, unregister: () => {} }
176
+ : new FinalizationRegistry(ptr => wasm.__wbg_dfstate_free(ptr >>> 0));
177
+ /**
178
+ */
179
+ class DFState {
180
+
181
+ __destroy_into_raw() {
182
+ const ptr = this.__wbg_ptr;
183
+ this.__wbg_ptr = 0;
184
+ DFStateFinalization.unregister(this);
185
+ return ptr;
186
+ }
187
+
188
+ free() {
189
+ const ptr = this.__destroy_into_raw();
190
+ wasm.__wbg_dfstate_free(ptr);
191
+ }
192
+ }
193
+ __exports.DFState = DFState;
194
+
195
+ async function __wbg_load(module, imports) {
196
+ if (typeof Response === 'function' && module instanceof Response) {
197
+ if (typeof WebAssembly.instantiateStreaming === 'function') {
198
+ try {
199
+ return await WebAssembly.instantiateStreaming(module, imports);
200
+
201
+ } catch (e) {
202
+ if (module.headers.get('Content-Type') != 'application/wasm') {
203
+ console.warn("`WebAssembly.instantiateStreaming` failed because your server does not serve wasm with `application/wasm` MIME type. Falling back to `WebAssembly.instantiate` which is slower. Original error:\n", e);
204
+
205
+ } else {
206
+ throw e;
207
+ }
208
+ }
209
+ }
210
+
211
+ const bytes = await module.arrayBuffer();
212
+ return await WebAssembly.instantiate(bytes, imports);
213
+
214
+ } else {
215
+ const instance = await WebAssembly.instantiate(module, imports);
216
+
217
+ if (instance instanceof WebAssembly.Instance) {
218
+ return { instance, module };
219
+
220
+ } else {
221
+ return instance;
222
+ }
223
+ }
224
+ }
225
+
226
+ function __wbg_get_imports() {
227
+ const imports = {};
228
+ imports.wbg = {};
229
+ imports.wbg.__wbindgen_object_drop_ref = function(arg0) {
230
+ takeObject(arg0);
231
+ };
232
+ imports.wbg.__wbg_crypto_566d7465cdbb6b7a = function(arg0) {
233
+ const ret = getObject(arg0).crypto;
234
+ return addHeapObject(ret);
235
+ };
236
+ imports.wbg.__wbindgen_is_object = function(arg0) {
237
+ const val = getObject(arg0);
238
+ const ret = typeof(val) === 'object' && val !== null;
239
+ return ret;
240
+ };
241
+ imports.wbg.__wbg_process_dc09a8c7d59982f6 = function(arg0) {
242
+ const ret = getObject(arg0).process;
243
+ return addHeapObject(ret);
244
+ };
245
+ imports.wbg.__wbg_versions_d98c6400c6ca2bd8 = function(arg0) {
246
+ const ret = getObject(arg0).versions;
247
+ return addHeapObject(ret);
248
+ };
249
+ imports.wbg.__wbg_node_caaf83d002149bd5 = function(arg0) {
250
+ const ret = getObject(arg0).node;
251
+ return addHeapObject(ret);
252
+ };
253
+ imports.wbg.__wbindgen_is_string = function(arg0) {
254
+ const ret = typeof(getObject(arg0)) === 'string';
255
+ return ret;
256
+ };
257
+ imports.wbg.__wbg_require_94a9da52636aacbf = function() { return handleError(function () {
258
+ const ret = module.require;
259
+ return addHeapObject(ret);
260
+ }, arguments) };
261
+ imports.wbg.__wbindgen_is_function = function(arg0) {
262
+ const ret = typeof(getObject(arg0)) === 'function';
263
+ return ret;
264
+ };
265
+ imports.wbg.__wbindgen_string_new = function(arg0, arg1) {
266
+ const ret = getStringFromWasm0(arg0, arg1);
267
+ return addHeapObject(ret);
268
+ };
269
+ imports.wbg.__wbg_msCrypto_0b84745e9245cdf6 = function(arg0) {
270
+ const ret = getObject(arg0).msCrypto;
271
+ return addHeapObject(ret);
272
+ };
273
+ imports.wbg.__wbg_randomFillSync_290977693942bf03 = function() { return handleError(function (arg0, arg1) {
274
+ getObject(arg0).randomFillSync(takeObject(arg1));
275
+ }, arguments) };
276
+ imports.wbg.__wbg_getRandomValues_260cc23a41afad9a = function() { return handleError(function (arg0, arg1) {
277
+ getObject(arg0).getRandomValues(getObject(arg1));
278
+ }, arguments) };
279
+ imports.wbg.__wbg_newnoargs_e258087cd0daa0ea = function(arg0, arg1) {
280
+ const ret = new Function(getStringFromWasm0(arg0, arg1));
281
+ return addHeapObject(ret);
282
+ };
283
+ imports.wbg.__wbg_new_63b92bc8671ed464 = function(arg0) {
284
+ const ret = new Uint8Array(getObject(arg0));
285
+ return addHeapObject(ret);
286
+ };
287
+ imports.wbg.__wbg_new_9efabd6b6d2ce46d = function(arg0) {
288
+ const ret = new Float32Array(getObject(arg0));
289
+ return addHeapObject(ret);
290
+ };
291
+ imports.wbg.__wbg_buffer_12d079cc21e14bdb = function(arg0) {
292
+ const ret = getObject(arg0).buffer;
293
+ return addHeapObject(ret);
294
+ };
295
+ imports.wbg.__wbg_newwithbyteoffsetandlength_aa4a17c33a06e5cb = function(arg0, arg1, arg2) {
296
+ const ret = new Uint8Array(getObject(arg0), arg1 >>> 0, arg2 >>> 0);
297
+ return addHeapObject(ret);
298
+ };
299
+ imports.wbg.__wbg_newwithlength_e9b4878cebadb3d3 = function(arg0) {
300
+ const ret = new Uint8Array(arg0 >>> 0);
301
+ return addHeapObject(ret);
302
+ };
303
+ imports.wbg.__wbg_set_a47bac70306a19a7 = function(arg0, arg1, arg2) {
304
+ getObject(arg0).set(getObject(arg1), arg2 >>> 0);
305
+ };
306
+ imports.wbg.__wbg_subarray_a1f73cd4b5b42fe1 = function(arg0, arg1, arg2) {
307
+ const ret = getObject(arg0).subarray(arg1 >>> 0, arg2 >>> 0);
308
+ return addHeapObject(ret);
309
+ };
310
+ imports.wbg.__wbg_newwithbyteoffsetandlength_4a659d079a1650e0 = function(arg0, arg1, arg2) {
311
+ const ret = new Float32Array(getObject(arg0), arg1 >>> 0, arg2 >>> 0);
312
+ return addHeapObject(ret);
313
+ };
314
+ imports.wbg.__wbg_self_ce0dbfc45cf2f5be = function() { return handleError(function () {
315
+ const ret = self.self;
316
+ return addHeapObject(ret);
317
+ }, arguments) };
318
+ imports.wbg.__wbg_window_c6fb939a7f436783 = function() { return handleError(function () {
319
+ const ret = window.window;
320
+ return addHeapObject(ret);
321
+ }, arguments) };
322
+ imports.wbg.__wbg_globalThis_d1e6af4856ba331b = function() { return handleError(function () {
323
+ const ret = globalThis.globalThis;
324
+ return addHeapObject(ret);
325
+ }, arguments) };
326
+ imports.wbg.__wbg_global_207b558942527489 = function() { return handleError(function () {
327
+ const ret = global.global;
328
+ return addHeapObject(ret);
329
+ }, arguments) };
330
+ imports.wbg.__wbindgen_is_undefined = function(arg0) {
331
+ const ret = getObject(arg0) === undefined;
332
+ return ret;
333
+ };
334
+ imports.wbg.__wbg_call_27c0f87801dedf93 = function() { return handleError(function (arg0, arg1) {
335
+ const ret = getObject(arg0).call(getObject(arg1));
336
+ return addHeapObject(ret);
337
+ }, arguments) };
338
+ imports.wbg.__wbindgen_object_clone_ref = function(arg0) {
339
+ const ret = getObject(arg0);
340
+ return addHeapObject(ret);
341
+ };
342
+ imports.wbg.__wbg_call_b3ca7c6051f9bec1 = function() { return handleError(function (arg0, arg1, arg2) {
343
+ const ret = getObject(arg0).call(getObject(arg1), getObject(arg2));
344
+ return addHeapObject(ret);
345
+ }, arguments) };
346
+ imports.wbg.__wbindgen_memory = function() {
347
+ const ret = wasm.memory;
348
+ return addHeapObject(ret);
349
+ };
350
+ imports.wbg.__wbindgen_throw = function(arg0, arg1) {
351
+ throw new Error(getStringFromWasm0(arg0, arg1));
352
+ };
353
+
354
+ return imports;
355
+ }
356
+
357
+ function __wbg_init_memory(imports, maybe_memory) {
358
+
359
+ }
360
+
361
+ function __wbg_finalize_init(instance, module) {
362
+ wasm = instance.exports;
363
+ __wbg_init.__wbindgen_wasm_module = module;
364
+ cachedFloat32Memory0 = null;
365
+ cachedUint8Memory0 = null;
366
+
367
+
368
+ return wasm;
369
+ }
370
+
371
+ function initSync(module) {
372
+ if (wasm !== undefined) return wasm;
373
+
374
+ const imports = __wbg_get_imports();
375
+
376
+ __wbg_init_memory(imports);
377
+
378
+ if (!(module instanceof WebAssembly.Module)) {
379
+ module = new WebAssembly.Module(module);
380
+ }
381
+
382
+ const instance = new WebAssembly.Instance(module, imports);
383
+
384
+ return __wbg_finalize_init(instance, module);
385
+ }
386
+
387
+ async function __wbg_init(input) {
388
+ if (wasm !== undefined) return wasm;
389
+
390
+ if (typeof input === 'undefined' && typeof script_src !== 'undefined') {
391
+ input = script_src.replace(/\.js$/, '_bg.wasm');
392
+ }
393
+ const imports = __wbg_get_imports();
394
+
395
+ if (typeof input === 'string' || (typeof Request === 'function' && input instanceof Request) || (typeof URL === 'function' && input instanceof URL)) {
396
+ input = fetch(input);
397
+ }
398
+
399
+ __wbg_init_memory(imports);
400
+
401
+ const { instance, module } = await __wbg_load(await input, imports);
402
+
403
+ return __wbg_finalize_init(instance, module);
404
+ }
405
+
406
+ wasm_bindgen = Object.assign(__wbg_init, { initSync }, __exports);
407
+
408
+ })();