@sorisdk/matcher 0.4.0 → 0.6.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 +3 -1
- package/dist/generated/core.d.ts +21 -0
- package/dist/generated/core.js +1 -1
- package/dist/generated/core_bg.js +221 -0
- package/dist/generated/core_bg.wasm +0 -0
- package/dist/generated/core_bg.wasm.d.ts +14 -0
- package/dist/index.d.ts +58 -1
- package/dist/index.js +358 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -72,7 +72,9 @@ If you want campaign events and browser recognition flow on top of matching, use
|
|
|
72
72
|
## Metadata lookup
|
|
73
73
|
|
|
74
74
|
Audiopack footer metadata is available through explicit lookup rather than being
|
|
75
|
-
embedded in `MatchResult`.
|
|
75
|
+
embedded in `MatchResult`. Segment timing is the exception: when a pack provides
|
|
76
|
+
valid `matcherSegments` metadata, `MatchResult.position` is segment-local and
|
|
77
|
+
`MatchResult.durationMillis` contains the matched segment duration.
|
|
76
78
|
|
|
77
79
|
```ts
|
|
78
80
|
const best = await session.bestMatch(queryBytes);
|
package/dist/generated/core.d.ts
CHANGED
|
@@ -21,10 +21,31 @@ export class WasmMatcherEngine {
|
|
|
21
21
|
[Symbol.dispose](): void;
|
|
22
22
|
bestMatch(database: WasmMatcherDatabase, query: Uint8Array, config?: any | null): any;
|
|
23
23
|
bestMatchWithVariants(database: WasmMatcherDatabase, query: Uint8Array, pitch_query: any, config?: any | null, variant_config?: any | null): any;
|
|
24
|
+
detectAudioMarker(pcm16_le: Uint8Array, sample_rate: number, config?: any | null): any;
|
|
25
|
+
detectPatternMark(pcm16_le: Uint8Array, sample_rate: number, config?: any | null): any;
|
|
26
|
+
estimatePitchRatio(pcm16_le: Uint8Array, sample_rate: number): any;
|
|
27
|
+
estimatePitchRatioAgainstReference(pcm16_le: Uint8Array, sample_rate: number, reference_pitch_hz: number, reference_confidence?: number | null): any;
|
|
28
|
+
estimatePitchRatioAgainstSpectralFeatures(pcm16_le: Uint8Array, sample_rate: number, reference_features: string, reference_position_millis: number, reference_confidence?: number | null): any;
|
|
29
|
+
extractPitchReference(pcm16_le: Uint8Array, sample_rate: number): any;
|
|
30
|
+
extractSpectralShiftReference(pcm16_le: Uint8Array, sample_rate: number): any;
|
|
24
31
|
matchQuery(database: WasmMatcherDatabase, query: Uint8Array, config?: any | null): any;
|
|
25
32
|
matchQueryWithVariants(database: WasmMatcherDatabase, query: Uint8Array, pitch_query: any, config?: any | null, variant_config?: any | null): any;
|
|
26
33
|
constructor();
|
|
27
34
|
resetDistinctMatchState(): void;
|
|
28
35
|
}
|
|
29
36
|
|
|
37
|
+
export function detectAudioMarker(pcm16_le: Uint8Array, sample_rate: number, config?: any | null): any;
|
|
38
|
+
|
|
39
|
+
export function detectPatternMark(pcm16_le: Uint8Array, sample_rate: number, config?: any | null): any;
|
|
40
|
+
|
|
41
|
+
export function estimatePitchRatio(pcm16_le: Uint8Array, sample_rate: number): any;
|
|
42
|
+
|
|
43
|
+
export function estimatePitchRatioAgainstReference(pcm16_le: Uint8Array, sample_rate: number, reference_pitch_hz: number, reference_confidence?: number | null): any;
|
|
44
|
+
|
|
45
|
+
export function estimatePitchRatioAgainstSpectralFeatures(pcm16_le: Uint8Array, sample_rate: number, reference_features: string, reference_position_millis: number, reference_confidence?: number | null): any;
|
|
46
|
+
|
|
47
|
+
export function extractPitchReference(pcm16_le: Uint8Array, sample_rate: number): any;
|
|
48
|
+
|
|
49
|
+
export function extractSpectralShiftReference(pcm16_le: Uint8Array, sample_rate: number): any;
|
|
50
|
+
|
|
30
51
|
export function init_matcher_wasm(): void;
|
package/dist/generated/core.js
CHANGED
|
@@ -5,5 +5,5 @@ import { __wbg_set_wasm } from "./core_bg.js";
|
|
|
5
5
|
__wbg_set_wasm(wasm);
|
|
6
6
|
wasm.__wbindgen_start();
|
|
7
7
|
export {
|
|
8
|
-
WasmMatcherDatabase, WasmMatcherEngine, init_matcher_wasm
|
|
8
|
+
WasmMatcherDatabase, WasmMatcherEngine, detectAudioMarker, detectPatternMark, estimatePitchRatio, estimatePitchRatioAgainstReference, estimatePitchRatioAgainstSpectralFeatures, extractPitchReference, extractSpectralShiftReference, init_matcher_wasm
|
|
9
9
|
} from "./core_bg.js";
|
|
@@ -164,6 +164,113 @@ export class WasmMatcherEngine {
|
|
|
164
164
|
}
|
|
165
165
|
return takeFromExternrefTable0(ret[0]);
|
|
166
166
|
}
|
|
167
|
+
/**
|
|
168
|
+
* @param {Uint8Array} pcm16_le
|
|
169
|
+
* @param {number} sample_rate
|
|
170
|
+
* @param {any | null} [config]
|
|
171
|
+
* @returns {any}
|
|
172
|
+
*/
|
|
173
|
+
detectAudioMarker(pcm16_le, sample_rate, config) {
|
|
174
|
+
const ptr0 = passArray8ToWasm0(pcm16_le, wasm.__wbindgen_malloc);
|
|
175
|
+
const len0 = WASM_VECTOR_LEN;
|
|
176
|
+
const ret = wasm.wasmmatcherengine_detectAudioMarker(this.__wbg_ptr, ptr0, len0, sample_rate, isLikeNone(config) ? 0 : addToExternrefTable0(config));
|
|
177
|
+
if (ret[2]) {
|
|
178
|
+
throw takeFromExternrefTable0(ret[1]);
|
|
179
|
+
}
|
|
180
|
+
return takeFromExternrefTable0(ret[0]);
|
|
181
|
+
}
|
|
182
|
+
/**
|
|
183
|
+
* @param {Uint8Array} pcm16_le
|
|
184
|
+
* @param {number} sample_rate
|
|
185
|
+
* @param {any | null} [config]
|
|
186
|
+
* @returns {any}
|
|
187
|
+
*/
|
|
188
|
+
detectPatternMark(pcm16_le, sample_rate, config) {
|
|
189
|
+
const ptr0 = passArray8ToWasm0(pcm16_le, wasm.__wbindgen_malloc);
|
|
190
|
+
const len0 = WASM_VECTOR_LEN;
|
|
191
|
+
const ret = wasm.wasmmatcherengine_detectPatternMark(this.__wbg_ptr, ptr0, len0, sample_rate, isLikeNone(config) ? 0 : addToExternrefTable0(config));
|
|
192
|
+
if (ret[2]) {
|
|
193
|
+
throw takeFromExternrefTable0(ret[1]);
|
|
194
|
+
}
|
|
195
|
+
return takeFromExternrefTable0(ret[0]);
|
|
196
|
+
}
|
|
197
|
+
/**
|
|
198
|
+
* @param {Uint8Array} pcm16_le
|
|
199
|
+
* @param {number} sample_rate
|
|
200
|
+
* @returns {any}
|
|
201
|
+
*/
|
|
202
|
+
estimatePitchRatio(pcm16_le, sample_rate) {
|
|
203
|
+
const ptr0 = passArray8ToWasm0(pcm16_le, wasm.__wbindgen_malloc);
|
|
204
|
+
const len0 = WASM_VECTOR_LEN;
|
|
205
|
+
const ret = wasm.wasmmatcherengine_estimatePitchRatio(this.__wbg_ptr, ptr0, len0, sample_rate);
|
|
206
|
+
if (ret[2]) {
|
|
207
|
+
throw takeFromExternrefTable0(ret[1]);
|
|
208
|
+
}
|
|
209
|
+
return takeFromExternrefTable0(ret[0]);
|
|
210
|
+
}
|
|
211
|
+
/**
|
|
212
|
+
* @param {Uint8Array} pcm16_le
|
|
213
|
+
* @param {number} sample_rate
|
|
214
|
+
* @param {number} reference_pitch_hz
|
|
215
|
+
* @param {number | null} [reference_confidence]
|
|
216
|
+
* @returns {any}
|
|
217
|
+
*/
|
|
218
|
+
estimatePitchRatioAgainstReference(pcm16_le, sample_rate, reference_pitch_hz, reference_confidence) {
|
|
219
|
+
const ptr0 = passArray8ToWasm0(pcm16_le, wasm.__wbindgen_malloc);
|
|
220
|
+
const len0 = WASM_VECTOR_LEN;
|
|
221
|
+
const ret = wasm.wasmmatcherengine_estimatePitchRatioAgainstReference(this.__wbg_ptr, ptr0, len0, sample_rate, reference_pitch_hz, !isLikeNone(reference_confidence), isLikeNone(reference_confidence) ? 0 : reference_confidence);
|
|
222
|
+
if (ret[2]) {
|
|
223
|
+
throw takeFromExternrefTable0(ret[1]);
|
|
224
|
+
}
|
|
225
|
+
return takeFromExternrefTable0(ret[0]);
|
|
226
|
+
}
|
|
227
|
+
/**
|
|
228
|
+
* @param {Uint8Array} pcm16_le
|
|
229
|
+
* @param {number} sample_rate
|
|
230
|
+
* @param {string} reference_features
|
|
231
|
+
* @param {number} reference_position_millis
|
|
232
|
+
* @param {number | null} [reference_confidence]
|
|
233
|
+
* @returns {any}
|
|
234
|
+
*/
|
|
235
|
+
estimatePitchRatioAgainstSpectralFeatures(pcm16_le, sample_rate, reference_features, reference_position_millis, reference_confidence) {
|
|
236
|
+
const ptr0 = passArray8ToWasm0(pcm16_le, wasm.__wbindgen_malloc);
|
|
237
|
+
const len0 = WASM_VECTOR_LEN;
|
|
238
|
+
const ptr1 = passStringToWasm0(reference_features, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
239
|
+
const len1 = WASM_VECTOR_LEN;
|
|
240
|
+
const ret = wasm.wasmmatcherengine_estimatePitchRatioAgainstSpectralFeatures(this.__wbg_ptr, ptr0, len0, sample_rate, ptr1, len1, reference_position_millis, !isLikeNone(reference_confidence), isLikeNone(reference_confidence) ? 0 : reference_confidence);
|
|
241
|
+
if (ret[2]) {
|
|
242
|
+
throw takeFromExternrefTable0(ret[1]);
|
|
243
|
+
}
|
|
244
|
+
return takeFromExternrefTable0(ret[0]);
|
|
245
|
+
}
|
|
246
|
+
/**
|
|
247
|
+
* @param {Uint8Array} pcm16_le
|
|
248
|
+
* @param {number} sample_rate
|
|
249
|
+
* @returns {any}
|
|
250
|
+
*/
|
|
251
|
+
extractPitchReference(pcm16_le, sample_rate) {
|
|
252
|
+
const ptr0 = passArray8ToWasm0(pcm16_le, wasm.__wbindgen_malloc);
|
|
253
|
+
const len0 = WASM_VECTOR_LEN;
|
|
254
|
+
const ret = wasm.wasmmatcherengine_extractPitchReference(this.__wbg_ptr, ptr0, len0, sample_rate);
|
|
255
|
+
if (ret[2]) {
|
|
256
|
+
throw takeFromExternrefTable0(ret[1]);
|
|
257
|
+
}
|
|
258
|
+
return takeFromExternrefTable0(ret[0]);
|
|
259
|
+
}
|
|
260
|
+
/**
|
|
261
|
+
* @param {Uint8Array} pcm16_le
|
|
262
|
+
* @param {number} sample_rate
|
|
263
|
+
* @returns {any}
|
|
264
|
+
*/
|
|
265
|
+
extractSpectralShiftReference(pcm16_le, sample_rate) {
|
|
266
|
+
const ptr0 = passArray8ToWasm0(pcm16_le, wasm.__wbindgen_malloc);
|
|
267
|
+
const len0 = WASM_VECTOR_LEN;
|
|
268
|
+
const ret = wasm.wasmmatcherengine_extractSpectralShiftReference(this.__wbg_ptr, ptr0, len0, sample_rate);
|
|
269
|
+
if (ret[2]) {
|
|
270
|
+
throw takeFromExternrefTable0(ret[1]);
|
|
271
|
+
}
|
|
272
|
+
return takeFromExternrefTable0(ret[0]);
|
|
273
|
+
}
|
|
167
274
|
/**
|
|
168
275
|
* @param {WasmMatcherDatabase} database
|
|
169
276
|
* @param {Uint8Array} query
|
|
@@ -210,6 +317,120 @@ export class WasmMatcherEngine {
|
|
|
210
317
|
}
|
|
211
318
|
if (Symbol.dispose) WasmMatcherEngine.prototype[Symbol.dispose] = WasmMatcherEngine.prototype.free;
|
|
212
319
|
|
|
320
|
+
/**
|
|
321
|
+
* @param {Uint8Array} pcm16_le
|
|
322
|
+
* @param {number} sample_rate
|
|
323
|
+
* @param {any | null} [config]
|
|
324
|
+
* @returns {any}
|
|
325
|
+
*/
|
|
326
|
+
export function detectAudioMarker(pcm16_le, sample_rate, config) {
|
|
327
|
+
const ptr0 = passArray8ToWasm0(pcm16_le, wasm.__wbindgen_malloc);
|
|
328
|
+
const len0 = WASM_VECTOR_LEN;
|
|
329
|
+
const ret = wasm.detectAudioMarker(ptr0, len0, sample_rate, isLikeNone(config) ? 0 : addToExternrefTable0(config));
|
|
330
|
+
if (ret[2]) {
|
|
331
|
+
throw takeFromExternrefTable0(ret[1]);
|
|
332
|
+
}
|
|
333
|
+
return takeFromExternrefTable0(ret[0]);
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
/**
|
|
337
|
+
* @param {Uint8Array} pcm16_le
|
|
338
|
+
* @param {number} sample_rate
|
|
339
|
+
* @param {any | null} [config]
|
|
340
|
+
* @returns {any}
|
|
341
|
+
*/
|
|
342
|
+
export function detectPatternMark(pcm16_le, sample_rate, config) {
|
|
343
|
+
const ptr0 = passArray8ToWasm0(pcm16_le, wasm.__wbindgen_malloc);
|
|
344
|
+
const len0 = WASM_VECTOR_LEN;
|
|
345
|
+
const ret = wasm.detectPatternMark(ptr0, len0, sample_rate, isLikeNone(config) ? 0 : addToExternrefTable0(config));
|
|
346
|
+
if (ret[2]) {
|
|
347
|
+
throw takeFromExternrefTable0(ret[1]);
|
|
348
|
+
}
|
|
349
|
+
return takeFromExternrefTable0(ret[0]);
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
/**
|
|
353
|
+
* @param {Uint8Array} pcm16_le
|
|
354
|
+
* @param {number} sample_rate
|
|
355
|
+
* @returns {any}
|
|
356
|
+
*/
|
|
357
|
+
export function estimatePitchRatio(pcm16_le, sample_rate) {
|
|
358
|
+
const ptr0 = passArray8ToWasm0(pcm16_le, wasm.__wbindgen_malloc);
|
|
359
|
+
const len0 = WASM_VECTOR_LEN;
|
|
360
|
+
const ret = wasm.estimatePitchRatio(ptr0, len0, sample_rate);
|
|
361
|
+
if (ret[2]) {
|
|
362
|
+
throw takeFromExternrefTable0(ret[1]);
|
|
363
|
+
}
|
|
364
|
+
return takeFromExternrefTable0(ret[0]);
|
|
365
|
+
}
|
|
366
|
+
|
|
367
|
+
/**
|
|
368
|
+
* @param {Uint8Array} pcm16_le
|
|
369
|
+
* @param {number} sample_rate
|
|
370
|
+
* @param {number} reference_pitch_hz
|
|
371
|
+
* @param {number | null} [reference_confidence]
|
|
372
|
+
* @returns {any}
|
|
373
|
+
*/
|
|
374
|
+
export function estimatePitchRatioAgainstReference(pcm16_le, sample_rate, reference_pitch_hz, reference_confidence) {
|
|
375
|
+
const ptr0 = passArray8ToWasm0(pcm16_le, wasm.__wbindgen_malloc);
|
|
376
|
+
const len0 = WASM_VECTOR_LEN;
|
|
377
|
+
const ret = wasm.estimatePitchRatioAgainstReference(ptr0, len0, sample_rate, reference_pitch_hz, !isLikeNone(reference_confidence), isLikeNone(reference_confidence) ? 0 : reference_confidence);
|
|
378
|
+
if (ret[2]) {
|
|
379
|
+
throw takeFromExternrefTable0(ret[1]);
|
|
380
|
+
}
|
|
381
|
+
return takeFromExternrefTable0(ret[0]);
|
|
382
|
+
}
|
|
383
|
+
|
|
384
|
+
/**
|
|
385
|
+
* @param {Uint8Array} pcm16_le
|
|
386
|
+
* @param {number} sample_rate
|
|
387
|
+
* @param {string} reference_features
|
|
388
|
+
* @param {number} reference_position_millis
|
|
389
|
+
* @param {number | null} [reference_confidence]
|
|
390
|
+
* @returns {any}
|
|
391
|
+
*/
|
|
392
|
+
export function estimatePitchRatioAgainstSpectralFeatures(pcm16_le, sample_rate, reference_features, reference_position_millis, reference_confidence) {
|
|
393
|
+
const ptr0 = passArray8ToWasm0(pcm16_le, wasm.__wbindgen_malloc);
|
|
394
|
+
const len0 = WASM_VECTOR_LEN;
|
|
395
|
+
const ptr1 = passStringToWasm0(reference_features, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
396
|
+
const len1 = WASM_VECTOR_LEN;
|
|
397
|
+
const ret = wasm.estimatePitchRatioAgainstSpectralFeatures(ptr0, len0, sample_rate, ptr1, len1, reference_position_millis, !isLikeNone(reference_confidence), isLikeNone(reference_confidence) ? 0 : reference_confidence);
|
|
398
|
+
if (ret[2]) {
|
|
399
|
+
throw takeFromExternrefTable0(ret[1]);
|
|
400
|
+
}
|
|
401
|
+
return takeFromExternrefTable0(ret[0]);
|
|
402
|
+
}
|
|
403
|
+
|
|
404
|
+
/**
|
|
405
|
+
* @param {Uint8Array} pcm16_le
|
|
406
|
+
* @param {number} sample_rate
|
|
407
|
+
* @returns {any}
|
|
408
|
+
*/
|
|
409
|
+
export function extractPitchReference(pcm16_le, sample_rate) {
|
|
410
|
+
const ptr0 = passArray8ToWasm0(pcm16_le, wasm.__wbindgen_malloc);
|
|
411
|
+
const len0 = WASM_VECTOR_LEN;
|
|
412
|
+
const ret = wasm.extractPitchReference(ptr0, len0, sample_rate);
|
|
413
|
+
if (ret[2]) {
|
|
414
|
+
throw takeFromExternrefTable0(ret[1]);
|
|
415
|
+
}
|
|
416
|
+
return takeFromExternrefTable0(ret[0]);
|
|
417
|
+
}
|
|
418
|
+
|
|
419
|
+
/**
|
|
420
|
+
* @param {Uint8Array} pcm16_le
|
|
421
|
+
* @param {number} sample_rate
|
|
422
|
+
* @returns {any}
|
|
423
|
+
*/
|
|
424
|
+
export function extractSpectralShiftReference(pcm16_le, sample_rate) {
|
|
425
|
+
const ptr0 = passArray8ToWasm0(pcm16_le, wasm.__wbindgen_malloc);
|
|
426
|
+
const len0 = WASM_VECTOR_LEN;
|
|
427
|
+
const ret = wasm.extractSpectralShiftReference(ptr0, len0, sample_rate);
|
|
428
|
+
if (ret[2]) {
|
|
429
|
+
throw takeFromExternrefTable0(ret[1]);
|
|
430
|
+
}
|
|
431
|
+
return takeFromExternrefTable0(ret[0]);
|
|
432
|
+
}
|
|
433
|
+
|
|
213
434
|
export function init_matcher_wasm() {
|
|
214
435
|
wasm.init_matcher_wasm();
|
|
215
436
|
}
|
|
Binary file
|
|
@@ -3,6 +3,13 @@
|
|
|
3
3
|
export const memory: WebAssembly.Memory;
|
|
4
4
|
export const __wbg_wasmmatcherdatabase_free: (a: number, b: number) => void;
|
|
5
5
|
export const __wbg_wasmmatcherengine_free: (a: number, b: number) => void;
|
|
6
|
+
export const detectAudioMarker: (a: number, b: number, c: number, d: number) => [number, number, number];
|
|
7
|
+
export const detectPatternMark: (a: number, b: number, c: number, d: number) => [number, number, number];
|
|
8
|
+
export const estimatePitchRatio: (a: number, b: number, c: number) => [number, number, number];
|
|
9
|
+
export const estimatePitchRatioAgainstReference: (a: number, b: number, c: number, d: number, e: number, f: number) => [number, number, number];
|
|
10
|
+
export const estimatePitchRatioAgainstSpectralFeatures: (a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number) => [number, number, number];
|
|
11
|
+
export const extractPitchReference: (a: number, b: number, c: number) => [number, number, number];
|
|
12
|
+
export const extractSpectralShiftReference: (a: number, b: number, c: number) => [number, number, number];
|
|
6
13
|
export const wasmmatcherdatabase_addEntry: (a: number, b: number, c: number, d: number, e: number, f: number) => [number, number];
|
|
7
14
|
export const wasmmatcherdatabase_addOrReplace: (a: number, b: number, c: number, d: number, e: number, f: number, g: number) => [number, number];
|
|
8
15
|
export const wasmmatcherdatabase_clear: (a: number) => void;
|
|
@@ -15,6 +22,13 @@ export const wasmmatcherdatabase_removeEntry: (a: number, b: number, c: number)
|
|
|
15
22
|
export const wasmmatcherdatabase_setEntryVariantMetadata: (a: number, b: number, c: number, d: number, e: number) => [number, number];
|
|
16
23
|
export const wasmmatcherengine_bestMatch: (a: number, b: number, c: number, d: number, e: number) => [number, number, number];
|
|
17
24
|
export const wasmmatcherengine_bestMatchWithVariants: (a: number, b: number, c: number, d: number, e: any, f: number, g: number) => [number, number, number];
|
|
25
|
+
export const wasmmatcherengine_detectAudioMarker: (a: number, b: number, c: number, d: number, e: number) => [number, number, number];
|
|
26
|
+
export const wasmmatcherengine_detectPatternMark: (a: number, b: number, c: number, d: number, e: number) => [number, number, number];
|
|
27
|
+
export const wasmmatcherengine_estimatePitchRatio: (a: number, b: number, c: number, d: number) => [number, number, number];
|
|
28
|
+
export const wasmmatcherengine_estimatePitchRatioAgainstReference: (a: number, b: number, c: number, d: number, e: number, f: number, g: number) => [number, number, number];
|
|
29
|
+
export const wasmmatcherengine_estimatePitchRatioAgainstSpectralFeatures: (a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number, i: number) => [number, number, number];
|
|
30
|
+
export const wasmmatcherengine_extractPitchReference: (a: number, b: number, c: number, d: number) => [number, number, number];
|
|
31
|
+
export const wasmmatcherengine_extractSpectralShiftReference: (a: number, b: number, c: number, d: number) => [number, number, number];
|
|
18
32
|
export const wasmmatcherengine_matchQuery: (a: number, b: number, c: number, d: number, e: number) => [number, number, number];
|
|
19
33
|
export const wasmmatcherengine_matchQueryWithVariants: (a: number, b: number, c: number, d: number, e: any, f: number, g: number) => [number, number, number];
|
|
20
34
|
export const wasmmatcherengine_new: () => number;
|
package/dist/index.d.ts
CHANGED
|
@@ -7,11 +7,62 @@ interface MatchConfig {
|
|
|
7
7
|
maxResults?: number;
|
|
8
8
|
scoreThreshold?: number;
|
|
9
9
|
gapThreshold?: number;
|
|
10
|
+
audiomarker?: boolean;
|
|
11
|
+
}
|
|
12
|
+
interface AudioMarkerCode {
|
|
13
|
+
code: string;
|
|
14
|
+
pattern: string;
|
|
15
|
+
}
|
|
16
|
+
interface AudioMarkerConfig {
|
|
17
|
+
bandLowHz?: number;
|
|
18
|
+
bandHighHz?: number;
|
|
19
|
+
syncDurationMillis?: number;
|
|
20
|
+
codeDurationMillis?: number;
|
|
21
|
+
frameIntervalMillis?: number;
|
|
22
|
+
syncSearchStepMillis?: number;
|
|
23
|
+
minSyncScore?: number;
|
|
24
|
+
minScore?: number;
|
|
25
|
+
minMargin?: number;
|
|
26
|
+
minRatio?: number;
|
|
27
|
+
minConfidence?: number;
|
|
28
|
+
minVotes?: number;
|
|
29
|
+
maxSyncCandidates?: number;
|
|
30
|
+
codebook?: AudioMarkerCode[];
|
|
31
|
+
}
|
|
32
|
+
interface AudioMarkerDetection {
|
|
33
|
+
pattern?: string | null;
|
|
34
|
+
code?: string | null;
|
|
35
|
+
confidence?: number | null;
|
|
36
|
+
score: number;
|
|
37
|
+
margin: number;
|
|
38
|
+
accuracy: number;
|
|
39
|
+
bandLowHz: number;
|
|
40
|
+
bandHighHz: number;
|
|
41
|
+
syncScore: number;
|
|
42
|
+
chipCount: number;
|
|
43
|
+
frameStartSample: number;
|
|
44
|
+
frameCount: number;
|
|
45
|
+
voteCount: number;
|
|
46
|
+
reason?: string | null;
|
|
47
|
+
candidatePattern?: string | null;
|
|
48
|
+
candidateCode?: string | null;
|
|
49
|
+
candidateConfidence?: number | null;
|
|
50
|
+
runnerUpPattern?: string | null;
|
|
51
|
+
runnerUpCode?: string | null;
|
|
52
|
+
runnerUpScore?: number | null;
|
|
53
|
+
runnerUpAccuracy?: number | null;
|
|
10
54
|
}
|
|
11
55
|
interface VariantMatchQuery {
|
|
12
56
|
estimatedPitchRatio?: number | null;
|
|
13
57
|
pitchConfidence?: number | null;
|
|
14
58
|
}
|
|
59
|
+
/** Query-side estimate produced from mono PCM16 little-endian audio. */
|
|
60
|
+
type PitchRatioEstimate = VariantMatchQuery;
|
|
61
|
+
interface PitchReferenceEstimate {
|
|
62
|
+
pitchHz?: number | null;
|
|
63
|
+
pitchConfidence?: number | null;
|
|
64
|
+
features?: string | null;
|
|
65
|
+
}
|
|
15
66
|
interface VariantMatchConfig {
|
|
16
67
|
minConfidence?: number;
|
|
17
68
|
defaultToleranceRatio?: number;
|
|
@@ -47,6 +98,7 @@ interface MatchResult {
|
|
|
47
98
|
name: string;
|
|
48
99
|
score: number;
|
|
49
100
|
position: number;
|
|
101
|
+
durationMillis?: number;
|
|
50
102
|
afpType: AudioFingerprintType;
|
|
51
103
|
}
|
|
52
104
|
interface VariantMatch {
|
|
@@ -171,6 +223,11 @@ declare class MatcherSession {
|
|
|
171
223
|
getEntryMetadata(name: string): Promise<EntryMetadata | null>;
|
|
172
224
|
match(query: Uint8Array, config?: MatchConfig): Promise<MatchResult[]>;
|
|
173
225
|
bestMatch(query: Uint8Array, config?: MatchConfig): Promise<MatchResult | null>;
|
|
226
|
+
estimatePitchRatio(pcm16Le: Uint8Array, sampleRate: number): Promise<PitchRatioEstimate>;
|
|
227
|
+
extractPitchReference(pcm16Le: Uint8Array, sampleRate: number): Promise<PitchReferenceEstimate>;
|
|
228
|
+
estimatePitchRatioAgainstReference(pcm16Le: Uint8Array, sampleRate: number, referencePitchHz: number, referenceConfidence?: number | null): Promise<PitchRatioEstimate>;
|
|
229
|
+
estimatePitchRatioAgainstReferenceFeatures(pcm16Le: Uint8Array, sampleRate: number, referenceFeatures: string, referencePositionMillis: number, referenceConfidence?: number | null): Promise<PitchRatioEstimate>;
|
|
230
|
+
detectAudioMarker(pcm16Le: Uint8Array, sampleRate: number, config?: AudioMarkerConfig): Promise<AudioMarkerDetection>;
|
|
174
231
|
matchWithVariants(query: Uint8Array, pitchQuery: VariantMatchQuery, config?: MatchConfig, variantConfig?: VariantMatchConfig): Promise<VariantMatch[]>;
|
|
175
232
|
bestMatchWithVariants(query: Uint8Array, pitchQuery: VariantMatchQuery, config?: MatchConfig, variantConfig?: VariantMatchConfig): Promise<VariantMatch | null>;
|
|
176
233
|
destroy(): void;
|
|
@@ -185,4 +242,4 @@ declare function __setMatcherWasmModuleForTests(moduleLike: unknown): void;
|
|
|
185
242
|
declare function __setMatcherEmbeddedPackForTests(bytes: Uint8Array): void;
|
|
186
243
|
declare function __resetMatcherWasmForTests(): void;
|
|
187
244
|
|
|
188
|
-
export { AudioFingerprintType, type EntryMetadata, type InitMatcherOptions, type InitMatcherResult, type MatchConfig, type MatchResult, type MatcherEphemeralAuthOptions, type MatcherEphemeralAuthResult, type MatcherEphemeralKeyExchangeMetadata, type MatcherEphemeralKeyExchangeOptions, MatcherSession, type MatcherSessionEventMap, type MatcherSessionEventName, type MatcherSessionListener, type MatcherSessionOptions, type PackSource, type VariantDecision, type VariantDecisionStatus, type VariantMatch, type VariantMatchConfig, type VariantMatchQuery, __resetMatcherWasmForTests, __setMatcherEmbeddedPackForTests, __setMatcherWasmModuleForTests, initMatcher };
|
|
245
|
+
export { AudioFingerprintType, type AudioMarkerCode, type AudioMarkerConfig, type AudioMarkerDetection, type EntryMetadata, type InitMatcherOptions, type InitMatcherResult, type MatchConfig, type MatchResult, type MatcherEphemeralAuthOptions, type MatcherEphemeralAuthResult, type MatcherEphemeralKeyExchangeMetadata, type MatcherEphemeralKeyExchangeOptions, MatcherSession, type MatcherSessionEventMap, type MatcherSessionEventName, type MatcherSessionListener, type MatcherSessionOptions, type PackSource, type PitchRatioEstimate, type PitchReferenceEstimate, type VariantDecision, type VariantDecisionStatus, type VariantMatch, type VariantMatchConfig, type VariantMatchQuery, __resetMatcherWasmForTests, __setMatcherEmbeddedPackForTests, __setMatcherWasmModuleForTests, initMatcher };
|
package/dist/index.js
CHANGED
|
@@ -375,7 +375,70 @@ var WrappedDatabase = class {
|
|
|
375
375
|
var WrappedMatcher = class {
|
|
376
376
|
constructor(inner) {
|
|
377
377
|
this.inner = inner;
|
|
378
|
+
const estimatePitchRatioFn = getCallable(this.inner, [
|
|
379
|
+
"estimatePitchRatio",
|
|
380
|
+
"estimate_pitch_ratio"
|
|
381
|
+
]);
|
|
382
|
+
if (estimatePitchRatioFn) {
|
|
383
|
+
this.estimatePitchRatio = (pcm16Le, sampleRate) => normalizePitchRatioEstimate(estimatePitchRatioFn.call(this.inner, pcm16Le, sampleRate));
|
|
384
|
+
}
|
|
385
|
+
const extractPitchReferenceFn = getCallable(this.inner, [
|
|
386
|
+
"extractPitchReference",
|
|
387
|
+
"extract_pitch_reference"
|
|
388
|
+
]);
|
|
389
|
+
if (extractPitchReferenceFn) {
|
|
390
|
+
this.extractPitchReference = (pcm16Le, sampleRate) => normalizePitchReferenceEstimate(
|
|
391
|
+
extractPitchReferenceFn.call(this.inner, pcm16Le, sampleRate)
|
|
392
|
+
);
|
|
393
|
+
}
|
|
394
|
+
const estimateAgainstReferenceFn = getCallable(this.inner, [
|
|
395
|
+
"estimatePitchRatioAgainstReference",
|
|
396
|
+
"estimate_pitch_ratio_against_reference"
|
|
397
|
+
]);
|
|
398
|
+
if (estimateAgainstReferenceFn) {
|
|
399
|
+
this.estimatePitchRatioAgainstReference = (pcm16Le, sampleRate, referencePitchHz, referenceConfidence) => normalizePitchRatioEstimate(
|
|
400
|
+
estimateAgainstReferenceFn.call(
|
|
401
|
+
this.inner,
|
|
402
|
+
pcm16Le,
|
|
403
|
+
sampleRate,
|
|
404
|
+
referencePitchHz,
|
|
405
|
+
referenceConfidence
|
|
406
|
+
)
|
|
407
|
+
);
|
|
408
|
+
}
|
|
409
|
+
const estimateAgainstReferenceFeaturesFn = getCallable(this.inner, [
|
|
410
|
+
"estimatePitchRatioAgainstReferenceFeatures",
|
|
411
|
+
"estimate_pitch_ratio_against_reference_features"
|
|
412
|
+
]);
|
|
413
|
+
if (estimateAgainstReferenceFeaturesFn) {
|
|
414
|
+
this.estimatePitchRatioAgainstReferenceFeatures = (pcm16Le, sampleRate, referenceFeatures, referencePositionMillis, referenceConfidence) => normalizePitchRatioEstimate(
|
|
415
|
+
estimateAgainstReferenceFeaturesFn.call(
|
|
416
|
+
this.inner,
|
|
417
|
+
pcm16Le,
|
|
418
|
+
sampleRate,
|
|
419
|
+
referenceFeatures,
|
|
420
|
+
referencePositionMillis,
|
|
421
|
+
referenceConfidence
|
|
422
|
+
)
|
|
423
|
+
);
|
|
424
|
+
}
|
|
425
|
+
const detectAudioMarkerFn = getCallable(this.inner, [
|
|
426
|
+
"detectAudioMarker",
|
|
427
|
+
"detect_audio_marker",
|
|
428
|
+
"detectPatternMark",
|
|
429
|
+
"detect_pattern_mark"
|
|
430
|
+
]);
|
|
431
|
+
if (detectAudioMarkerFn) {
|
|
432
|
+
this.detectAudioMarker = (pcm16Le, sampleRate, config) => normalizeAudioMarkerDetection(
|
|
433
|
+
detectAudioMarkerFn.call(this.inner, pcm16Le, sampleRate, config)
|
|
434
|
+
);
|
|
435
|
+
}
|
|
378
436
|
}
|
|
437
|
+
estimatePitchRatio;
|
|
438
|
+
extractPitchReference;
|
|
439
|
+
estimatePitchRatioAgainstReference;
|
|
440
|
+
estimatePitchRatioAgainstReferenceFeatures;
|
|
441
|
+
detectAudioMarker;
|
|
379
442
|
findMatches(database, query, config) {
|
|
380
443
|
const fn = getCallable(this.inner, ["findMatches", "find_matches", "matchQuery", "match_query", "match"]);
|
|
381
444
|
if (!fn) {
|
|
@@ -448,12 +511,17 @@ var WrappedMatcher = class {
|
|
|
448
511
|
};
|
|
449
512
|
function normalizeResult(raw) {
|
|
450
513
|
const afpType = Number(raw.afpType ?? raw.afp_type);
|
|
451
|
-
|
|
514
|
+
const durationMillis = raw.durationMillis ?? raw.duration_millis;
|
|
515
|
+
const result = {
|
|
452
516
|
name: String(raw.name),
|
|
453
517
|
score: Number(raw.score),
|
|
454
518
|
position: Number(raw.position),
|
|
455
519
|
afpType
|
|
456
520
|
};
|
|
521
|
+
if (durationMillis != null) {
|
|
522
|
+
result.durationMillis = Number(durationMillis);
|
|
523
|
+
}
|
|
524
|
+
return result;
|
|
457
525
|
}
|
|
458
526
|
function normalizeVariantMatch(raw) {
|
|
459
527
|
const rawMatch = raw.matchResult ?? raw.match;
|
|
@@ -467,6 +535,64 @@ function normalizeVariantMatch(raw) {
|
|
|
467
535
|
}
|
|
468
536
|
};
|
|
469
537
|
}
|
|
538
|
+
function normalizeOptionalNumber(camelValue, snakeValue) {
|
|
539
|
+
const value = camelValue ?? snakeValue;
|
|
540
|
+
return value == null ? null : Number(value);
|
|
541
|
+
}
|
|
542
|
+
function normalizePitchRatioEstimate(raw) {
|
|
543
|
+
const record = raw && typeof raw === "object" ? raw : {};
|
|
544
|
+
return {
|
|
545
|
+
estimatedPitchRatio: normalizeOptionalNumber(
|
|
546
|
+
record.estimatedPitchRatio,
|
|
547
|
+
record.estimated_pitch_ratio
|
|
548
|
+
),
|
|
549
|
+
pitchConfidence: normalizeOptionalNumber(record.pitchConfidence, record.pitch_confidence)
|
|
550
|
+
};
|
|
551
|
+
}
|
|
552
|
+
function normalizeOptionalString(value) {
|
|
553
|
+
return value == null ? null : String(value);
|
|
554
|
+
}
|
|
555
|
+
function normalizePitchReferenceEstimate(raw) {
|
|
556
|
+
const record = raw && typeof raw === "object" ? raw : {};
|
|
557
|
+
return {
|
|
558
|
+
pitchHz: normalizeOptionalNumber(record.pitchHz, record.pitch_hz),
|
|
559
|
+
pitchConfidence: normalizeOptionalNumber(record.pitchConfidence, record.pitch_confidence),
|
|
560
|
+
features: normalizeOptionalString(record.features)
|
|
561
|
+
};
|
|
562
|
+
}
|
|
563
|
+
function normalizeNumber(camelValue, snakeValue, fallback = 0) {
|
|
564
|
+
const value = camelValue ?? snakeValue;
|
|
565
|
+
return value == null ? fallback : Number(value);
|
|
566
|
+
}
|
|
567
|
+
function normalizeAudioMarkerDetection(raw) {
|
|
568
|
+
const record = raw && typeof raw === "object" ? raw : {};
|
|
569
|
+
return {
|
|
570
|
+
pattern: normalizeOptionalString(record.pattern),
|
|
571
|
+
code: normalizeOptionalString(record.code),
|
|
572
|
+
confidence: normalizeOptionalNumber(record.confidence, void 0),
|
|
573
|
+
score: normalizeNumber(record.score, void 0),
|
|
574
|
+
margin: normalizeNumber(record.margin, void 0),
|
|
575
|
+
accuracy: normalizeNumber(record.accuracy, void 0),
|
|
576
|
+
bandLowHz: normalizeNumber(record.bandLowHz, record.band_low_hz),
|
|
577
|
+
bandHighHz: normalizeNumber(record.bandHighHz, record.band_high_hz),
|
|
578
|
+
syncScore: normalizeNumber(record.syncScore, record.sync_score),
|
|
579
|
+
chipCount: normalizeNumber(record.chipCount, record.chip_count),
|
|
580
|
+
frameStartSample: normalizeNumber(record.frameStartSample, record.frame_start_sample),
|
|
581
|
+
frameCount: normalizeNumber(record.frameCount, record.frame_count),
|
|
582
|
+
voteCount: normalizeNumber(record.voteCount, record.vote_count),
|
|
583
|
+
reason: normalizeOptionalString(record.reason),
|
|
584
|
+
candidatePattern: normalizeOptionalString(record.candidatePattern ?? record.candidate_pattern),
|
|
585
|
+
candidateCode: normalizeOptionalString(record.candidateCode ?? record.candidate_code),
|
|
586
|
+
candidateConfidence: normalizeOptionalNumber(
|
|
587
|
+
record.candidateConfidence,
|
|
588
|
+
record.candidate_confidence
|
|
589
|
+
),
|
|
590
|
+
runnerUpPattern: normalizeOptionalString(record.runnerUpPattern ?? record.runner_up_pattern),
|
|
591
|
+
runnerUpCode: normalizeOptionalString(record.runnerUpCode ?? record.runner_up_code),
|
|
592
|
+
runnerUpScore: normalizeOptionalNumber(record.runnerUpScore, record.runner_up_score),
|
|
593
|
+
runnerUpAccuracy: normalizeOptionalNumber(record.runnerUpAccuracy, record.runner_up_accuracy)
|
|
594
|
+
};
|
|
595
|
+
}
|
|
470
596
|
function isMapLike(raw) {
|
|
471
597
|
return raw instanceof Map || Object.prototype.toString.call(raw) === "[object Map]" && typeof raw.entries === "function";
|
|
472
598
|
}
|
|
@@ -526,6 +652,25 @@ function createBindingsFromModule(moduleLike) {
|
|
|
526
652
|
const initFn = getCallable(mod, ["initMatcher"]) ?? (typeof mod.default === "function" ? mod.default.bind(mod) : null);
|
|
527
653
|
const createDatabaseFactory = resolveFactory(mod, ["createDatabase"]);
|
|
528
654
|
const createMatcherFactory = resolveFactory(mod, ["createMatcher"]);
|
|
655
|
+
const estimatePitchRatioFn = resolveFactory(mod, ["estimatePitchRatio", "estimate_pitch_ratio"]);
|
|
656
|
+
const extractPitchReferenceFn = resolveFactory(mod, [
|
|
657
|
+
"extractPitchReference",
|
|
658
|
+
"extract_pitch_reference"
|
|
659
|
+
]);
|
|
660
|
+
const estimatePitchRatioAgainstReferenceFn = resolveFactory(mod, [
|
|
661
|
+
"estimatePitchRatioAgainstReference",
|
|
662
|
+
"estimate_pitch_ratio_against_reference"
|
|
663
|
+
]);
|
|
664
|
+
const estimatePitchRatioAgainstReferenceFeaturesFn = resolveFactory(mod, [
|
|
665
|
+
"estimatePitchRatioAgainstReferenceFeatures",
|
|
666
|
+
"estimate_pitch_ratio_against_reference_features"
|
|
667
|
+
]);
|
|
668
|
+
const detectAudioMarkerFn = resolveFactory(mod, [
|
|
669
|
+
"detectAudioMarker",
|
|
670
|
+
"detect_audio_marker",
|
|
671
|
+
"detectPatternMark",
|
|
672
|
+
"detect_pattern_mark"
|
|
673
|
+
]);
|
|
529
674
|
const DatabaseCtor = mod.WasmMatcherDatabase ?? mod.MatcherDatabase ?? mod.Database;
|
|
530
675
|
const MatcherCtor = mod.WasmMatcherEngine ?? mod.MatcherEngine ?? mod.Matcher ?? mod.AudioMatcher;
|
|
531
676
|
if (!createDatabaseFactory && !DatabaseCtor) {
|
|
@@ -547,6 +692,116 @@ function createBindingsFromModule(moduleLike) {
|
|
|
547
692
|
createMatcher() {
|
|
548
693
|
const matcher = createMatcherFactory ? createMatcherFactory() : new MatcherCtor();
|
|
549
694
|
return new WrappedMatcher(matcher);
|
|
695
|
+
},
|
|
696
|
+
estimatePitchRatio(pcm16Le, sampleRate) {
|
|
697
|
+
if (estimatePitchRatioFn) {
|
|
698
|
+
return normalizePitchRatioEstimate(estimatePitchRatioFn(pcm16Le, sampleRate));
|
|
699
|
+
}
|
|
700
|
+
const matcher = createMatcherFactory ? createMatcherFactory() : new MatcherCtor();
|
|
701
|
+
try {
|
|
702
|
+
const wrapped = new WrappedMatcher(matcher);
|
|
703
|
+
if (!wrapped.estimatePitchRatio) {
|
|
704
|
+
throw new Error("WASM matcher is missing estimatePitchRatio-compatible method");
|
|
705
|
+
}
|
|
706
|
+
return wrapped.estimatePitchRatio(pcm16Le, sampleRate);
|
|
707
|
+
} finally {
|
|
708
|
+
const destroy = getCallable(matcher, ["destroy", "free"]);
|
|
709
|
+
destroy?.call(matcher);
|
|
710
|
+
}
|
|
711
|
+
},
|
|
712
|
+
extractPitchReference(pcm16Le, sampleRate) {
|
|
713
|
+
if (extractPitchReferenceFn) {
|
|
714
|
+
return normalizePitchReferenceEstimate(extractPitchReferenceFn(pcm16Le, sampleRate));
|
|
715
|
+
}
|
|
716
|
+
const matcher = createMatcherFactory ? createMatcherFactory() : new MatcherCtor();
|
|
717
|
+
try {
|
|
718
|
+
const wrapped = new WrappedMatcher(matcher);
|
|
719
|
+
if (!wrapped.extractPitchReference) {
|
|
720
|
+
throw new Error("WASM matcher is missing extractPitchReference-compatible method");
|
|
721
|
+
}
|
|
722
|
+
return wrapped.extractPitchReference(pcm16Le, sampleRate);
|
|
723
|
+
} finally {
|
|
724
|
+
const destroy = getCallable(matcher, ["destroy", "free"]);
|
|
725
|
+
destroy?.call(matcher);
|
|
726
|
+
}
|
|
727
|
+
},
|
|
728
|
+
estimatePitchRatioAgainstReference(pcm16Le, sampleRate, referencePitchHz, referenceConfidence) {
|
|
729
|
+
if (estimatePitchRatioAgainstReferenceFn) {
|
|
730
|
+
return normalizePitchRatioEstimate(
|
|
731
|
+
estimatePitchRatioAgainstReferenceFn(
|
|
732
|
+
pcm16Le,
|
|
733
|
+
sampleRate,
|
|
734
|
+
referencePitchHz,
|
|
735
|
+
referenceConfidence
|
|
736
|
+
)
|
|
737
|
+
);
|
|
738
|
+
}
|
|
739
|
+
const matcher = createMatcherFactory ? createMatcherFactory() : new MatcherCtor();
|
|
740
|
+
try {
|
|
741
|
+
const wrapped = new WrappedMatcher(matcher);
|
|
742
|
+
if (!wrapped.estimatePitchRatioAgainstReference) {
|
|
743
|
+
throw new Error(
|
|
744
|
+
"WASM matcher is missing estimatePitchRatioAgainstReference-compatible method"
|
|
745
|
+
);
|
|
746
|
+
}
|
|
747
|
+
return wrapped.estimatePitchRatioAgainstReference(
|
|
748
|
+
pcm16Le,
|
|
749
|
+
sampleRate,
|
|
750
|
+
referencePitchHz,
|
|
751
|
+
referenceConfidence
|
|
752
|
+
);
|
|
753
|
+
} finally {
|
|
754
|
+
const destroy = getCallable(matcher, ["destroy", "free"]);
|
|
755
|
+
destroy?.call(matcher);
|
|
756
|
+
}
|
|
757
|
+
},
|
|
758
|
+
estimatePitchRatioAgainstReferenceFeatures(pcm16Le, sampleRate, referenceFeatures, referencePositionMillis, referenceConfidence) {
|
|
759
|
+
if (estimatePitchRatioAgainstReferenceFeaturesFn) {
|
|
760
|
+
return normalizePitchRatioEstimate(
|
|
761
|
+
estimatePitchRatioAgainstReferenceFeaturesFn(
|
|
762
|
+
pcm16Le,
|
|
763
|
+
sampleRate,
|
|
764
|
+
referenceFeatures,
|
|
765
|
+
referencePositionMillis,
|
|
766
|
+
referenceConfidence
|
|
767
|
+
)
|
|
768
|
+
);
|
|
769
|
+
}
|
|
770
|
+
const matcher = createMatcherFactory ? createMatcherFactory() : new MatcherCtor();
|
|
771
|
+
try {
|
|
772
|
+
const wrapped = new WrappedMatcher(matcher);
|
|
773
|
+
if (!wrapped.estimatePitchRatioAgainstReferenceFeatures) {
|
|
774
|
+
throw new Error(
|
|
775
|
+
"WASM matcher is missing estimatePitchRatioAgainstReferenceFeatures-compatible method"
|
|
776
|
+
);
|
|
777
|
+
}
|
|
778
|
+
return wrapped.estimatePitchRatioAgainstReferenceFeatures(
|
|
779
|
+
pcm16Le,
|
|
780
|
+
sampleRate,
|
|
781
|
+
referenceFeatures,
|
|
782
|
+
referencePositionMillis,
|
|
783
|
+
referenceConfidence
|
|
784
|
+
);
|
|
785
|
+
} finally {
|
|
786
|
+
const destroy = getCallable(matcher, ["destroy", "free"]);
|
|
787
|
+
destroy?.call(matcher);
|
|
788
|
+
}
|
|
789
|
+
},
|
|
790
|
+
detectAudioMarker(pcm16Le, sampleRate, config) {
|
|
791
|
+
if (detectAudioMarkerFn) {
|
|
792
|
+
return normalizeAudioMarkerDetection(detectAudioMarkerFn(pcm16Le, sampleRate, config));
|
|
793
|
+
}
|
|
794
|
+
const matcher = createMatcherFactory ? createMatcherFactory() : new MatcherCtor();
|
|
795
|
+
try {
|
|
796
|
+
const wrapped = new WrappedMatcher(matcher);
|
|
797
|
+
if (!wrapped.detectAudioMarker) {
|
|
798
|
+
throw new Error("WASM matcher is missing detectAudioMarker-compatible method");
|
|
799
|
+
}
|
|
800
|
+
return wrapped.detectAudioMarker(pcm16Le, sampleRate, config);
|
|
801
|
+
} finally {
|
|
802
|
+
const destroy = getCallable(matcher, ["destroy", "free"]);
|
|
803
|
+
destroy?.call(matcher);
|
|
804
|
+
}
|
|
550
805
|
}
|
|
551
806
|
};
|
|
552
807
|
}
|
|
@@ -731,6 +986,108 @@ var MatcherSession = class {
|
|
|
731
986
|
handleError(this.events, "bestMatch", error);
|
|
732
987
|
}
|
|
733
988
|
}
|
|
989
|
+
async estimatePitchRatio(pcm16Le, sampleRate) {
|
|
990
|
+
try {
|
|
991
|
+
await this.ensureLiveReady();
|
|
992
|
+
const safePcm = toUint8ArrayCopy(pcm16Le);
|
|
993
|
+
const matcher = this.matcherOrThrow();
|
|
994
|
+
if (matcher.estimatePitchRatio) {
|
|
995
|
+
return matcher.estimatePitchRatio(safePcm, sampleRate);
|
|
996
|
+
}
|
|
997
|
+
if (!this.bindings) {
|
|
998
|
+
throw new Error("Matcher bindings are not initialized");
|
|
999
|
+
}
|
|
1000
|
+
return this.bindings.estimatePitchRatio(safePcm, sampleRate);
|
|
1001
|
+
} catch (error) {
|
|
1002
|
+
handleError(this.events, "estimatePitchRatio", error);
|
|
1003
|
+
}
|
|
1004
|
+
}
|
|
1005
|
+
async extractPitchReference(pcm16Le, sampleRate) {
|
|
1006
|
+
try {
|
|
1007
|
+
await this.ensureLiveReady();
|
|
1008
|
+
const safePcm = toUint8ArrayCopy(pcm16Le);
|
|
1009
|
+
const matcher = this.matcherOrThrow();
|
|
1010
|
+
if (matcher.extractPitchReference) {
|
|
1011
|
+
return matcher.extractPitchReference(safePcm, sampleRate);
|
|
1012
|
+
}
|
|
1013
|
+
if (!this.bindings) {
|
|
1014
|
+
throw new Error("Matcher bindings are not initialized");
|
|
1015
|
+
}
|
|
1016
|
+
return this.bindings.extractPitchReference(safePcm, sampleRate);
|
|
1017
|
+
} catch (error) {
|
|
1018
|
+
handleError(this.events, "extractPitchReference", error);
|
|
1019
|
+
}
|
|
1020
|
+
}
|
|
1021
|
+
async estimatePitchRatioAgainstReference(pcm16Le, sampleRate, referencePitchHz, referenceConfidence) {
|
|
1022
|
+
try {
|
|
1023
|
+
await this.ensureLiveReady();
|
|
1024
|
+
const safePcm = toUint8ArrayCopy(pcm16Le);
|
|
1025
|
+
const matcher = this.matcherOrThrow();
|
|
1026
|
+
if (matcher.estimatePitchRatioAgainstReference) {
|
|
1027
|
+
return matcher.estimatePitchRatioAgainstReference(
|
|
1028
|
+
safePcm,
|
|
1029
|
+
sampleRate,
|
|
1030
|
+
referencePitchHz,
|
|
1031
|
+
referenceConfidence
|
|
1032
|
+
);
|
|
1033
|
+
}
|
|
1034
|
+
if (!this.bindings) {
|
|
1035
|
+
throw new Error("Matcher bindings are not initialized");
|
|
1036
|
+
}
|
|
1037
|
+
return this.bindings.estimatePitchRatioAgainstReference(
|
|
1038
|
+
safePcm,
|
|
1039
|
+
sampleRate,
|
|
1040
|
+
referencePitchHz,
|
|
1041
|
+
referenceConfidence
|
|
1042
|
+
);
|
|
1043
|
+
} catch (error) {
|
|
1044
|
+
handleError(this.events, "estimatePitchRatioAgainstReference", error);
|
|
1045
|
+
}
|
|
1046
|
+
}
|
|
1047
|
+
async estimatePitchRatioAgainstReferenceFeatures(pcm16Le, sampleRate, referenceFeatures, referencePositionMillis, referenceConfidence) {
|
|
1048
|
+
try {
|
|
1049
|
+
await this.ensureLiveReady();
|
|
1050
|
+
const safePcm = toUint8ArrayCopy(pcm16Le);
|
|
1051
|
+
const matcher = this.matcherOrThrow();
|
|
1052
|
+
if (matcher.estimatePitchRatioAgainstReferenceFeatures) {
|
|
1053
|
+
return matcher.estimatePitchRatioAgainstReferenceFeatures(
|
|
1054
|
+
safePcm,
|
|
1055
|
+
sampleRate,
|
|
1056
|
+
referenceFeatures,
|
|
1057
|
+
referencePositionMillis,
|
|
1058
|
+
referenceConfidence
|
|
1059
|
+
);
|
|
1060
|
+
}
|
|
1061
|
+
if (!this.bindings) {
|
|
1062
|
+
throw new Error("Matcher bindings are not initialized");
|
|
1063
|
+
}
|
|
1064
|
+
return this.bindings.estimatePitchRatioAgainstReferenceFeatures(
|
|
1065
|
+
safePcm,
|
|
1066
|
+
sampleRate,
|
|
1067
|
+
referenceFeatures,
|
|
1068
|
+
referencePositionMillis,
|
|
1069
|
+
referenceConfidence
|
|
1070
|
+
);
|
|
1071
|
+
} catch (error) {
|
|
1072
|
+
handleError(this.events, "estimatePitchRatioAgainstReferenceFeatures", error);
|
|
1073
|
+
}
|
|
1074
|
+
}
|
|
1075
|
+
async detectAudioMarker(pcm16Le, sampleRate, config) {
|
|
1076
|
+
try {
|
|
1077
|
+
await this.ensureLiveReady();
|
|
1078
|
+
const safePcm = toUint8ArrayCopy(pcm16Le);
|
|
1079
|
+
const matcher = this.matcherOrThrow();
|
|
1080
|
+
if (matcher.detectAudioMarker) {
|
|
1081
|
+
return matcher.detectAudioMarker(safePcm, sampleRate, config);
|
|
1082
|
+
}
|
|
1083
|
+
if (!this.bindings) {
|
|
1084
|
+
throw new Error("Matcher bindings are not initialized");
|
|
1085
|
+
}
|
|
1086
|
+
return this.bindings.detectAudioMarker(safePcm, sampleRate, config);
|
|
1087
|
+
} catch (error) {
|
|
1088
|
+
handleError(this.events, "detectAudioMarker", error);
|
|
1089
|
+
}
|
|
1090
|
+
}
|
|
734
1091
|
async matchWithVariants(query, pitchQuery, config, variantConfig) {
|
|
735
1092
|
try {
|
|
736
1093
|
await this.ensureLiveReady();
|