signavis 1.2.0 → 1.3.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.
Files changed (81) hide show
  1. package/dist/assets/wasm-spectrogram.worker-oU-CQV61.js.map +1 -1
  2. package/dist/birdnet-player.css +1 -1
  3. package/dist/birdnet-player.esm.js +1541 -1162
  4. package/dist/birdnet-player.esm.js.map +1 -1
  5. package/dist/birdnet-player.iife.js +63 -29
  6. package/dist/birdnet-player.iife.js.map +1 -1
  7. package/dist/tokens.css +3 -0
  8. package/package.json +6 -4
  9. package/types/generated/app/BirdNETPlayer.d.ts +36 -7
  10. package/types/generated/app/PlayerState.d.ts +8 -1
  11. package/types/generated/app/ViewportManager.d.ts +20 -3
  12. package/types/generated/app/adopt-detection.d.ts +34 -0
  13. package/types/generated/app/annotation-sets.d.ts +9 -1
  14. package/types/generated/app/annotator-profile.d.ts +2 -0
  15. package/types/generated/app/domRefs.d.ts +7 -0
  16. package/types/generated/app/interactionState.d.ts +2 -0
  17. package/types/generated/app/labeling/app-context.d.ts +44 -0
  18. package/types/generated/app/labeling/dedupe-labels.d.ts +13 -0
  19. package/types/generated/app/labeling/features/annota-import.d.ts +14 -0
  20. package/types/generated/app/labeling/features/file-drop.d.ts +12 -0
  21. package/types/generated/app/labeling/features/mic-recording.d.ts +9 -0
  22. package/types/generated/app/labeling/features/raven-export.d.ts +6 -0
  23. package/types/generated/app/labeling/features/theme.d.ts +1 -0
  24. package/types/generated/app/labeling/features/xc-upload.d.ts +48 -0
  25. package/types/generated/app/labeling/help-menu.d.ts +37 -0
  26. package/types/generated/app/labeling/label-store.d.ts +59 -0
  27. package/types/generated/app/labeling/main.d.ts +0 -0
  28. package/types/generated/app/labeling/render-scheduler.d.ts +16 -0
  29. package/types/generated/app/labeling/sponsor-card.d.ts +11 -0
  30. package/types/generated/app/player/WaveformRenderer.d.ts +10 -0
  31. package/types/generated/app/recording-manager.d.ts +2 -0
  32. package/types/generated/app/similarBand.d.ts +11 -0
  33. package/types/generated/app/similarSpectrogram.d.ts +34 -0
  34. package/types/generated/app/suggest-similar.d.ts +56 -0
  35. package/types/generated/domain/annotations.d.ts +103 -4
  36. package/types/generated/domain/detector/birdboxStream.d.ts +142 -0
  37. package/types/generated/domain/detector/boxUnder.d.ts +17 -0
  38. package/types/generated/domain/detector/fusion.d.ts +50 -0
  39. package/types/generated/domain/detector/nearby.d.ts +47 -0
  40. package/types/generated/domain/detector/pacer.d.ts +45 -0
  41. package/types/generated/domain/labelBand.d.ts +12 -0
  42. package/types/generated/domain/similar/cluster.d.ts +40 -0
  43. package/types/generated/domain/similar/ncc.d.ts +144 -0
  44. package/types/generated/domain/snapToCall.d.ts +10 -0
  45. package/types/generated/domain/species-lists.d.ts +53 -0
  46. package/types/generated/domain/speciesLinks.d.ts +17 -0
  47. package/types/generated/infrastructure/audio/LiveRecorder.d.ts +2 -0
  48. package/types/generated/infrastructure/birdnetInference.d.ts +3 -0
  49. package/types/generated/infrastructure/detector/birdbox.worker.d.ts +1 -0
  50. package/types/generated/infrastructure/detector/birdboxDetector.d.ts +69 -0
  51. package/types/generated/infrastructure/detector/birdboxGraph.d.ts +53 -0
  52. package/types/generated/infrastructure/similar.worker.d.ts +1 -0
  53. package/types/generated/infrastructure/tauri/runtime.d.ts +8 -2
  54. package/types/generated/infrastructure/xeno-canto/annotaPayload.d.ts +2 -0
  55. package/types/generated/shared/constants.d.ts +2 -1
  56. package/types/generated/shared/events.d.ts +2 -0
  57. package/types/generated/ui/components/label-editor/LabelEditorModal.d.ts +7 -1
  58. package/types/generated/ui/components/label-template/template-tags.d.ts +18 -0
  59. package/types/generated/ui/components/onboarding/onboarding-wizard.d.ts +22 -0
  60. package/types/generated/ui/components/overview/overview-controller.d.ts +6 -1
  61. package/types/generated/ui/components/similar-review/group-review.d.ts +40 -0
  62. package/types/generated/ui/components/similar-review/similar-review.d.ts +62 -0
  63. package/types/generated/ui/components/taxonomy-ui/species-geo-cache.d.ts +28 -0
  64. package/types/generated/ui/components/taxonomy-ui/species-ranking.d.ts +51 -0
  65. package/types/generated/ui/components/taxonomy-ui/taxonomy-ui.d.ts +43 -26
  66. package/types/generated/ui/components/toast/undo-toast.d.ts +6 -1
  67. package/types/generated/ui/components/waveform/waveform.d.ts +4 -1
  68. package/types/generated/ui/components/xc-export-modal/xc-export-modal.d.ts +5 -0
  69. package/types/generated/ui/mobile/i18n.d.ts +133 -0
  70. package/types/generated/ui/mobile/mobile-app.d.ts +272 -0
  71. package/types/generated/ui/mobile/thumb.d.ts +11 -0
  72. package/types/generated/ui/panels/birdbox-panel.d.ts +75 -0
  73. package/types/generated/ui/panels/birdnet-panel.d.ts +36 -4
  74. package/types/generated/ui/panels/label-list.d.ts +14 -0
  75. package/types/generated/ui/panels/mode-tiles.d.ts +7 -0
  76. package/types/generated/ui/panels/model-picker.d.ts +11 -0
  77. package/types/generated/ui/panels/recording-explorer.d.ts +2 -0
  78. package/types/generated/ui/panels/sidebar.d.ts +11 -1
  79. package/types/generated/ui/panels/similar-panel.d.ts +29 -0
  80. package/types/generated/ui/panels/species-lists-panel.d.ts +58 -0
  81. package/types/generated/ui/panels/xc-panel.d.ts +10 -0
@@ -6,6 +6,8 @@ export interface WaveformRendererDeps {
6
6
  waveformContent: HTMLElement | null;
7
7
  overviewCanvas: HTMLCanvasElement | null;
8
8
  overviewContainer: HTMLElement | null;
9
+ overviewDetailCanvas?: HTMLCanvasElement | null;
10
+ overviewDetail?: HTMLElement | null;
9
11
  freqLabels: HTMLElement | null;
10
12
  amplitudeLabels: HTMLElement | null;
11
13
  };
@@ -31,6 +33,14 @@ export declare class WaveformRenderer {
31
33
  #private;
32
34
  constructor(deps: WaveformRendererDeps);
33
35
  drawMainWaveform(): void;
36
+ /**
37
+ * Detail strip below the overview (long recordings): always a waveform,
38
+ * since the overview spectrogram is a whole-file image. null = hidden.
39
+ */
40
+ drawOverviewDetail(range?: {
41
+ startNorm: number;
42
+ endNorm: number;
43
+ } | null): void;
34
44
  drawOverviewWaveform(): void;
35
45
  /** A new file is loading: the old spectrogram image must not stay on screen. */
36
46
  resetOverview(): void;
@@ -41,6 +41,8 @@ export declare function defaultRecordingEntry(partial?: {}): {
41
41
  /** When true, activateRecordingEntry will re-import XC labels on next switch */
42
42
  needsXcImport: boolean;
43
43
  path: any;
44
+ /** When the entry was created (fallback date for lists). */
45
+ addedAt: string;
44
46
  };
45
47
  export declare class RecordingManager extends EventTarget {
46
48
  _entries: any;
@@ -0,0 +1,11 @@
1
+ import type { BandSpectrogram } from '../domain/similar/ncc.ts';
2
+ export interface BandOptions {
3
+ /** Called between blocks; return a promise to yield to the UI. */
4
+ yieldEvery?: () => Promise<void> | void;
5
+ /** Stops early when it returns true. */
6
+ cancelled?: () => boolean;
7
+ }
8
+ /** bandSpectrogram() on raw channels with a given aw-dsp instance (also used inside the search worker). */
9
+ export declare function bandSpectrogramOf(wasm: {
10
+ WasmStft: any;
11
+ }, channels: Float32Array[], length: number, sr: number, loHz: number, hiHz: number, opts?: BandOptions): Promise<BandSpectrogram | null>;
@@ -0,0 +1,34 @@
1
+ import { type BandOptions } from './similarBand.ts';
2
+ import type { CallPatch } from '../domain/similar/cluster.ts';
3
+ import { type CallTemplate, type BandSpectrogram, type Box, type FindOptions, type SimilarHit } from '../domain/similar/ncc.ts';
4
+ export type { BandOptions } from './similarBand.ts';
5
+ /** Spectrogram rows covering loHz..hiHz of the whole recording, or null before aw-dsp is ready / when cancelled. */
6
+ export declare function bandSpectrogram(audio: AudioBuffer, loHz: number, hiHz: number, opts?: BandOptions): Promise<BandSpectrogram | null>;
7
+ export declare class SimilarSession {
8
+ private worker;
9
+ private local;
10
+ private seq;
11
+ private disposed;
12
+ private readonly pending;
13
+ private call;
14
+ /** Hits for `exemplar`, best first. `spec` is consumed. */
15
+ find(spec: BandSpectrogram, exemplar: Box | {
16
+ template: CallTemplate;
17
+ }, opts?: FindOptions): Promise<SimilarHit[]>;
18
+ /**
19
+ * Hits for `exemplar` in loHz..hiHz of `audio`; the spectrogram is computed in the worker too,
20
+ * so a long recording does not stall the page. null: aw-dsp not ready or recording too short.
21
+ */
22
+ findInAudio(audio: AudioBuffer, loHz: number, hiHz: number, exemplar: Box | {
23
+ template: CallTemplate;
24
+ }, opts?: FindOptions): Promise<SimilarHit[] | null>;
25
+ private start;
26
+ /** Record a decision on hit i (`moved`: box centre corrected by dt s / df Hz); ranks of all hits (decided ones −Infinity). */
27
+ decide(i: number, accepted: boolean, moved?: {
28
+ dt: number;
29
+ df: number;
30
+ }): Promise<Float64Array>;
31
+ dispose(): void;
32
+ }
33
+ /** One patch per box (null where the box is empty or outside the recording); null before aw-dsp is ready. */
34
+ export declare function callPatches(audio: AudioBuffer, boxes: Box[], opts?: BandOptions): Promise<(CallPatch | null)[] | null>;
@@ -0,0 +1,56 @@
1
+ import { type Box, type SimilarHit } from '../domain/similar/ncc.ts';
2
+ export declare const SIMILAR_ORIGIN = "Similar";
3
+ export interface SimilarRecord {
4
+ sourceLabelId: string;
5
+ score: number;
6
+ sources: string[];
7
+ /** suggestionKey() of the correlation hit: recorded on reject, checked on the next search. */
8
+ key?: string;
9
+ /** Box as suggested (BirdBox may have refined the hit); base for carrying corrections over. */
10
+ found?: Box;
11
+ /** Box as last shown (found, or moved by carried-over corrections); differs once the user edits it. */
12
+ shown?: Box;
13
+ /** The correlation hit itself: re-ranking measures where a corrected call sits from here. */
14
+ hit?: Box;
15
+ /** The suggestion under review: highlighted and resizable. */
16
+ active?: boolean;
17
+ }
18
+ /** Edge moves of one box against another. */
19
+ export interface BoxCorrection {
20
+ start: number;
21
+ end: number;
22
+ freqMin: number;
23
+ freqMax: number;
24
+ }
25
+ /** The user edited this suggestion: its box differs from the one shown (carried-over moves are not edits). */
26
+ export declare function userEdited(l: any): boolean;
27
+ /** The user's correction against the box as found (null: not edited by the user). */
28
+ export declare function correctionOf(l: any): BoxCorrection | null;
29
+ /** For re-ranking: how far the centre of a user-corrected box is from its correlation hit (undefined: not edited). */
30
+ export declare function hitMove(l: any): {
31
+ dt: number;
32
+ df: number;
33
+ } | undefined;
34
+ /** Mean of corrections; applied to suggestions not looked at yet (the same systematic offset). */
35
+ export declare function meanCorrection(list: BoxCorrection[]): BoxCorrection | null;
36
+ /** `box` moved by `d`, kept inside the recording (0..duration, 0..nyquist) with a minimum size. */
37
+ export declare function applyCorrection(box: Box, d: BoxCorrection, nyquist?: number, duration?: number): Box;
38
+ /** Identity of a suggestion for "rejected, don't propose again". */
39
+ export declare function suggestionKey(species: string, start: number): string;
40
+ export interface BuildOptions {
41
+ /** All labels of the recording (own, detections, earlier suggestions). */
42
+ labels: any[];
43
+ /** BirdBox's boxes of the recording. */
44
+ boxes?: Box[];
45
+ /** suggestionKey()s rejected before. */
46
+ rejected?: Set<string>;
47
+ setId: string;
48
+ recordingId?: string | null;
49
+ newId: () => string;
50
+ /** Told which hit (index in `hits`) each suggestion came from. */
51
+ onPick?: (suggestion: any, hitIndex: number) => void;
52
+ }
53
+ /** Suggestion labels for `hits` of `exemplar`, best first. */
54
+ export declare function buildSuggestions(exemplar: any, hits: SimilarHit[], opts: BuildOptions): any[];
55
+ /** Rows computed for the search: the exemplar's band plus room for the margin and frequency shift. */
56
+ export declare function searchBand(exemplar: Box, sampleRate: number): [number, number];
@@ -1,6 +1,6 @@
1
1
  import { LabelEditorModal } from '../ui/components/label-editor/LabelEditorModal.ts';
2
2
  import type { SpectrogramLabel } from '../shared/label.types.ts';
3
- import { type SnapResult } from './snapToCall.ts';
3
+ import { type SnapBoxSource, type SnapResult } from './snapToCall.ts';
4
4
  export declare function parseColorToRgb(color: unknown): {
5
5
  r: number;
6
6
  g: number;
@@ -92,6 +92,30 @@ declare class AnnotationLayerBase extends EventTarget {
92
92
  _emitUpdate(_item: any): void;
93
93
  /** Render the overlay. Override in subclasses; default no-op for base typing. */
94
94
  render(): void;
95
+ /** Element per item id from the last render(), and the signature/geometry it was built for. */
96
+ _elById: Map<string, HTMLElement>;
97
+ _elState: WeakMap<HTMLElement, {
98
+ sig: string;
99
+ geo: string;
100
+ }>;
101
+ /**
102
+ * Keyed DOM update: an item keeps its element while `signature` is unchanged; if only `geometry`
103
+ * changed (zoom, scroll, layout) the element is re-placed. Every other overlay child is removed,
104
+ * as the former `innerHTML = ''` did, and DOM order follows `items`.
105
+ * `create` must return a fully placed element.
106
+ */
107
+ _reconcile<T extends {
108
+ id: string;
109
+ }>(items: T[], spec: {
110
+ signature: (item: T) => string;
111
+ geometry: (item: T) => string;
112
+ create: (item: T) => HTMLElement;
113
+ place: (el: HTMLElement, item: T) => void;
114
+ }): HTMLElement[];
115
+ /** An element was changed outside render() (drag, resize): rebuild it on the next render. */
116
+ _forgetElement(el: HTMLElement | null | undefined): void;
117
+ /** Signature of an item plus display flags; createdAt/updatedAt are not shown and change on every set(). */
118
+ _signature(item: unknown, ...flags: unknown[]): string;
95
119
  attach(player: unknown): void;
96
120
  detach(): void;
97
121
  add(item: Record<string, unknown>): void;
@@ -104,6 +128,15 @@ declare class AnnotationLayerBase extends EventTarget {
104
128
  setLockedIds(ids?: string[]): void;
105
129
  toggleMultiSelected(id: string): void;
106
130
  _updateMultiSelectedVisual(): void;
131
+ /**
132
+ * Escape during a drag/resize: put the item back where it started and end the interaction.
133
+ * Nothing is committed (no update event); the preview event resets the other layer.
134
+ */
135
+ _cancelEditInteraction(): void;
136
+ /** Live position during an interaction (the player mirrors it to the other layer). */
137
+ _emitPreview(_item: any): void;
138
+ /** Interaction over: the player drops the live highlight on the mirrored label. */
139
+ _emitPreviewEnd(id: string): void;
107
140
  _finishEditInteraction(): void;
108
141
  }
109
142
  export declare class AnnotationLayer extends AnnotationLayerBase {
@@ -150,6 +183,7 @@ export declare class AnnotationLayer extends AnnotationLayerBase {
150
183
  _bindInteractions(root: HTMLElement): void;
151
184
  _emitCreate(region: any): void;
152
185
  _emitUpdate(item: any): void;
186
+ _emitPreview(item: any): void;
153
187
  /** Public alias for the internal items array (backward compat). */
154
188
  get annotations(): any;
155
189
  highlightActiveRegion(currentTime: number): void;
@@ -172,6 +206,7 @@ export declare class AnnotationLayer extends AnnotationLayerBase {
172
206
  confidence: any;
173
207
  color: string;
174
208
  readonly: boolean;
209
+ origin: any;
175
210
  aiSuggested: any;
176
211
  recordingId: any;
177
212
  };
@@ -202,10 +237,25 @@ export declare class SpectrogramLabelLayer extends AnnotationLayerBase {
202
237
  /** Snap to call: click a call → preview box, Shift+wheel = sensitivity, click/Enter = commit. */
203
238
  snapMode: boolean;
204
239
  _snapSensitivity: number;
240
+ /**
241
+ * Detector boxes for Snap (BirdBox): asked first; without a box under the click the
242
+ * signal-based region growing answers. Null: Snap uses the signal only.
243
+ */
244
+ snapBoxSource: SnapBoxSource | null;
245
+ _snapBoxConf: number;
246
+ /** `source`: who drew the box; `tune`: what Shift+wheel changes for this click. */
247
+ /** The point of the last snap, kept apart from its result for refreshSnap. */
248
+ _snapAt: {
249
+ time: number;
250
+ freq: number;
251
+ } | null;
205
252
  _snap: {
206
253
  time: number;
207
254
  freq: number;
208
255
  result: SnapResult;
256
+ source: 'detector' | 'signal';
257
+ tune: 'conf' | 'sensitivity';
258
+ detector: boolean;
209
259
  } | null;
210
260
  _snapEl: HTMLElement | null;
211
261
  /** Zoom box ("Lupe"): drag a field → 'zoomboxselect', right-click → 'zoomboxback'. */
@@ -250,6 +300,12 @@ export declare class SpectrogramLabelLayer extends AnnotationLayerBase {
250
300
  _bindInteractions(root: HTMLElement): void;
251
301
  _emitCreate(region: any): void;
252
302
  _emitUpdate(item: any): void;
303
+ /** Bands as given to set(), before _normalize clamps them to the display maximum. */
304
+ _storedBands: Map<string, {
305
+ freqMin: number;
306
+ freqMax: number;
307
+ }>;
308
+ _emitPreview(item: any): void;
253
309
  /** Public alias for the internal items array (backward compat). */
254
310
  get labels(): SpectrogramLabel[];
255
311
  set labels(v: SpectrogramLabel[]);
@@ -278,6 +334,7 @@ export declare class SpectrogramLabelLayer extends AnnotationLayerBase {
278
334
  author: string;
279
335
  tags: Record<string, string>;
280
336
  readonly: boolean;
337
+ reviewing?: boolean;
281
338
  aiSuggested: any;
282
339
  recordingId: any;
283
340
  createdAt: any;
@@ -306,7 +363,28 @@ export declare class SpectrogramLabelLayer extends AnnotationLayerBase {
306
363
  * frequency). Shift its name into the visible part, staying inside the box.
307
364
  */
308
365
  _pinLabelText(el: HTMLElement): void;
366
+ /** Pins every name. Reads all layout first, then writes: one reflow instead of one per label. */
309
367
  _pinAllLabelTexts(): void;
368
+ _pinView(): {
369
+ viewL: number;
370
+ viewR: number;
371
+ viewH: number;
372
+ } | null;
373
+ /** Layout reads only (no writes), so measuring many labels in a row costs a single reflow. */
374
+ _measurePin(el: HTMLElement, { viewL, viewR, viewH }: {
375
+ viewL: number;
376
+ viewR: number;
377
+ viewH: number;
378
+ }): {
379
+ dx: number;
380
+ dy: number;
381
+ inside: boolean;
382
+ };
383
+ _applyPin(el: HTMLElement, { dx, dy, inside }: {
384
+ dx: number;
385
+ dy: number;
386
+ inside: boolean;
387
+ }): void;
310
388
  _textPinScrollBound: HTMLElement | null;
311
389
  _textPinRaf: number;
312
390
  _bindTextPinScroll(): void;
@@ -323,6 +401,13 @@ export declare class SpectrogramLabelLayer extends AnnotationLayerBase {
323
401
  width: number;
324
402
  height: number;
325
403
  }): void;
404
+ /** Position + size classes only; no layout reads. */
405
+ _setGeometry(el: HTMLElement, geometry: {
406
+ left: number;
407
+ top: number;
408
+ width: number;
409
+ height: number;
410
+ }): void;
326
411
  /** Lane of each full-band label in 'lanes' display (empty in other modes). */
327
412
  _lanes: Map<string, number>;
328
413
  /**
@@ -342,12 +427,17 @@ export declare class SpectrogramLabelLayer extends AnnotationLayerBase {
342
427
  _updateStampGhost(clientX: number, clientY: number): void;
343
428
  /** Exit stamp mode and clean up ghost. */
344
429
  exitStampMode(): void;
345
- /** Box the call at (time, freq); widens the analysed span while the call reaches its edge. */
430
+ /**
431
+ * Box the call at (time, freq): the detector's box under the click if there is one,
432
+ * else region growing on the signal (widens the analysed span while the call reaches its edge).
433
+ */
346
434
  _runSnap(time: number, freq: number): void;
435
+ /** Snap again at the last point (e.g. once the detector's rows for it arrived). */
436
+ refreshSnap(): void;
347
437
  _renderSnapPreview(): void;
348
438
  _clearSnap(): void;
349
439
  _snapContains(clientX: number, clientY: number): boolean;
350
- _commitSnap(): void;
440
+ _commitSnap(forcePicker?: boolean): void;
351
441
  exitSnapMode(): void;
352
442
  exitZoomBoxMode(): void;
353
443
  _clearZoomBox(): void;
@@ -371,13 +461,21 @@ export declare class SpectrogramLabelLayer extends AnnotationLayerBase {
371
461
  author: string;
372
462
  tags: Record<string, string>;
373
463
  readonly: boolean;
464
+ reviewing?: boolean;
374
465
  aiSuggested: any;
375
466
  recordingId: any;
376
467
  createdAt: any;
377
468
  updatedAt?: any;
378
469
  };
379
470
  _clearDraft(): void;
380
- _openNewLabelPicker(region: any): void;
471
+ /**
472
+ * Name a freshly drawn / snapped region. With a species in the label template the
473
+ * label is added at once (species + template tags); otherwise, or with
474
+ * `forcePicker` (Alt held), the dialog opens, pre-filled from the template.
475
+ */
476
+ _openNewLabelPicker(region: any, { forcePicker }?: {
477
+ forcePicker?: boolean;
478
+ }): void;
381
479
  _startEditInteraction(labelId: any, mode: any, clientX: number, clientY: number, element: any): void;
382
480
  _updateEditInteraction(clientX: number, clientY: number): void;
383
481
  _editLoupeEnabled(): boolean;
@@ -464,6 +562,7 @@ export declare class SpectrogramLabelLayer extends AnnotationLayerBase {
464
562
  author: string;
465
563
  tags: Record<string, string>;
466
564
  readonly: boolean;
565
+ reviewing?: boolean;
467
566
  aiSuggested: any;
468
567
  recordingId: any;
469
568
  createdAt: any;
@@ -0,0 +1,142 @@
1
+ export declare const SAMPLE_RATE = 32000;
2
+ export declare const CLIP_SECONDS = 3;
3
+ export declare const CLIP_SAMPLES: number;
4
+ export declare const HOP_SAMPLES: number;
5
+ export declare const HOP_SECONDS: number;
6
+ /** A window owns its boxes up to here (see fusion.ts). */
7
+ export declare const OWNED_UNTIL: number;
8
+ /** Column 0 counts the windows of each minute, as in the graph. */
9
+ export declare const SEGMENT_CLIPS: number;
10
+ export declare const N_MELS = 256, HOP_LENGTH = 375, N_FFT = 2048, CLIP_FRAMES = 252;
11
+ /** 128 frames from one window to the next. */
12
+ export declare const WINDOW_FRAMES: number;
13
+ /** Audio the graph mirrors in front of the file: 0.5 s. */
14
+ export declare const LEFT_PAD = 16000;
15
+ /** FLOOR_PERCENTILE / 100 in BirdBox's onnx_export.py, in float32. */
16
+ export declare const FLOOR_FRACTION: number;
17
+ /** File end of rows (column 8) while the recording is still growing. */
18
+ export declare const NO_END = 1000000000;
19
+ /** Windows whose rows are final in a recording of n samples: the audio has reached their end. */
20
+ export declare const readyWindows: (n: number) => number;
21
+ /** Samples the graph pads n samples to: the end of the last window. */
22
+ export declare const paddedLength: (n: number) => number;
23
+ /** Windows in a recording of n samples. */
24
+ export declare const windowCount: (n: number) => number;
25
+ /** File end of rows (column 8) for a recording of n samples: where its last window ends. */
26
+ export declare const fileEnd: (n: number) => number;
27
+ /** Seconds up to which every window that owns a box has been seen, after `windows` windows. */
28
+ export declare const analyzedTo: (windows: number) => number;
29
+ /** Samples for the stream: read(from, to) gives (or resolves to) samples from..to-1, reads move forward. */
30
+ export interface SampleSource {
31
+ readonly length: number;
32
+ read(from: number, to: number): Float32Array | Promise<Float32Array>;
33
+ /** The samples before `before` are done with. */
34
+ release?(before: number): void;
35
+ }
36
+ export declare const sourceOf: (samples: Float32Array | SampleSource) => SampleSource;
37
+ /** Samples from..to-1 of a source, and silence after its end, as the graph pads the file. */
38
+ export declare function readPadded(source: SampleSource, from: number, to: number): Promise<Float32Array>;
39
+ /**
40
+ * A recording handed out a block at a time: ask(from, to) asks for samples
41
+ * from..to-1, receive({ from, data }) takes them when they come. The next block
42
+ * is asked for while half of the last one is still to be read, and samples
43
+ * released are dropped, so only a few blocks are held at any time (a worker
44
+ * need not hold a copy of the whole file). A first read past the start skips
45
+ * the samples before it (a run resumed at a later window). cancel() rejects a
46
+ * pending read and every later one, so a stopped run can unwind.
47
+ */
48
+ export declare class BlockSource implements SampleSource {
49
+ readonly length: number;
50
+ private readonly ask;
51
+ private readonly block;
52
+ private base;
53
+ private data;
54
+ private keep;
55
+ private asked;
56
+ private waiting;
57
+ private failure;
58
+ constructor(length: number, ask: (from: number, to: number) => void, block?: number);
59
+ get end(): number;
60
+ read(from: number, to: number): Promise<Float32Array>;
61
+ release(before: number): void;
62
+ /** Stop serving reads: a pending read and all later ones reject with `reason`. */
63
+ cancel(reason: Error): void;
64
+ private askNext;
65
+ /** A block; the samples let go of are dropped. */
66
+ receive({ from, data }: {
67
+ from: number;
68
+ data: Float32Array;
69
+ }): void;
70
+ }
71
+ /** Spectrogram frames from frame `base` on, band by band (n_mels, frames) as the graph wants them. */
72
+ export declare class Frames {
73
+ readonly bands: number;
74
+ cap: number;
75
+ db: Float32Array<ArrayBuffer>;
76
+ sound: Uint8Array<ArrayBuffer>;
77
+ base: number;
78
+ count: number;
79
+ rolling: RollingFloor | null;
80
+ constructor(bands?: number);
81
+ get end(): number;
82
+ /** Forget the frames before `frame`. */
83
+ drop(frame: number): void;
84
+ /** Append n frames of a (bands, n) block. */
85
+ append(db: Float32Array, sound: ArrayLike<number> & {
86
+ subarray?: unknown;
87
+ }, n: number): void;
88
+ /** Frames from..to-1, as new arrays. */
89
+ slice(from: number, to: number): {
90
+ db: Float32Array;
91
+ sound: Uint8Array;
92
+ n: number;
93
+ };
94
+ }
95
+ /**
96
+ * Each window's noise floor as the detect graph takes it (log_floor in
97
+ * onnx_export.py): per band, the FLOOR_FRACTION percentile of the frames of its
98
+ * floor window that hold sound (all of them if none does), interpolated in
99
+ * float32 between two sorted values. The frames are kept sorted per band, and
100
+ * from one window to the next only the frames that leave and arrive (128 of
101
+ * about 5,100) are merged in. Bit for bit the graph's values (BirdBox
102
+ * tests/js/demo_chunk_parity.mjs).
103
+ */
104
+ export declare class RollingFloor {
105
+ private readonly bands;
106
+ private lo;
107
+ private hi;
108
+ private count;
109
+ private cap;
110
+ private sorted;
111
+ private spare;
112
+ constructor(bands?: number);
113
+ /**
114
+ * The floor of frames lo..hi-1 into out[b * windows + i] for every band b.
115
+ * Windows come in order; the frames from the last call's lo on must still be in `frames`.
116
+ */
117
+ at(frames: Frames, lo: number, hi: number, out: Float32Array, i: number, windows: number): void;
118
+ private room;
119
+ /** Sort the frames with sound of lo..hi-1 anew. */
120
+ private fill;
121
+ /** Move to lo..hi-1: take out the frames before lo, merge in those from the last hi on. */
122
+ private slide;
123
+ }
124
+ export interface FrameGrid {
125
+ /** Sample of frame 0 relative to the file start (negative: inside the left pad). */
126
+ frameOrigin: number;
127
+ /** Samples before a window's end its floor window starts. */
128
+ floorWindowSamples: number;
129
+ }
130
+ /** First frame of window w's floor window. */
131
+ export declare const floorFirstFrame: (w: number, g: FrameGrid) => number;
132
+ /** Last frame window w needs. */
133
+ export declare const lastFrame: (w: number) => number;
134
+ /**
135
+ * Rows of one network run as the file's graph gives them: column 0 numbered per minute,
136
+ * boxes past the file's content clipped (the graph padded only silence), column 8 the
137
+ * file end. In a recording in progress (`samples` null) the file end is NO_END.
138
+ */
139
+ export declare function finishRows(data: Float32Array, rows: number, samples: number | null): {
140
+ data: Float32Array;
141
+ rows: number;
142
+ };
@@ -0,0 +1,17 @@
1
+ import { type FusedBox, type FusionCache } from './fusion.ts';
2
+ /** Fusion caches per confidence; fuseBoxes checks that the rows still match. */
3
+ export type BoxUnderCache = Map<number, FusionCache>;
4
+ /**
5
+ * The most confident fused box containing (time, freq) at confidence `conf`.
6
+ * `weaker`: none at `conf`, but one at `minConf` (the lowest confidence the rows hold).
7
+ */
8
+ export declare function boxUnder(raw: Float32Array, rows: number, time: number, freq: number, { conf, gap, minConf, later, cache }: {
9
+ conf: number;
10
+ gap: number;
11
+ minConf: number;
12
+ later?: number;
13
+ cache?: BoxUnderCache;
14
+ }): {
15
+ box: FusedBox | null;
16
+ weaker: boolean;
17
+ };
@@ -0,0 +1,50 @@
1
+ /** Columns of one raw row: clip, t0, t1, fLo, fHi, score, class, clip start, file end. */
2
+ export declare const RAW_COLS = 9;
3
+ export interface FusionModel {
4
+ /** Window length in seconds. */
5
+ clip: number;
6
+ /** Fraction of the window cut off at each end for ownership (BirdBox: 1/4). */
7
+ ownMargin: number;
8
+ wbfIou: number;
9
+ /** Overlap (s) that links boxes when the phrase gap is 0. */
10
+ joinOverlap: number;
11
+ joinFreqIou: number;
12
+ nestedRatio: number;
13
+ }
14
+ /** BirdBox Just-Bird / Birds-With-Labels (fusion models). */
15
+ export declare const BIRDBOX_FUSION: FusionModel;
16
+ /** A fused box. Times in s, frequencies in Hz. */
17
+ export interface FusedBox {
18
+ t0: number;
19
+ t1: number;
20
+ flo: number;
21
+ fhi: number;
22
+ /** Score averaged over the raw boxes behind it. */
23
+ avg: number;
24
+ max: number;
25
+ /** Number of raw boxes behind it. */
26
+ n: number;
27
+ cls: number;
28
+ }
29
+ /** Kept between calls while detection runs; start with `{}`. */
30
+ export interface FusionCache {
31
+ key?: string;
32
+ rows?: number;
33
+ songs?: FusedBox[];
34
+ raw?: Float32Array;
35
+ }
36
+ /**
37
+ * Boxes for one (confidence, phrase gap) setting.
38
+ *
39
+ * While detection runs, pass a `cache` (kept from one call to the next) and `later`,
40
+ * the earliest start of a box in rows still to come (the start of the next window).
41
+ * Parts no later row can reach are kept, and the next call only fuses the rows after
42
+ * them. The cache holds while its rows, the confidence and the phrase gap stay the
43
+ * same (a recording that becomes its file changes the rows).
44
+ *
45
+ * @param raw raw rows, RAW_COLS columns each
46
+ * @param conf boxes must score above it
47
+ * @param phraseGap seconds; 0 keeps call-level boxes
48
+ * @param later seconds; Infinity when no more rows come
49
+ */
50
+ export declare function fuseBoxes(raw: Float32Array, rows: number, conf: number, phraseGap: number, cache?: FusionCache | null, later?: number, model?: FusionModel): FusedBox[];
@@ -0,0 +1,47 @@
1
+ import type { BoxUnderCache } from './boxUnder.ts';
2
+ /** Seconds around a snap click that a stretch covers: a call and its phrase. */
3
+ export declare const NEAR_SECONDS = 6;
4
+ export interface NearRows {
5
+ data: Float32Array;
6
+ rows: number;
7
+ next: number;
8
+ analyzedTo: number;
9
+ done: boolean;
10
+ }
11
+ interface Stretch {
12
+ t0: number;
13
+ t1: number;
14
+ raw: NearRows;
15
+ cache: BoxUnderCache;
16
+ }
17
+ export interface NearbyOptions<B> {
18
+ /** 32 kHz mono of a recording's audio (done once per recording and buffer). */
19
+ prepare: (buf: B) => Promise<Float32Array>;
20
+ /** Rows of windows from … to-1. */
21
+ detect: (pcm: Float32Array, from: number, to: number) => Promise<NearRows>;
22
+ }
23
+ /** Windows that cover `time` ± NEAR_SECONDS (window w: w·1.5 s … w·1.5 s + 3 s). */
24
+ export declare function nearWindows(time: number): {
25
+ from: number;
26
+ to: number;
27
+ };
28
+ /** Whether a run's rows hold the seconds around `time`: a stopped run's only up to analyzedTo. */
29
+ export declare function runCovers(raw: {
30
+ analyzedTo: number;
31
+ }, stopped: boolean, time: number): boolean;
32
+ export declare class NearbyRows<B> {
33
+ private readonly stretches;
34
+ private pending;
35
+ /** Bumped by forget/forgetAll: a detection started before keeps nothing. */
36
+ private epoch;
37
+ private pcm;
38
+ private readonly o;
39
+ constructor(o: NearbyOptions<B>);
40
+ /** The stretch of a recording that holds `time`. */
41
+ at(id: string, time: number): Stretch | null;
42
+ /** Detect the stretch around `time`; one at a time (a second call gets the running one). False if nothing was kept. */
43
+ detect(id: string, buf: B, time: number): Promise<boolean>;
44
+ forget(id: string): void;
45
+ forgetAll(): void;
46
+ }
47
+ export {};
@@ -0,0 +1,45 @@
1
+ export declare const HAND_MS = 600;
2
+ export interface PacerOptions<Timer> {
3
+ /** Clock in ms (tests pass a simulated one). */
4
+ now?: () => number;
5
+ later?: (fn: () => void, ms: number) => Timer;
6
+ cancel?: (timer: Timer | null) => void;
7
+ tune?: {
8
+ handMs?: number;
9
+ follow?: number;
10
+ correct?: number;
11
+ };
12
+ }
13
+ export declare class Pacer<T, Timer = ReturnType<typeof setTimeout>> {
14
+ private readonly show;
15
+ private readonly now;
16
+ private readonly later;
17
+ private readonly cancel;
18
+ private readonly handMs;
19
+ private readonly follow;
20
+ private readonly correct;
21
+ private queue;
22
+ private mean;
23
+ private lastIn;
24
+ private lastGap;
25
+ private count;
26
+ private minStep;
27
+ private timer;
28
+ private idle;
29
+ private started;
30
+ private ending;
31
+ private finished;
32
+ /** @param show draws the last item of a step */
33
+ constructor(show: (item: T) => void, opts?: PacerOptions<Timer>);
34
+ /** Windows held back. Before the mean is known: what the first windows took, at least two. */
35
+ private get inHand();
36
+ /** Windows per step: a redraw at most every minStep ms. */
37
+ private get size();
38
+ /** A window is done. The first does not count towards the mean: it also waits for the first frames. */
39
+ push(item: T): void;
40
+ /** Resolves once the last window is shown. */
41
+ finish(): Promise<void>;
42
+ /** Drop what is in hand: the run was stopped or replaced. */
43
+ stop(): void;
44
+ private step;
45
+ }
@@ -0,0 +1,12 @@
1
+ /**
2
+ * Frequency band to bandpass a label's playback with, or null when the label has none.
3
+ * Full-band labels carry numeric bounds after normalization (0 … Nyquist) but no real band.
4
+ */
5
+ export declare function labelPlaybackBand(label: {
6
+ freqMin?: number | null;
7
+ freqMax?: number | null;
8
+ fullBand?: boolean;
9
+ }): {
10
+ lo: number;
11
+ hi: number;
12
+ } | null;