@sorisdk/matcher 0.4.0 → 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.
@@ -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;
@@ -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;
@@ -171,6 +222,11 @@ declare class MatcherSession {
171
222
  getEntryMetadata(name: string): Promise<EntryMetadata | null>;
172
223
  match(query: Uint8Array, config?: MatchConfig): Promise<MatchResult[]>;
173
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>;
174
230
  matchWithVariants(query: Uint8Array, pitchQuery: VariantMatchQuery, config?: MatchConfig, variantConfig?: VariantMatchConfig): Promise<VariantMatch[]>;
175
231
  bestMatchWithVariants(query: Uint8Array, pitchQuery: VariantMatchQuery, config?: MatchConfig, variantConfig?: VariantMatchConfig): Promise<VariantMatch | null>;
176
232
  destroy(): void;
@@ -185,4 +241,4 @@ declare function __setMatcherWasmModuleForTests(moduleLike: unknown): void;
185
241
  declare function __setMatcherEmbeddedPackForTests(bytes: Uint8Array): void;
186
242
  declare function __resetMatcherWasmForTests(): void;
187
243
 
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 };
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
@@ -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) {
@@ -467,6 +530,64 @@ function normalizeVariantMatch(raw) {
467
530
  }
468
531
  };
469
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
+ }
470
591
  function isMapLike(raw) {
471
592
  return raw instanceof Map || Object.prototype.toString.call(raw) === "[object Map]" && typeof raw.entries === "function";
472
593
  }
@@ -526,6 +647,25 @@ function createBindingsFromModule(moduleLike) {
526
647
  const initFn = getCallable(mod, ["initMatcher"]) ?? (typeof mod.default === "function" ? mod.default.bind(mod) : null);
527
648
  const createDatabaseFactory = resolveFactory(mod, ["createDatabase"]);
528
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
+ ]);
529
669
  const DatabaseCtor = mod.WasmMatcherDatabase ?? mod.MatcherDatabase ?? mod.Database;
530
670
  const MatcherCtor = mod.WasmMatcherEngine ?? mod.MatcherEngine ?? mod.Matcher ?? mod.AudioMatcher;
531
671
  if (!createDatabaseFactory && !DatabaseCtor) {
@@ -547,6 +687,116 @@ function createBindingsFromModule(moduleLike) {
547
687
  createMatcher() {
548
688
  const matcher = createMatcherFactory ? createMatcherFactory() : new MatcherCtor();
549
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
+ }
550
800
  }
551
801
  };
552
802
  }
@@ -731,6 +981,108 @@ var MatcherSession = class {
731
981
  handleError(this.events, "bestMatch", error);
732
982
  }
733
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
+ }
734
1086
  async matchWithVariants(query, pitchQuery, config, variantConfig) {
735
1087
  try {
736
1088
  await this.ensureLiveReady();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sorisdk/matcher",
3
- "version": "0.4.0",
3
+ "version": "0.5.1",
4
4
  "description": "Browser WASM SDK for audio fingerprint matching",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",