@sorisdk/matcher 0.1.5 → 0.5.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/dist/generated/core.d.ts +24 -0
- package/dist/generated/core.js +1 -1
- package/dist/generated/core_bg.js +271 -0
- package/dist/generated/core_bg.wasm +0 -0
- package/dist/generated/core_bg.wasm.d.ts +17 -0
- package/dist/index.d.ts +91 -1
- package/dist/index.js +453 -0
- package/package.json +1 -1
package/dist/generated/core.d.ts
CHANGED
|
@@ -12,6 +12,7 @@ export class WasmMatcherDatabase {
|
|
|
12
12
|
loadPackBytesAppend(bytes: Uint8Array): void;
|
|
13
13
|
constructor();
|
|
14
14
|
removeEntry(name: string): void;
|
|
15
|
+
setEntryVariantMetadata(name: string, encoded_metadata: string): void;
|
|
15
16
|
readonly length: number;
|
|
16
17
|
}
|
|
17
18
|
|
|
@@ -19,9 +20,32 @@ export class WasmMatcherEngine {
|
|
|
19
20
|
free(): void;
|
|
20
21
|
[Symbol.dispose](): void;
|
|
21
22
|
bestMatch(database: WasmMatcherDatabase, query: Uint8Array, config?: any | null): any;
|
|
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;
|
|
22
31
|
matchQuery(database: WasmMatcherDatabase, query: Uint8Array, config?: any | null): any;
|
|
32
|
+
matchQueryWithVariants(database: WasmMatcherDatabase, query: Uint8Array, pitch_query: any, config?: any | null, variant_config?: any | null): any;
|
|
23
33
|
constructor();
|
|
24
34
|
resetDistinctMatchState(): void;
|
|
25
35
|
}
|
|
26
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
|
+
|
|
27
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";
|
|
@@ -102,6 +102,20 @@ export class WasmMatcherDatabase {
|
|
|
102
102
|
throw takeFromExternrefTable0(ret[0]);
|
|
103
103
|
}
|
|
104
104
|
}
|
|
105
|
+
/**
|
|
106
|
+
* @param {string} name
|
|
107
|
+
* @param {string} encoded_metadata
|
|
108
|
+
*/
|
|
109
|
+
setEntryVariantMetadata(name, encoded_metadata) {
|
|
110
|
+
const ptr0 = passStringToWasm0(name, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
111
|
+
const len0 = WASM_VECTOR_LEN;
|
|
112
|
+
const ptr1 = passStringToWasm0(encoded_metadata, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
113
|
+
const len1 = WASM_VECTOR_LEN;
|
|
114
|
+
const ret = wasm.wasmmatcherdatabase_setEntryVariantMetadata(this.__wbg_ptr, ptr0, len0, ptr1, len1);
|
|
115
|
+
if (ret[1]) {
|
|
116
|
+
throw takeFromExternrefTable0(ret[0]);
|
|
117
|
+
}
|
|
118
|
+
}
|
|
105
119
|
}
|
|
106
120
|
if (Symbol.dispose) WasmMatcherDatabase.prototype[Symbol.dispose] = WasmMatcherDatabase.prototype.free;
|
|
107
121
|
|
|
@@ -132,6 +146,131 @@ export class WasmMatcherEngine {
|
|
|
132
146
|
}
|
|
133
147
|
return takeFromExternrefTable0(ret[0]);
|
|
134
148
|
}
|
|
149
|
+
/**
|
|
150
|
+
* @param {WasmMatcherDatabase} database
|
|
151
|
+
* @param {Uint8Array} query
|
|
152
|
+
* @param {any} pitch_query
|
|
153
|
+
* @param {any | null} [config]
|
|
154
|
+
* @param {any | null} [variant_config]
|
|
155
|
+
* @returns {any}
|
|
156
|
+
*/
|
|
157
|
+
bestMatchWithVariants(database, query, pitch_query, config, variant_config) {
|
|
158
|
+
_assertClass(database, WasmMatcherDatabase);
|
|
159
|
+
const ptr0 = passArray8ToWasm0(query, wasm.__wbindgen_malloc);
|
|
160
|
+
const len0 = WASM_VECTOR_LEN;
|
|
161
|
+
const ret = wasm.wasmmatcherengine_bestMatchWithVariants(this.__wbg_ptr, database.__wbg_ptr, ptr0, len0, pitch_query, isLikeNone(config) ? 0 : addToExternrefTable0(config), isLikeNone(variant_config) ? 0 : addToExternrefTable0(variant_config));
|
|
162
|
+
if (ret[2]) {
|
|
163
|
+
throw takeFromExternrefTable0(ret[1]);
|
|
164
|
+
}
|
|
165
|
+
return takeFromExternrefTable0(ret[0]);
|
|
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
|
+
}
|
|
135
274
|
/**
|
|
136
275
|
* @param {WasmMatcherDatabase} database
|
|
137
276
|
* @param {Uint8Array} query
|
|
@@ -148,6 +287,24 @@ export class WasmMatcherEngine {
|
|
|
148
287
|
}
|
|
149
288
|
return takeFromExternrefTable0(ret[0]);
|
|
150
289
|
}
|
|
290
|
+
/**
|
|
291
|
+
* @param {WasmMatcherDatabase} database
|
|
292
|
+
* @param {Uint8Array} query
|
|
293
|
+
* @param {any} pitch_query
|
|
294
|
+
* @param {any | null} [config]
|
|
295
|
+
* @param {any | null} [variant_config]
|
|
296
|
+
* @returns {any}
|
|
297
|
+
*/
|
|
298
|
+
matchQueryWithVariants(database, query, pitch_query, config, variant_config) {
|
|
299
|
+
_assertClass(database, WasmMatcherDatabase);
|
|
300
|
+
const ptr0 = passArray8ToWasm0(query, wasm.__wbindgen_malloc);
|
|
301
|
+
const len0 = WASM_VECTOR_LEN;
|
|
302
|
+
const ret = wasm.wasmmatcherengine_matchQueryWithVariants(this.__wbg_ptr, database.__wbg_ptr, ptr0, len0, pitch_query, isLikeNone(config) ? 0 : addToExternrefTable0(config), isLikeNone(variant_config) ? 0 : addToExternrefTable0(variant_config));
|
|
303
|
+
if (ret[2]) {
|
|
304
|
+
throw takeFromExternrefTable0(ret[1]);
|
|
305
|
+
}
|
|
306
|
+
return takeFromExternrefTable0(ret[0]);
|
|
307
|
+
}
|
|
151
308
|
constructor() {
|
|
152
309
|
const ret = wasm.wasmmatcherengine_new();
|
|
153
310
|
this.__wbg_ptr = ret >>> 0;
|
|
@@ -160,6 +317,120 @@ export class WasmMatcherEngine {
|
|
|
160
317
|
}
|
|
161
318
|
if (Symbol.dispose) WasmMatcherEngine.prototype[Symbol.dispose] = WasmMatcherEngine.prototype.free;
|
|
162
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
|
+
|
|
163
434
|
export function init_matcher_wasm() {
|
|
164
435
|
wasm.init_matcher_wasm();
|
|
165
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;
|
|
@@ -12,8 +19,18 @@ export const wasmmatcherdatabase_loadPackBytes: (a: number, b: number, c: number
|
|
|
12
19
|
export const wasmmatcherdatabase_loadPackBytesAppend: (a: number, b: number, c: number) => [number, number];
|
|
13
20
|
export const wasmmatcherdatabase_new: () => number;
|
|
14
21
|
export const wasmmatcherdatabase_removeEntry: (a: number, b: number, c: number) => [number, number];
|
|
22
|
+
export const wasmmatcherdatabase_setEntryVariantMetadata: (a: number, b: number, c: number, d: number, e: number) => [number, number];
|
|
15
23
|
export const wasmmatcherengine_bestMatch: (a: number, b: number, c: number, d: number, e: number) => [number, number, number];
|
|
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];
|
|
16
32
|
export const wasmmatcherengine_matchQuery: (a: number, b: number, c: number, d: number, e: number) => [number, number, number];
|
|
33
|
+
export const wasmmatcherengine_matchQueryWithVariants: (a: number, b: number, c: number, d: number, e: any, f: number, g: number) => [number, number, number];
|
|
17
34
|
export const wasmmatcherengine_new: () => number;
|
|
18
35
|
export const wasmmatcherengine_resetDistinctMatchState: (a: number) => void;
|
|
19
36
|
export const init_matcher_wasm: () => void;
|
package/dist/index.d.ts
CHANGED
|
@@ -7,6 +7,84 @@ 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;
|
|
54
|
+
}
|
|
55
|
+
interface VariantMatchQuery {
|
|
56
|
+
estimatedPitchRatio?: number | null;
|
|
57
|
+
pitchConfidence?: number | null;
|
|
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
|
+
}
|
|
66
|
+
interface VariantMatchConfig {
|
|
67
|
+
minConfidence?: number;
|
|
68
|
+
defaultToleranceRatio?: number;
|
|
69
|
+
minRatioMargin?: number;
|
|
70
|
+
candidateLimit?: number;
|
|
71
|
+
}
|
|
72
|
+
type VariantDecisionStatus = "variant" | "variant_unknown" | "no_variant";
|
|
73
|
+
interface VariantDecision {
|
|
74
|
+
status: VariantDecisionStatus;
|
|
75
|
+
reason?: string | null;
|
|
76
|
+
canonicalMaterialId?: string | null;
|
|
77
|
+
matchedEntryName?: string | null;
|
|
78
|
+
variantId?: string | null;
|
|
79
|
+
variantLabel?: string | null;
|
|
80
|
+
nominalRatio?: number | null;
|
|
81
|
+
estimatedPitchRatio?: number | null;
|
|
82
|
+
pitchConfidence?: number | null;
|
|
83
|
+
ratioError?: number | null;
|
|
84
|
+
pitchScore?: number | null;
|
|
85
|
+
toleranceMinRatio?: number | null;
|
|
86
|
+
toleranceMaxRatio?: number | null;
|
|
87
|
+
candidateCount: number;
|
|
10
88
|
}
|
|
11
89
|
interface EntryMetadata {
|
|
12
90
|
id?: string | null;
|
|
@@ -22,6 +100,10 @@ interface MatchResult {
|
|
|
22
100
|
position: number;
|
|
23
101
|
afpType: AudioFingerprintType;
|
|
24
102
|
}
|
|
103
|
+
interface VariantMatch {
|
|
104
|
+
matchResult: MatchResult;
|
|
105
|
+
variant: VariantDecision;
|
|
106
|
+
}
|
|
25
107
|
type PackSource = Uint8Array | ArrayBuffer | Blob | Response | Request | string | URL;
|
|
26
108
|
type MatcherSessionEventMap = {
|
|
27
109
|
ready: {
|
|
@@ -134,11 +216,19 @@ declare class MatcherSession {
|
|
|
134
216
|
loadPack(source: PackSource): Promise<void>;
|
|
135
217
|
addEntry(name: string, afpType: AudioFingerprintType, fingerprint: Uint8Array): Promise<void>;
|
|
136
218
|
addOrReplace(name: string, afpType: AudioFingerprintType, fingerprint: Uint8Array, metadata?: EntryMetadata | null): Promise<void>;
|
|
219
|
+
setEntryVariantMetadata(name: string, encodedMetadata: string): Promise<void>;
|
|
137
220
|
removeEntry(name: string): Promise<void>;
|
|
138
221
|
clear(): Promise<void>;
|
|
139
222
|
getEntryMetadata(name: string): Promise<EntryMetadata | null>;
|
|
140
223
|
match(query: Uint8Array, config?: MatchConfig): Promise<MatchResult[]>;
|
|
141
224
|
bestMatch(query: Uint8Array, config?: MatchConfig): Promise<MatchResult | null>;
|
|
225
|
+
estimatePitchRatio(pcm16Le: Uint8Array, sampleRate: number): Promise<PitchRatioEstimate>;
|
|
226
|
+
extractPitchReference(pcm16Le: Uint8Array, sampleRate: number): Promise<PitchReferenceEstimate>;
|
|
227
|
+
estimatePitchRatioAgainstReference(pcm16Le: Uint8Array, sampleRate: number, referencePitchHz: number, referenceConfidence?: number | null): Promise<PitchRatioEstimate>;
|
|
228
|
+
estimatePitchRatioAgainstReferenceFeatures(pcm16Le: Uint8Array, sampleRate: number, referenceFeatures: string, referencePositionMillis: number, referenceConfidence?: number | null): Promise<PitchRatioEstimate>;
|
|
229
|
+
detectAudioMarker(pcm16Le: Uint8Array, sampleRate: number, config?: AudioMarkerConfig): Promise<AudioMarkerDetection>;
|
|
230
|
+
matchWithVariants(query: Uint8Array, pitchQuery: VariantMatchQuery, config?: MatchConfig, variantConfig?: VariantMatchConfig): Promise<VariantMatch[]>;
|
|
231
|
+
bestMatchWithVariants(query: Uint8Array, pitchQuery: VariantMatchQuery, config?: MatchConfig, variantConfig?: VariantMatchConfig): Promise<VariantMatch | null>;
|
|
142
232
|
destroy(): void;
|
|
143
233
|
private bootstrap;
|
|
144
234
|
private ensureLiveReady;
|
|
@@ -151,4 +241,4 @@ declare function __setMatcherWasmModuleForTests(moduleLike: unknown): void;
|
|
|
151
241
|
declare function __setMatcherEmbeddedPackForTests(bytes: Uint8Array): void;
|
|
152
242
|
declare function __resetMatcherWasmForTests(): void;
|
|
153
243
|
|
|
154
|
-
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, __resetMatcherWasmForTests, __setMatcherEmbeddedPackForTests, __setMatcherWasmModuleForTests, initMatcher };
|
|
244
|
+
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
|
@@ -358,6 +358,13 @@ var WrappedDatabase = class {
|
|
|
358
358
|
}
|
|
359
359
|
return normalizeEntryMetadata(raw);
|
|
360
360
|
}
|
|
361
|
+
setEntryVariantMetadata(name, encodedMetadata) {
|
|
362
|
+
const fn = getCallable(this.inner, ["setEntryVariantMetadata", "set_entry_variant_metadata"]);
|
|
363
|
+
if (!fn) {
|
|
364
|
+
throw new Error("WASM database is missing setEntryVariantMetadata-compatible method");
|
|
365
|
+
}
|
|
366
|
+
fn.call(this.inner, name, encodedMetadata);
|
|
367
|
+
}
|
|
361
368
|
destroy() {
|
|
362
369
|
const fn = getCallable(this.inner, ["destroy", "free"]);
|
|
363
370
|
if (fn) {
|
|
@@ -368,7 +375,70 @@ var WrappedDatabase = class {
|
|
|
368
375
|
var WrappedMatcher = class {
|
|
369
376
|
constructor(inner) {
|
|
370
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
|
+
}
|
|
371
436
|
}
|
|
437
|
+
estimatePitchRatio;
|
|
438
|
+
extractPitchReference;
|
|
439
|
+
estimatePitchRatioAgainstReference;
|
|
440
|
+
estimatePitchRatioAgainstReferenceFeatures;
|
|
441
|
+
detectAudioMarker;
|
|
372
442
|
findMatches(database, query, config) {
|
|
373
443
|
const fn = getCallable(this.inner, ["findMatches", "find_matches", "matchQuery", "match_query", "match"]);
|
|
374
444
|
if (!fn) {
|
|
@@ -403,6 +473,31 @@ var WrappedMatcher = class {
|
|
|
403
473
|
}
|
|
404
474
|
return normalizeResult(raw);
|
|
405
475
|
}
|
|
476
|
+
findMatchesWithVariants(database, query, pitchQuery, config, variantConfig) {
|
|
477
|
+
const fn = getCallable(this.inner, [
|
|
478
|
+
"findMatchesWithVariants",
|
|
479
|
+
"matchQueryWithVariants",
|
|
480
|
+
"match_query_with_variants"
|
|
481
|
+
]);
|
|
482
|
+
if (!fn) {
|
|
483
|
+
throw new Error("WASM matcher is missing findMatchesWithVariants-compatible method");
|
|
484
|
+
}
|
|
485
|
+
const dbRecord = typeof database.raw === "function" ? database.raw() : database;
|
|
486
|
+
const rawResults = fn.call(this.inner, dbRecord, query, pitchQuery, config, variantConfig);
|
|
487
|
+
return normalizeVariantMatches(rawResults ?? []);
|
|
488
|
+
}
|
|
489
|
+
bestMatchWithVariants(database, query, pitchQuery, config, variantConfig) {
|
|
490
|
+
const fn = getCallable(this.inner, [
|
|
491
|
+
"bestMatchWithVariants",
|
|
492
|
+
"best_match_with_variants"
|
|
493
|
+
]);
|
|
494
|
+
if (!fn) {
|
|
495
|
+
throw new Error("WASM matcher is missing bestMatchWithVariants-compatible method");
|
|
496
|
+
}
|
|
497
|
+
const dbRecord = typeof database.raw === "function" ? database.raw() : database;
|
|
498
|
+
const raw = fn.call(this.inner, dbRecord, query, pitchQuery, config, variantConfig);
|
|
499
|
+
return raw && typeof raw === "object" ? normalizeVariantMatch(raw) : null;
|
|
500
|
+
}
|
|
406
501
|
resetDistinctMatchState() {
|
|
407
502
|
const fn = getCallable(this.inner, ["resetDistinctMatchState", "reset_distinct_match_state"]);
|
|
408
503
|
fn?.call(this.inner);
|
|
@@ -423,6 +518,76 @@ function normalizeResult(raw) {
|
|
|
423
518
|
afpType
|
|
424
519
|
};
|
|
425
520
|
}
|
|
521
|
+
function normalizeVariantMatch(raw) {
|
|
522
|
+
const rawMatch = raw.matchResult ?? raw.match;
|
|
523
|
+
const rawVariant = raw.variant ?? {};
|
|
524
|
+
return {
|
|
525
|
+
matchResult: normalizeResult(rawMatch),
|
|
526
|
+
variant: {
|
|
527
|
+
...rawVariant,
|
|
528
|
+
status: String(rawVariant.status),
|
|
529
|
+
candidateCount: Number(rawVariant.candidateCount ?? 0)
|
|
530
|
+
}
|
|
531
|
+
};
|
|
532
|
+
}
|
|
533
|
+
function normalizeOptionalNumber(camelValue, snakeValue) {
|
|
534
|
+
const value = camelValue ?? snakeValue;
|
|
535
|
+
return value == null ? null : Number(value);
|
|
536
|
+
}
|
|
537
|
+
function normalizePitchRatioEstimate(raw) {
|
|
538
|
+
const record = raw && typeof raw === "object" ? raw : {};
|
|
539
|
+
return {
|
|
540
|
+
estimatedPitchRatio: normalizeOptionalNumber(
|
|
541
|
+
record.estimatedPitchRatio,
|
|
542
|
+
record.estimated_pitch_ratio
|
|
543
|
+
),
|
|
544
|
+
pitchConfidence: normalizeOptionalNumber(record.pitchConfidence, record.pitch_confidence)
|
|
545
|
+
};
|
|
546
|
+
}
|
|
547
|
+
function normalizeOptionalString(value) {
|
|
548
|
+
return value == null ? null : String(value);
|
|
549
|
+
}
|
|
550
|
+
function normalizePitchReferenceEstimate(raw) {
|
|
551
|
+
const record = raw && typeof raw === "object" ? raw : {};
|
|
552
|
+
return {
|
|
553
|
+
pitchHz: normalizeOptionalNumber(record.pitchHz, record.pitch_hz),
|
|
554
|
+
pitchConfidence: normalizeOptionalNumber(record.pitchConfidence, record.pitch_confidence),
|
|
555
|
+
features: normalizeOptionalString(record.features)
|
|
556
|
+
};
|
|
557
|
+
}
|
|
558
|
+
function normalizeNumber(camelValue, snakeValue, fallback = 0) {
|
|
559
|
+
const value = camelValue ?? snakeValue;
|
|
560
|
+
return value == null ? fallback : Number(value);
|
|
561
|
+
}
|
|
562
|
+
function normalizeAudioMarkerDetection(raw) {
|
|
563
|
+
const record = raw && typeof raw === "object" ? raw : {};
|
|
564
|
+
return {
|
|
565
|
+
pattern: normalizeOptionalString(record.pattern),
|
|
566
|
+
code: normalizeOptionalString(record.code),
|
|
567
|
+
confidence: normalizeOptionalNumber(record.confidence, void 0),
|
|
568
|
+
score: normalizeNumber(record.score, void 0),
|
|
569
|
+
margin: normalizeNumber(record.margin, void 0),
|
|
570
|
+
accuracy: normalizeNumber(record.accuracy, void 0),
|
|
571
|
+
bandLowHz: normalizeNumber(record.bandLowHz, record.band_low_hz),
|
|
572
|
+
bandHighHz: normalizeNumber(record.bandHighHz, record.band_high_hz),
|
|
573
|
+
syncScore: normalizeNumber(record.syncScore, record.sync_score),
|
|
574
|
+
chipCount: normalizeNumber(record.chipCount, record.chip_count),
|
|
575
|
+
frameStartSample: normalizeNumber(record.frameStartSample, record.frame_start_sample),
|
|
576
|
+
frameCount: normalizeNumber(record.frameCount, record.frame_count),
|
|
577
|
+
voteCount: normalizeNumber(record.voteCount, record.vote_count),
|
|
578
|
+
reason: normalizeOptionalString(record.reason),
|
|
579
|
+
candidatePattern: normalizeOptionalString(record.candidatePattern ?? record.candidate_pattern),
|
|
580
|
+
candidateCode: normalizeOptionalString(record.candidateCode ?? record.candidate_code),
|
|
581
|
+
candidateConfidence: normalizeOptionalNumber(
|
|
582
|
+
record.candidateConfidence,
|
|
583
|
+
record.candidate_confidence
|
|
584
|
+
),
|
|
585
|
+
runnerUpPattern: normalizeOptionalString(record.runnerUpPattern ?? record.runner_up_pattern),
|
|
586
|
+
runnerUpCode: normalizeOptionalString(record.runnerUpCode ?? record.runner_up_code),
|
|
587
|
+
runnerUpScore: normalizeOptionalNumber(record.runnerUpScore, record.runner_up_score),
|
|
588
|
+
runnerUpAccuracy: normalizeOptionalNumber(record.runnerUpAccuracy, record.runner_up_accuracy)
|
|
589
|
+
};
|
|
590
|
+
}
|
|
426
591
|
function isMapLike(raw) {
|
|
427
592
|
return raw instanceof Map || Object.prototype.toString.call(raw) === "[object Map]" && typeof raw.entries === "function";
|
|
428
593
|
}
|
|
@@ -462,6 +627,9 @@ function normalizeEntryMetadata(raw) {
|
|
|
462
627
|
function normalizeResults(rawResults) {
|
|
463
628
|
return rawResults.filter((item) => typeof item === "object" && item !== null).map((item) => normalizeResult(item));
|
|
464
629
|
}
|
|
630
|
+
function normalizeVariantMatches(rawResults) {
|
|
631
|
+
return rawResults.filter((item) => typeof item === "object" && item !== null).map((item) => normalizeVariantMatch(item));
|
|
632
|
+
}
|
|
465
633
|
function isInternallyDuplicatedBestMatch(result) {
|
|
466
634
|
return Boolean(
|
|
467
635
|
result && typeof result === "object" && result[INTERNAL_DUPLICATE_MATCH_FLAG] === true
|
|
@@ -479,6 +647,25 @@ function createBindingsFromModule(moduleLike) {
|
|
|
479
647
|
const initFn = getCallable(mod, ["initMatcher"]) ?? (typeof mod.default === "function" ? mod.default.bind(mod) : null);
|
|
480
648
|
const createDatabaseFactory = resolveFactory(mod, ["createDatabase"]);
|
|
481
649
|
const createMatcherFactory = resolveFactory(mod, ["createMatcher"]);
|
|
650
|
+
const estimatePitchRatioFn = resolveFactory(mod, ["estimatePitchRatio", "estimate_pitch_ratio"]);
|
|
651
|
+
const extractPitchReferenceFn = resolveFactory(mod, [
|
|
652
|
+
"extractPitchReference",
|
|
653
|
+
"extract_pitch_reference"
|
|
654
|
+
]);
|
|
655
|
+
const estimatePitchRatioAgainstReferenceFn = resolveFactory(mod, [
|
|
656
|
+
"estimatePitchRatioAgainstReference",
|
|
657
|
+
"estimate_pitch_ratio_against_reference"
|
|
658
|
+
]);
|
|
659
|
+
const estimatePitchRatioAgainstReferenceFeaturesFn = resolveFactory(mod, [
|
|
660
|
+
"estimatePitchRatioAgainstReferenceFeatures",
|
|
661
|
+
"estimate_pitch_ratio_against_reference_features"
|
|
662
|
+
]);
|
|
663
|
+
const detectAudioMarkerFn = resolveFactory(mod, [
|
|
664
|
+
"detectAudioMarker",
|
|
665
|
+
"detect_audio_marker",
|
|
666
|
+
"detectPatternMark",
|
|
667
|
+
"detect_pattern_mark"
|
|
668
|
+
]);
|
|
482
669
|
const DatabaseCtor = mod.WasmMatcherDatabase ?? mod.MatcherDatabase ?? mod.Database;
|
|
483
670
|
const MatcherCtor = mod.WasmMatcherEngine ?? mod.MatcherEngine ?? mod.Matcher ?? mod.AudioMatcher;
|
|
484
671
|
if (!createDatabaseFactory && !DatabaseCtor) {
|
|
@@ -500,6 +687,116 @@ function createBindingsFromModule(moduleLike) {
|
|
|
500
687
|
createMatcher() {
|
|
501
688
|
const matcher = createMatcherFactory ? createMatcherFactory() : new MatcherCtor();
|
|
502
689
|
return new WrappedMatcher(matcher);
|
|
690
|
+
},
|
|
691
|
+
estimatePitchRatio(pcm16Le, sampleRate) {
|
|
692
|
+
if (estimatePitchRatioFn) {
|
|
693
|
+
return normalizePitchRatioEstimate(estimatePitchRatioFn(pcm16Le, sampleRate));
|
|
694
|
+
}
|
|
695
|
+
const matcher = createMatcherFactory ? createMatcherFactory() : new MatcherCtor();
|
|
696
|
+
try {
|
|
697
|
+
const wrapped = new WrappedMatcher(matcher);
|
|
698
|
+
if (!wrapped.estimatePitchRatio) {
|
|
699
|
+
throw new Error("WASM matcher is missing estimatePitchRatio-compatible method");
|
|
700
|
+
}
|
|
701
|
+
return wrapped.estimatePitchRatio(pcm16Le, sampleRate);
|
|
702
|
+
} finally {
|
|
703
|
+
const destroy = getCallable(matcher, ["destroy", "free"]);
|
|
704
|
+
destroy?.call(matcher);
|
|
705
|
+
}
|
|
706
|
+
},
|
|
707
|
+
extractPitchReference(pcm16Le, sampleRate) {
|
|
708
|
+
if (extractPitchReferenceFn) {
|
|
709
|
+
return normalizePitchReferenceEstimate(extractPitchReferenceFn(pcm16Le, sampleRate));
|
|
710
|
+
}
|
|
711
|
+
const matcher = createMatcherFactory ? createMatcherFactory() : new MatcherCtor();
|
|
712
|
+
try {
|
|
713
|
+
const wrapped = new WrappedMatcher(matcher);
|
|
714
|
+
if (!wrapped.extractPitchReference) {
|
|
715
|
+
throw new Error("WASM matcher is missing extractPitchReference-compatible method");
|
|
716
|
+
}
|
|
717
|
+
return wrapped.extractPitchReference(pcm16Le, sampleRate);
|
|
718
|
+
} finally {
|
|
719
|
+
const destroy = getCallable(matcher, ["destroy", "free"]);
|
|
720
|
+
destroy?.call(matcher);
|
|
721
|
+
}
|
|
722
|
+
},
|
|
723
|
+
estimatePitchRatioAgainstReference(pcm16Le, sampleRate, referencePitchHz, referenceConfidence) {
|
|
724
|
+
if (estimatePitchRatioAgainstReferenceFn) {
|
|
725
|
+
return normalizePitchRatioEstimate(
|
|
726
|
+
estimatePitchRatioAgainstReferenceFn(
|
|
727
|
+
pcm16Le,
|
|
728
|
+
sampleRate,
|
|
729
|
+
referencePitchHz,
|
|
730
|
+
referenceConfidence
|
|
731
|
+
)
|
|
732
|
+
);
|
|
733
|
+
}
|
|
734
|
+
const matcher = createMatcherFactory ? createMatcherFactory() : new MatcherCtor();
|
|
735
|
+
try {
|
|
736
|
+
const wrapped = new WrappedMatcher(matcher);
|
|
737
|
+
if (!wrapped.estimatePitchRatioAgainstReference) {
|
|
738
|
+
throw new Error(
|
|
739
|
+
"WASM matcher is missing estimatePitchRatioAgainstReference-compatible method"
|
|
740
|
+
);
|
|
741
|
+
}
|
|
742
|
+
return wrapped.estimatePitchRatioAgainstReference(
|
|
743
|
+
pcm16Le,
|
|
744
|
+
sampleRate,
|
|
745
|
+
referencePitchHz,
|
|
746
|
+
referenceConfidence
|
|
747
|
+
);
|
|
748
|
+
} finally {
|
|
749
|
+
const destroy = getCallable(matcher, ["destroy", "free"]);
|
|
750
|
+
destroy?.call(matcher);
|
|
751
|
+
}
|
|
752
|
+
},
|
|
753
|
+
estimatePitchRatioAgainstReferenceFeatures(pcm16Le, sampleRate, referenceFeatures, referencePositionMillis, referenceConfidence) {
|
|
754
|
+
if (estimatePitchRatioAgainstReferenceFeaturesFn) {
|
|
755
|
+
return normalizePitchRatioEstimate(
|
|
756
|
+
estimatePitchRatioAgainstReferenceFeaturesFn(
|
|
757
|
+
pcm16Le,
|
|
758
|
+
sampleRate,
|
|
759
|
+
referenceFeatures,
|
|
760
|
+
referencePositionMillis,
|
|
761
|
+
referenceConfidence
|
|
762
|
+
)
|
|
763
|
+
);
|
|
764
|
+
}
|
|
765
|
+
const matcher = createMatcherFactory ? createMatcherFactory() : new MatcherCtor();
|
|
766
|
+
try {
|
|
767
|
+
const wrapped = new WrappedMatcher(matcher);
|
|
768
|
+
if (!wrapped.estimatePitchRatioAgainstReferenceFeatures) {
|
|
769
|
+
throw new Error(
|
|
770
|
+
"WASM matcher is missing estimatePitchRatioAgainstReferenceFeatures-compatible method"
|
|
771
|
+
);
|
|
772
|
+
}
|
|
773
|
+
return wrapped.estimatePitchRatioAgainstReferenceFeatures(
|
|
774
|
+
pcm16Le,
|
|
775
|
+
sampleRate,
|
|
776
|
+
referenceFeatures,
|
|
777
|
+
referencePositionMillis,
|
|
778
|
+
referenceConfidence
|
|
779
|
+
);
|
|
780
|
+
} finally {
|
|
781
|
+
const destroy = getCallable(matcher, ["destroy", "free"]);
|
|
782
|
+
destroy?.call(matcher);
|
|
783
|
+
}
|
|
784
|
+
},
|
|
785
|
+
detectAudioMarker(pcm16Le, sampleRate, config) {
|
|
786
|
+
if (detectAudioMarkerFn) {
|
|
787
|
+
return normalizeAudioMarkerDetection(detectAudioMarkerFn(pcm16Le, sampleRate, config));
|
|
788
|
+
}
|
|
789
|
+
const matcher = createMatcherFactory ? createMatcherFactory() : new MatcherCtor();
|
|
790
|
+
try {
|
|
791
|
+
const wrapped = new WrappedMatcher(matcher);
|
|
792
|
+
if (!wrapped.detectAudioMarker) {
|
|
793
|
+
throw new Error("WASM matcher is missing detectAudioMarker-compatible method");
|
|
794
|
+
}
|
|
795
|
+
return wrapped.detectAudioMarker(pcm16Le, sampleRate, config);
|
|
796
|
+
} finally {
|
|
797
|
+
const destroy = getCallable(matcher, ["destroy", "free"]);
|
|
798
|
+
destroy?.call(matcher);
|
|
799
|
+
}
|
|
503
800
|
}
|
|
504
801
|
};
|
|
505
802
|
}
|
|
@@ -619,6 +916,16 @@ var MatcherSession = class {
|
|
|
619
916
|
handleError(this.events, "addOrReplace", error);
|
|
620
917
|
}
|
|
621
918
|
}
|
|
919
|
+
async setEntryVariantMetadata(name, encodedMetadata) {
|
|
920
|
+
try {
|
|
921
|
+
await this.ensureLiveReady();
|
|
922
|
+
this.databaseOrThrow().setEntryVariantMetadata(name, encodedMetadata);
|
|
923
|
+
this.distinctMatchDeduper.reset();
|
|
924
|
+
this.matcher?.resetDistinctMatchState?.();
|
|
925
|
+
} catch (error) {
|
|
926
|
+
handleError(this.events, "setEntryVariantMetadata", error);
|
|
927
|
+
}
|
|
928
|
+
}
|
|
622
929
|
async removeEntry(name) {
|
|
623
930
|
try {
|
|
624
931
|
await this.ensureLiveReady();
|
|
@@ -674,6 +981,152 @@ var MatcherSession = class {
|
|
|
674
981
|
handleError(this.events, "bestMatch", error);
|
|
675
982
|
}
|
|
676
983
|
}
|
|
984
|
+
async estimatePitchRatio(pcm16Le, sampleRate) {
|
|
985
|
+
try {
|
|
986
|
+
await this.ensureLiveReady();
|
|
987
|
+
const safePcm = toUint8ArrayCopy(pcm16Le);
|
|
988
|
+
const matcher = this.matcherOrThrow();
|
|
989
|
+
if (matcher.estimatePitchRatio) {
|
|
990
|
+
return matcher.estimatePitchRatio(safePcm, sampleRate);
|
|
991
|
+
}
|
|
992
|
+
if (!this.bindings) {
|
|
993
|
+
throw new Error("Matcher bindings are not initialized");
|
|
994
|
+
}
|
|
995
|
+
return this.bindings.estimatePitchRatio(safePcm, sampleRate);
|
|
996
|
+
} catch (error) {
|
|
997
|
+
handleError(this.events, "estimatePitchRatio", error);
|
|
998
|
+
}
|
|
999
|
+
}
|
|
1000
|
+
async extractPitchReference(pcm16Le, sampleRate) {
|
|
1001
|
+
try {
|
|
1002
|
+
await this.ensureLiveReady();
|
|
1003
|
+
const safePcm = toUint8ArrayCopy(pcm16Le);
|
|
1004
|
+
const matcher = this.matcherOrThrow();
|
|
1005
|
+
if (matcher.extractPitchReference) {
|
|
1006
|
+
return matcher.extractPitchReference(safePcm, sampleRate);
|
|
1007
|
+
}
|
|
1008
|
+
if (!this.bindings) {
|
|
1009
|
+
throw new Error("Matcher bindings are not initialized");
|
|
1010
|
+
}
|
|
1011
|
+
return this.bindings.extractPitchReference(safePcm, sampleRate);
|
|
1012
|
+
} catch (error) {
|
|
1013
|
+
handleError(this.events, "extractPitchReference", error);
|
|
1014
|
+
}
|
|
1015
|
+
}
|
|
1016
|
+
async estimatePitchRatioAgainstReference(pcm16Le, sampleRate, referencePitchHz, referenceConfidence) {
|
|
1017
|
+
try {
|
|
1018
|
+
await this.ensureLiveReady();
|
|
1019
|
+
const safePcm = toUint8ArrayCopy(pcm16Le);
|
|
1020
|
+
const matcher = this.matcherOrThrow();
|
|
1021
|
+
if (matcher.estimatePitchRatioAgainstReference) {
|
|
1022
|
+
return matcher.estimatePitchRatioAgainstReference(
|
|
1023
|
+
safePcm,
|
|
1024
|
+
sampleRate,
|
|
1025
|
+
referencePitchHz,
|
|
1026
|
+
referenceConfidence
|
|
1027
|
+
);
|
|
1028
|
+
}
|
|
1029
|
+
if (!this.bindings) {
|
|
1030
|
+
throw new Error("Matcher bindings are not initialized");
|
|
1031
|
+
}
|
|
1032
|
+
return this.bindings.estimatePitchRatioAgainstReference(
|
|
1033
|
+
safePcm,
|
|
1034
|
+
sampleRate,
|
|
1035
|
+
referencePitchHz,
|
|
1036
|
+
referenceConfidence
|
|
1037
|
+
);
|
|
1038
|
+
} catch (error) {
|
|
1039
|
+
handleError(this.events, "estimatePitchRatioAgainstReference", error);
|
|
1040
|
+
}
|
|
1041
|
+
}
|
|
1042
|
+
async estimatePitchRatioAgainstReferenceFeatures(pcm16Le, sampleRate, referenceFeatures, referencePositionMillis, referenceConfidence) {
|
|
1043
|
+
try {
|
|
1044
|
+
await this.ensureLiveReady();
|
|
1045
|
+
const safePcm = toUint8ArrayCopy(pcm16Le);
|
|
1046
|
+
const matcher = this.matcherOrThrow();
|
|
1047
|
+
if (matcher.estimatePitchRatioAgainstReferenceFeatures) {
|
|
1048
|
+
return matcher.estimatePitchRatioAgainstReferenceFeatures(
|
|
1049
|
+
safePcm,
|
|
1050
|
+
sampleRate,
|
|
1051
|
+
referenceFeatures,
|
|
1052
|
+
referencePositionMillis,
|
|
1053
|
+
referenceConfidence
|
|
1054
|
+
);
|
|
1055
|
+
}
|
|
1056
|
+
if (!this.bindings) {
|
|
1057
|
+
throw new Error("Matcher bindings are not initialized");
|
|
1058
|
+
}
|
|
1059
|
+
return this.bindings.estimatePitchRatioAgainstReferenceFeatures(
|
|
1060
|
+
safePcm,
|
|
1061
|
+
sampleRate,
|
|
1062
|
+
referenceFeatures,
|
|
1063
|
+
referencePositionMillis,
|
|
1064
|
+
referenceConfidence
|
|
1065
|
+
);
|
|
1066
|
+
} catch (error) {
|
|
1067
|
+
handleError(this.events, "estimatePitchRatioAgainstReferenceFeatures", error);
|
|
1068
|
+
}
|
|
1069
|
+
}
|
|
1070
|
+
async detectAudioMarker(pcm16Le, sampleRate, config) {
|
|
1071
|
+
try {
|
|
1072
|
+
await this.ensureLiveReady();
|
|
1073
|
+
const safePcm = toUint8ArrayCopy(pcm16Le);
|
|
1074
|
+
const matcher = this.matcherOrThrow();
|
|
1075
|
+
if (matcher.detectAudioMarker) {
|
|
1076
|
+
return matcher.detectAudioMarker(safePcm, sampleRate, config);
|
|
1077
|
+
}
|
|
1078
|
+
if (!this.bindings) {
|
|
1079
|
+
throw new Error("Matcher bindings are not initialized");
|
|
1080
|
+
}
|
|
1081
|
+
return this.bindings.detectAudioMarker(safePcm, sampleRate, config);
|
|
1082
|
+
} catch (error) {
|
|
1083
|
+
handleError(this.events, "detectAudioMarker", error);
|
|
1084
|
+
}
|
|
1085
|
+
}
|
|
1086
|
+
async matchWithVariants(query, pitchQuery, config, variantConfig) {
|
|
1087
|
+
try {
|
|
1088
|
+
await this.ensureLiveReady();
|
|
1089
|
+
const safeQuery = toUint8ArrayCopy(query);
|
|
1090
|
+
this.events.emit("querystart", { queryByteLength: safeQuery.byteLength });
|
|
1091
|
+
const results = this.matcherOrThrow().findMatchesWithVariants(
|
|
1092
|
+
this.databaseOrThrow(),
|
|
1093
|
+
safeQuery,
|
|
1094
|
+
pitchQuery,
|
|
1095
|
+
config,
|
|
1096
|
+
variantConfig
|
|
1097
|
+
);
|
|
1098
|
+
this.emitDistinctMatchEvent(
|
|
1099
|
+
results[0]?.matchResult ?? null,
|
|
1100
|
+
safeQuery.byteLength,
|
|
1101
|
+
results.map((result) => result.matchResult)
|
|
1102
|
+
);
|
|
1103
|
+
return results;
|
|
1104
|
+
} catch (error) {
|
|
1105
|
+
handleError(this.events, "matchWithVariants", error);
|
|
1106
|
+
}
|
|
1107
|
+
}
|
|
1108
|
+
async bestMatchWithVariants(query, pitchQuery, config, variantConfig) {
|
|
1109
|
+
try {
|
|
1110
|
+
await this.ensureLiveReady();
|
|
1111
|
+
const safeQuery = toUint8ArrayCopy(query);
|
|
1112
|
+
this.events.emit("querystart", { queryByteLength: safeQuery.byteLength });
|
|
1113
|
+
const best = this.matcherOrThrow().bestMatchWithVariants(
|
|
1114
|
+
this.databaseOrThrow(),
|
|
1115
|
+
safeQuery,
|
|
1116
|
+
pitchQuery,
|
|
1117
|
+
config,
|
|
1118
|
+
variantConfig
|
|
1119
|
+
);
|
|
1120
|
+
this.emitDistinctMatchEvent(
|
|
1121
|
+
best?.matchResult ?? null,
|
|
1122
|
+
safeQuery.byteLength,
|
|
1123
|
+
best ? [best.matchResult] : []
|
|
1124
|
+
);
|
|
1125
|
+
return best;
|
|
1126
|
+
} catch (error) {
|
|
1127
|
+
handleError(this.events, "bestMatchWithVariants", error);
|
|
1128
|
+
}
|
|
1129
|
+
}
|
|
677
1130
|
destroy() {
|
|
678
1131
|
if (this.destroyed) {
|
|
679
1132
|
return;
|