streaming-sortformer-node 0.1.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.
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Sortformer.js","sourceRoot":"","sources":["../src/Sortformer.ts"],"names":[],"mappings":"AAAA;;GAEG;AAGH,OAAO,EAAE,eAAe,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAC/D,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC1C,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AAEzD;;;;;;;;;;;;;GAaG;AACH,MAAM,OAAO,UAAU;IAIrB;;;OAGG;IACH,YAAoB,MAAW;QANvB,WAAM,GAAY,KAAK,CAAC;QAO9B,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;IACvB,CAAC;IAED;;;;;;;;;;;;OAYG;IACH,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,SAAiB,EAAE,OAAqB;QACxD,iBAAiB;QACjB,IAAI,CAAC,SAAS,IAAI,OAAO,SAAS,KAAK,QAAQ,EAAE,CAAC;YAChD,MAAM,IAAI,SAAS,CAAC,sCAAsC,CAAC,CAAC;QAC9D,CAAC;QAED,qBAAqB;QACrB,MAAM,OAAO,GAAG,UAAU,EAAE,CAAC;QAE7B,+BAA+B;QAC/B,wCAAwC;QACxC,MAAM,OAAO,GAAG,OAAO,EAAE,OAAO,IAAI,CAAC,CAAC;QAEtC,IAAI,OAAO,GAAG,CAAC,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,OAAO,CAAC,EAAE,CAAC;YAC9C,MAAM,IAAI,KAAK,CAAC,oCAAoC,CAAC,CAAC;QACxD,CAAC;QAED,2BAA2B;QAC3B,MAAM,MAAM,GAAG,IAAI,OAAO,CAAC,eAAe,CAAC,SAAS,EAAE,OAAO,CAAC,CAAC;QAE/D,OAAO,IAAI,UAAU,CAAC,MAAM,CAAC,CAAC;IAChC,CAAC;I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AAM,SAAS,GAAoC;YACjD,KAAK,EAAE,CAAC,EAAG,gCAAgC;YAC3C,IAAI,EAAE,CAAC,EAAI,uBAAuB;YAClC,IAAI,EAAE,CAAC,EAAI,uBAAuB;YAClC,IAAI,EAAE,CAAC,EAAI,uBAAuB;SACnC,CAAC;QAEF,MAAM,SAAS,GAAG,SAAS,CAAC,MAAM,CAAC,CAAC;QACpC,IAAI,SAAS,KAAK,SAAS,EAAE,CAAC;YAC5B,MAAM,IAAI,KAAK,CAAC,mBAAmB,MAAM,EAAE,CAAC,CAAC;QAC/C,CAAC;QAED,wCAAwC;QACxC,MAAM,OAAO,GAAG,UAAU,EAAE,CAAC;QAC7B,MAAM,aAAa,GAAG,IAAI,OAAO,CAAC,gBAAgB,CAAC,IAAI,CAAC,MAAM,EAAE,SAAS,CAAC,CAAC;QAE3E,OAAO,IAAI,gBAAgB,CAAC,aAAa,CAAC,CAAC;IAC7C,CAAC;CACF"}
@@ -0,0 +1,88 @@
1
+ /**
2
+ * TypeScript wrapper for native StreamingSession
3
+ */
4
+ import type { FeedResult } from './types.js';
5
+ /**
6
+ * Streaming diarization session
7
+ *
8
+ * Maintains state across incremental audio feed calls for true real-time
9
+ * speaker diarization. State is kept in native C code for efficiency.
10
+ *
11
+ * @example
12
+ * ```typescript
13
+ * const session = model.createStreamingSession({ preset: '2s' });
14
+ *
15
+ * // Feed audio chunks as they arrive
16
+ * const result1 = session.feed(chunk1);
17
+ * const result2 = session.feed(chunk2);
18
+ *
19
+ * // Get total frames processed
20
+ * console.log(session.totalFrames);
21
+ *
22
+ * // Reset for new audio stream
23
+ * session.reset();
24
+ *
25
+ * // Clean up
26
+ * session.close();
27
+ * ```
28
+ */
29
+ export declare class StreamingSession {
30
+ private native;
31
+ private _closed;
32
+ /**
33
+ * Create a new streaming session
34
+ * @param native - Native StreamingSession instance from binding
35
+ * @internal
36
+ */
37
+ constructor(native: any);
38
+ /**
39
+ * Feed audio samples and get predictions for this chunk
40
+ *
41
+ * @param audio - Audio samples as Float32Array (16kHz mono)
42
+ * @returns Predictions for the new frames in this chunk
43
+ * @throws Error if session is closed or audio is invalid
44
+ *
45
+ * @example
46
+ * ```typescript
47
+ * const audio = new Float32Array(48000); // 3 seconds
48
+ * const result = session.feed(audio);
49
+ * console.log(`Got ${result.frameCount} new frames`);
50
+ * ```
51
+ */
52
+ feed(audio: Float32Array): FeedResult;
53
+ /**
54
+ * Flush remaining buffered audio at end of stream
55
+ *
56
+ * Call this when the audio stream ends to process any remaining
57
+ * buffered audio that hasn't been output yet due to latency buffering.
58
+ *
59
+ * @returns Final predictions for buffered audio
60
+ * @throws Error if session is closed
61
+ */
62
+ flush(): FeedResult;
63
+ /**
64
+ * Reset the streaming state for a new audio stream
65
+ *
66
+ * Clears all internal buffers (spkcache, fifo, mel overlap) while
67
+ * keeping the model loaded. Use this when starting a new recording.
68
+ *
69
+ * @throws Error if session is closed
70
+ */
71
+ reset(): void;
72
+ /**
73
+ * Close the session and free native resources
74
+ *
75
+ * After calling close(), the session cannot be used.
76
+ * Calling close() multiple times is safe (idempotent).
77
+ */
78
+ close(): void;
79
+ /**
80
+ * Get total frames output so far
81
+ */
82
+ get totalFrames(): number;
83
+ /**
84
+ * Check if the session is closed
85
+ */
86
+ get isClosed(): boolean;
87
+ }
88
+ //# sourceMappingURL=StreamingSession.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"StreamingSession.d.ts","sourceRoot":"","sources":["../src/StreamingSession.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EAAE,UAAU,EAAmB,MAAM,YAAY,CAAC;AAE9D;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,qBAAa,gBAAgB;IAC3B,OAAO,CAAC,MAAM,CAAM;IACpB,OAAO,CAAC,OAAO,CAAkB;IAEjC;;;;OAIG;gBACS,MAAM,EAAE,GAAG;IAIvB;;;;;;;;;;;;;OAaG;IACH,IAAI,CAAC,KAAK,EAAE,YAAY,GAAG,UAAU;IAiBrC;;;;;;;;OAQG;IACH,KAAK,IAAI,UAAU;IAanB;;;;;;;OAOG;IACH,KAAK,IAAI,IAAI;IAOb;;;;;OAKG;IACH,KAAK,IAAI,IAAI;IASb;;OAEG;IACH,IAAI,WAAW,IAAI,MAAM,CAKxB;IAED;;OAEG;IACH,IAAI,QAAQ,IAAI,OAAO,CAEtB;CACF"}
@@ -0,0 +1,128 @@
1
+ /**
2
+ * TypeScript wrapper for native StreamingSession
3
+ */
4
+ /**
5
+ * Streaming diarization session
6
+ *
7
+ * Maintains state across incremental audio feed calls for true real-time
8
+ * speaker diarization. State is kept in native C code for efficiency.
9
+ *
10
+ * @example
11
+ * ```typescript
12
+ * const session = model.createStreamingSession({ preset: '2s' });
13
+ *
14
+ * // Feed audio chunks as they arrive
15
+ * const result1 = session.feed(chunk1);
16
+ * const result2 = session.feed(chunk2);
17
+ *
18
+ * // Get total frames processed
19
+ * console.log(session.totalFrames);
20
+ *
21
+ * // Reset for new audio stream
22
+ * session.reset();
23
+ *
24
+ * // Clean up
25
+ * session.close();
26
+ * ```
27
+ */
28
+ export class StreamingSession {
29
+ /**
30
+ * Create a new streaming session
31
+ * @param native - Native StreamingSession instance from binding
32
+ * @internal
33
+ */
34
+ constructor(native) {
35
+ this._closed = false;
36
+ this.native = native;
37
+ }
38
+ /**
39
+ * Feed audio samples and get predictions for this chunk
40
+ *
41
+ * @param audio - Audio samples as Float32Array (16kHz mono)
42
+ * @returns Predictions for the new frames in this chunk
43
+ * @throws Error if session is closed or audio is invalid
44
+ *
45
+ * @example
46
+ * ```typescript
47
+ * const audio = new Float32Array(48000); // 3 seconds
48
+ * const result = session.feed(audio);
49
+ * console.log(`Got ${result.frameCount} new frames`);
50
+ * ```
51
+ */
52
+ feed(audio) {
53
+ if (this._closed) {
54
+ throw new Error('Session is closed');
55
+ }
56
+ if (!(audio instanceof Float32Array)) {
57
+ throw new TypeError('audio must be a Float32Array');
58
+ }
59
+ const result = this.native.feed(audio);
60
+ return {
61
+ predictions: result.predictions,
62
+ frameCount: result.frameCount,
63
+ };
64
+ }
65
+ /**
66
+ * Flush remaining buffered audio at end of stream
67
+ *
68
+ * Call this when the audio stream ends to process any remaining
69
+ * buffered audio that hasn't been output yet due to latency buffering.
70
+ *
71
+ * @returns Final predictions for buffered audio
72
+ * @throws Error if session is closed
73
+ */
74
+ flush() {
75
+ if (this._closed) {
76
+ throw new Error('Session is closed');
77
+ }
78
+ const result = this.native.flush();
79
+ return {
80
+ predictions: result.predictions,
81
+ frameCount: result.frameCount,
82
+ };
83
+ }
84
+ /**
85
+ * Reset the streaming state for a new audio stream
86
+ *
87
+ * Clears all internal buffers (spkcache, fifo, mel overlap) while
88
+ * keeping the model loaded. Use this when starting a new recording.
89
+ *
90
+ * @throws Error if session is closed
91
+ */
92
+ reset() {
93
+ if (this._closed) {
94
+ throw new Error('Session is closed');
95
+ }
96
+ this.native.reset();
97
+ }
98
+ /**
99
+ * Close the session and free native resources
100
+ *
101
+ * After calling close(), the session cannot be used.
102
+ * Calling close() multiple times is safe (idempotent).
103
+ */
104
+ close() {
105
+ if (!this._closed) {
106
+ if (this.native && typeof this.native.close === 'function') {
107
+ this.native.close();
108
+ }
109
+ this._closed = true;
110
+ }
111
+ }
112
+ /**
113
+ * Get total frames output so far
114
+ */
115
+ get totalFrames() {
116
+ if (this._closed) {
117
+ return 0;
118
+ }
119
+ return this.native.getTotalFrames();
120
+ }
121
+ /**
122
+ * Check if the session is closed
123
+ */
124
+ get isClosed() {
125
+ return this._closed;
126
+ }
127
+ }
128
+ //# sourceMappingURL=StreamingSession.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"StreamingSession.js","sourceRoot":"","sources":["../src/StreamingSession.ts"],"names":[],"mappings":"AAAA;;GAEG;AAIH;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,MAAM,OAAO,gBAAgB;IAI3B;;;;OAIG;IACH,YAAY,MAAW;QAPf,YAAO,GAAY,KAAK,CAAC;QAQ/B,IAAI,CAAC,MAA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,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC;QACtB,CAAC;IACH,CAAC;IAED;;OAEG;IACH,IAAI,WAAW;QACb,IAAI,IAAI,CAAC,OAAO,EAAE,CAAC;YACjB,OAAO,CAAC,CAAC;QACX,CAAC;QACD,OAAO,IAAI,CAAC,MAAM,CAAC,cAAc,EAAE,CAAC;IACtC,CAAC;IAED;;OAEG;IACH,IAAI,QAAQ;QACV,OAAO,IAAI,CAAC,OAAO,CAAC;IACtB,CAAC;CACF"}
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Get the native binding for the current platform
3
+ * Detects platform and architecture, loads the appropriate platform-specific package
4
+ * @returns The native module binding
5
+ * @throws Error if platform is not supported or binding cannot be loaded
6
+ */
7
+ export declare function getBinding(): any;
8
+ //# sourceMappingURL=binding.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"binding.d.ts","sourceRoot":"","sources":["../src/binding.ts"],"names":[],"mappings":"AAMA;;;;;GAKG;AACH,wBAAgB,UAAU,IAAI,GAAG,CA4BhC"}
@@ -0,0 +1,35 @@
1
+ import { createRequire } from 'module';
2
+ const require = createRequire(import.meta.url);
3
+ let cachedBinding = null;
4
+ /**
5
+ * Get the native binding for the current platform
6
+ * Detects platform and architecture, loads the appropriate platform-specific package
7
+ * @returns The native module binding
8
+ * @throws Error if platform is not supported or binding cannot be loaded
9
+ */
10
+ export function getBinding() {
11
+ if (cachedBinding)
12
+ return cachedBinding;
13
+ const platform = process.platform;
14
+ const arch = process.arch;
15
+ let packageName;
16
+ if (platform === 'darwin' && arch === 'arm64') {
17
+ packageName = '@streaming-sortformer-node/darwin-arm64';
18
+ }
19
+ else if (platform === 'darwin' && arch === 'x64') {
20
+ packageName = '@streaming-sortformer-node/darwin-x64';
21
+ }
22
+ else {
23
+ throw new Error(`Unsupported platform: ${platform}-${arch}. ` +
24
+ `streaming-sortformer-node currently supports: darwin-arm64, darwin-x64`);
25
+ }
26
+ try {
27
+ cachedBinding = require(packageName);
28
+ return cachedBinding;
29
+ }
30
+ catch (e) {
31
+ throw new Error(`Failed to load native binding from ${packageName}. ` +
32
+ `Make sure the package is installed: npm install ${packageName}`);
33
+ }
34
+ }
35
+ //# sourceMappingURL=binding.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"binding.js","sourceRoot":"","sources":["../src/binding.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,QAAQ,CAAC;AAEvC,MAAM,OAAO,GAAG,aAAa,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AAE/C,IAAI,aAAa,GAAQ,IAAI,CAAC;AAE9B;;;;;GAKG;AACH,MAAM,UAAU,UAAU;IACxB,IAAI,aAAa;QAAE,OAAO,aAAa,CAAC;IAExC,MAAM,QAAQ,GAAG,OAAO,CAAC,QAAQ,CAAC;IAClC,MAAM,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC;IAE1B,IAAI,WAAmB,CAAC;IAExB,IAAI,QAAQ,KAAK,QAAQ,IAAI,IAAI,KAAK,OAAO,EAAE,CAAC;QAC9C,WAAW,GAAG,yCAAyC,CAAC;IAC1D,CAAC;SAAM,IAAI,QAAQ,KAAK,QAAQ,IAAI,IAAI,KAAK,KAAK,EAAE,CAAC;QACnD,WAAW,GAAG,uCAAuC,CAAC;IACxD,CAAC;SAAM,CAAC;QACN,MAAM,IAAI,KAAK,CACb,yBAAyB,QAAQ,IAAI,IAAI,IAAI;YAC7C,wEAAwE,CACzE,CAAC;IACJ,CAAC;IAED,IAAI,CAAC;QACH,aAAa,GAAG,OAAO,CAAC,WAAW,CAAC,CAAC;QACrC,OAAO,aAAa,CAAC;IACvB,CAAC;IAAC,OAAO,CAAC,EAAE,CAAC;QACX,MAAM,IAAI,KAAK,CACb,sCAAsC,WAAW,IAAI;YACrD,mDAAmD,WAAW,EAAE,CACjE,CAAC;IACJ,CAAC;AACH,CAAC"}
@@ -0,0 +1,5 @@
1
+ export { Sortformer } from './Sortformer.js';
2
+ export { StreamingSession } from './StreamingSession.js';
3
+ export type { LoadOptions, DiarizeOptions, DiarizeResult, LatencyPreset, DiarizeMode, StreamingPreset, StreamingSessionOptions, FeedResult, } from './types.js';
4
+ export { LATENCY_PRESETS, OFFLINE_PARAMS } from './presets.js';
5
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAC7C,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AACzD,YAAY,EACV,WAAW,EACX,cAAc,EACd,aAAa,EACb,aAAa,EACb,WAAW,EACX,eAAe,EACf,uBAAuB,EACvB,UAAU,GACX,MAAM,YAAY,CAAC;AACpB,OAAO,EAAE,eAAe,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,4 @@
1
+ export { Sortformer } from './Sortformer.js';
2
+ export { StreamingSession } from './StreamingSession.js';
3
+ export { LATENCY_PRESETS, OFFLINE_PARAMS } from './presets.js';
4
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAC7C,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AAWzD,OAAO,EAAE,eAAe,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC"}
@@ -0,0 +1,45 @@
1
+ /**
2
+ * Latency presets for streaming diarization
3
+ * Maps preset names to their corresponding parameter configurations
4
+ */
5
+ import type { LatencyPreset } from './types';
6
+ /**
7
+ * Streaming latency preset parameters
8
+ * Each preset controls chunk processing, buffering, and speaker cache update behavior
9
+ */
10
+ export interface PresetParams {
11
+ /** Chunk length in frames (16kHz, hop=160) */
12
+ chunkLen: number;
13
+ /** Right context frames for conformer processing */
14
+ rightContext: number;
15
+ /** FIFO buffer length in frames */
16
+ fifoLen: number;
17
+ /** Speaker cache update period in frames */
18
+ spkcacheUpdatePeriod: number;
19
+ }
20
+ /**
21
+ * Streaming latency presets
22
+ * - 'low': ~188ms latency, minimal buffering
23
+ * - '2s': ~2 second latency
24
+ * - '3s': ~3 second latency
25
+ * - '5s': ~5 second latency
26
+ */
27
+ export declare const LATENCY_PRESETS: Record<LatencyPreset, PresetParams>;
28
+ /**
29
+ * Offline mode parameters
30
+ * Used when mode='offline' to process entire audio at once
31
+ */
32
+ export declare const OFFLINE_PARAMS: PresetParams;
33
+ /**
34
+ * Get preset parameters by name
35
+ * @param preset - Latency preset name
36
+ * @returns Preset parameters
37
+ * @throws Error if preset is not found
38
+ */
39
+ export declare function getPresetParams(preset: LatencyPreset): PresetParams;
40
+ /**
41
+ * Get default preset parameters for offline mode
42
+ * @returns Offline mode parameters
43
+ */
44
+ export declare function getOfflineParams(): PresetParams;
45
+ //# sourceMappingURL=presets.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"presets.d.ts","sourceRoot":"","sources":["../src/presets.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAE7C;;;GAGG;AACH,MAAM,WAAW,YAAY;IAC3B,8CAA8C;IAC9C,QAAQ,EAAE,MAAM,CAAC;IACjB,oDAAoD;IACpD,YAAY,EAAE,MAAM,CAAC;IACrB,mCAAmC;IACnC,OAAO,EAAE,MAAM,CAAC;IAChB,4CAA4C;IAC5C,oBAAoB,EAAE,MAAM,CAAC;CAC9B;AAED;;;;;;GAMG;AACH,eAAO,MAAM,eAAe,EAAE,MAAM,CAAC,aAAa,EAAE,YAAY,CAyBtD,CAAC;AAEX;;;GAGG;AACH,eAAO,MAAM,cAAc,EAAE,YAKnB,CAAC;AAEX;;;;;GAKG;AACH,wBAAgB,eAAe,CAAC,MAAM,EAAE,aAAa,GAAG,YAAY,CAMnE;AAED;;;GAGG;AACH,wBAAgB,gBAAgB,IAAI,YAAY,CAE/C"}
@@ -0,0 +1,68 @@
1
+ /**
2
+ * Latency presets for streaming diarization
3
+ * Maps preset names to their corresponding parameter configurations
4
+ */
5
+ /**
6
+ * Streaming latency presets
7
+ * - 'low': ~188ms latency, minimal buffering
8
+ * - '2s': ~2 second latency
9
+ * - '3s': ~3 second latency
10
+ * - '5s': ~5 second latency
11
+ */
12
+ export const LATENCY_PRESETS = {
13
+ 'low': {
14
+ chunkLen: 6,
15
+ rightContext: 7,
16
+ fifoLen: 188,
17
+ spkcacheUpdatePeriod: 144,
18
+ },
19
+ '2s': {
20
+ chunkLen: 15,
21
+ rightContext: 10,
22
+ fifoLen: 100,
23
+ spkcacheUpdatePeriod: 144,
24
+ },
25
+ '3s': {
26
+ chunkLen: 30,
27
+ rightContext: 7,
28
+ fifoLen: 100,
29
+ spkcacheUpdatePeriod: 100,
30
+ },
31
+ '5s': {
32
+ chunkLen: 55,
33
+ rightContext: 7,
34
+ fifoLen: 100,
35
+ spkcacheUpdatePeriod: 100,
36
+ },
37
+ };
38
+ /**
39
+ * Offline mode parameters
40
+ * Used when mode='offline' to process entire audio at once
41
+ */
42
+ export const OFFLINE_PARAMS = {
43
+ chunkLen: 188,
44
+ rightContext: 1,
45
+ fifoLen: 0,
46
+ spkcacheUpdatePeriod: 188,
47
+ };
48
+ /**
49
+ * Get preset parameters by name
50
+ * @param preset - Latency preset name
51
+ * @returns Preset parameters
52
+ * @throws Error if preset is not found
53
+ */
54
+ export function getPresetParams(preset) {
55
+ const params = LATENCY_PRESETS[preset];
56
+ if (!params) {
57
+ throw new Error(`Unknown latency preset: ${preset}`);
58
+ }
59
+ return params;
60
+ }
61
+ /**
62
+ * Get default preset parameters for offline mode
63
+ * @returns Offline mode parameters
64
+ */
65
+ export function getOfflineParams() {
66
+ return OFFLINE_PARAMS;
67
+ }
68
+ //# sourceMappingURL=presets.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"presets.js","sourceRoot":"","sources":["../src/presets.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAmBH;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,eAAe,GAAwC;IAClE,KAAK,EAAE;QACL,QAAQ,EAAE,CAAC;QACX,YAAY,EAAE,CAAC;QACf,OAAO,EAAE,GAAG;QACZ,oBAAoB,EAAE,GAAG;KAC1B;IACD,IAAI,EAAE;QACJ,QAAQ,EAAE,EAAE;QACZ,YAAY,EAAE,EAAE;QAChB,OAAO,EAAE,GAAG;QACZ,oBAAoB,EAAE,GAAG;KAC1B;IACD,IAAI,EAAE;QACJ,QAAQ,EAAE,EAAE;QACZ,YAAY,EAAE,CAAC;QACf,OAAO,EAAE,GAAG;QACZ,oBAAoB,EAAE,GAAG;KAC1B;IACD,IAAI,EAAE;QACJ,QAAQ,EAAE,EAAE;QACZ,YAAY,EAAE,CAAC;QACf,OAAO,EAAE,GAAG;QACZ,oBAAoB,EAAE,GAAG;KAC1B;CACO,CAAC;AAEX;;;GAGG;AACH,MAAM,CAAC,MAAM,cAAc,GAAiB;IAC1C,QAAQ,EAAE,GAAG;IACb,YAAY,EAAE,CAAC;IACf,OAAO,EAAE,CAAC;IACV,oBAAoB,EAAE,GAAG;CACjB,CAAC;AAEX;;;;;GAKG;AACH,MAAM,UAAU,eAAe,CAAC,MAAqB;IACnD,MAAM,MAAM,GAAG,eAAe,CAAC,MAAM,CAAC,CAAC;IACvC,IAAI,CAAC,MAAM,EAAE,CAAC;QACZ,MAAM,IAAI,KAAK,CAAC,2BAA2B,MAAM,EAAE,CAAC,CAAC;IACvD,CAAC;IACD,OAAO,MAAM,CAAC;AAChB,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,gBAAgB;IAC9B,OAAO,cAAc,CAAC;AACxB,CAAC"}
@@ -0,0 +1,107 @@
1
+ /**
2
+ * TypeScript type definitions for streaming-sortformer-node
3
+ */
4
+ /**
5
+ * Diarization mode: offline processes entire audio at once,
6
+ * streaming processes audio in chunks with latency control
7
+ */
8
+ export type DiarizeMode = 'offline' | 'streaming';
9
+ /**
10
+ * Latency preset for streaming mode
11
+ * - 'low': ~188ms latency, minimal buffering
12
+ * - '2s': ~2 second latency
13
+ * - '3s': ~3 second latency
14
+ * - '5s': ~5 second latency
15
+ */
16
+ export type LatencyPreset = 'low' | '2s' | '3s' | '5s';
17
+ /**
18
+ * Options for loading a SortFormer model
19
+ */
20
+ export interface LoadOptions {
21
+ /**
22
+ * Number of CPU threads to use for inference
23
+ * @default auto-detected based on CPU cores
24
+ */
25
+ threads?: number;
26
+ }
27
+ /**
28
+ * Options for diarization inference
29
+ */
30
+ export interface DiarizeOptions {
31
+ /**
32
+ * Diarization mode: 'offline' or 'streaming'
33
+ * @default 'offline'
34
+ */
35
+ mode?: DiarizeMode;
36
+ /**
37
+ * Latency preset for streaming mode
38
+ * Only used when mode='streaming'
39
+ * @default '2s'
40
+ */
41
+ latency?: LatencyPreset;
42
+ /**
43
+ * Speaker activity threshold (0.0 to 1.0)
44
+ * Frames with prediction >= threshold are considered active
45
+ * @default 0.5
46
+ */
47
+ threshold?: number;
48
+ /**
49
+ * Median filter window size for smoothing predictions
50
+ * Must be odd number >= 1
51
+ * @default 11
52
+ */
53
+ medianFilter?: number;
54
+ }
55
+ /**
56
+ * Result of diarization inference
57
+ */
58
+ export interface DiarizeResult {
59
+ /**
60
+ * RTTM format output (speaker diarization segments)
61
+ * Format: SPEAKER <filename> <channel> <start> <duration> <conf> <spk_type> <spk_id> <score>
62
+ */
63
+ rttm: string;
64
+ /**
65
+ * Raw per-frame speaker activity predictions
66
+ * Shape: [frameCount, 4] (4 speakers max)
67
+ * Values: 0.0 to 1.0 (probability of speaker activity)
68
+ */
69
+ predictions: Float32Array;
70
+ /**
71
+ * Number of frames in the output
72
+ */
73
+ frameCount: number;
74
+ /**
75
+ * Number of speakers detected (1-4)
76
+ */
77
+ speakerCount: number;
78
+ }
79
+ /**
80
+ * Streaming preset type
81
+ */
82
+ export type StreamingPreset = 'low' | '2s' | '3s' | '5s';
83
+ /**
84
+ * Options for creating a streaming session
85
+ */
86
+ export interface StreamingSessionOptions {
87
+ /**
88
+ * Latency preset
89
+ * @default '2s'
90
+ */
91
+ preset?: StreamingPreset;
92
+ }
93
+ /**
94
+ * Result from feeding audio to streaming session
95
+ */
96
+ export interface FeedResult {
97
+ /**
98
+ * Per-frame speaker predictions for this chunk
99
+ * Shape: [frameCount, 4]
100
+ */
101
+ predictions: Float32Array;
102
+ /**
103
+ * Number of new frames in this result
104
+ */
105
+ frameCount: number;
106
+ }
107
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH;;;GAGG;AACH,MAAM,MAAM,WAAW,GAAG,SAAS,GAAG,WAAW,CAAC;AAElD;;;;;;GAMG;AACH,MAAM,MAAM,aAAa,GAAG,KAAK,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,CAAC;AAEvD;;GAEG;AACH,MAAM,WAAW,WAAW;IAC1B;;;OAGG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED;;GAEG;AACH,MAAM,WAAW,cAAc;IAC7B;;;OAGG;IACH,IAAI,CAAC,EAAE,WAAW,CAAC;IAEnB;;;;OAIG;IACH,OAAO,CAAC,EAAE,aAAa,CAAC;IAExB;;;;OAIG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;IAEnB;;;;OAIG;IACH,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB;AAED;;GAEG;AACH,MAAM,WAAW,aAAa;IAC5B;;;OAGG;IACH,IAAI,EAAE,MAAM,CAAC;IAEb;;;;OAIG;IACH,WAAW,EAAE,YAAY,CAAC;IAE1B;;OAEG;IACH,UAAU,EAAE,MAAM,CAAC;IAEnB;;OAEG;IACH,YAAY,EAAE,MAAM,CAAC;CACtB;AAED;;GAEG;AACH,MAAM,MAAM,eAAe,GAAG,KAAK,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,CAAC;AAEzD;;GAEG;AACH,MAAM,WAAW,uBAAuB;IACtC;;;OAGG;IACH,MAAM,CAAC,EAAE,eAAe,CAAC;CAC1B;AAED;;GAEG;AACH,MAAM,WAAW,UAAU;IACzB;;;OAGG;IACH,WAAW,EAAE,YAAY,CAAC;IAE1B;;OAEG;IACH,UAAU,EAAE,MAAM,CAAC;CACpB"}
package/dist/types.js ADDED
@@ -0,0 +1,5 @@
1
+ /**
2
+ * TypeScript type definitions for streaming-sortformer-node
3
+ */
4
+ export {};
5
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;GAEG"}
package/package.json ADDED
@@ -0,0 +1,31 @@
1
+ {
2
+ "name": "streaming-sortformer-node",
3
+ "version": "0.1.0",
4
+ "description": "Node.js bindings for SortFormer streaming speaker diarization",
5
+ "type": "module",
6
+ "main": "./dist/index.js",
7
+ "types": "./dist/index.d.ts",
8
+ "files": [
9
+ "dist",
10
+ "src"
11
+ ],
12
+ "dependencies": {
13
+ "node-addon-api": "^7.0.0"
14
+ },
15
+ "devDependencies": {
16
+ "typescript": "^5.0.0",
17
+ "cmake-js": "^7.0.0"
18
+ },
19
+ "optionalDependencies": {
20
+ "@streaming-sortformer-node/darwin-x64": "0.1.0",
21
+ "@streaming-sortformer-node/darwin-arm64": "0.1.0"
22
+ },
23
+ "engines": {
24
+ "node": ">=18.0.0"
25
+ },
26
+ "scripts": {
27
+ "build": "tsc",
28
+ "test": "echo 'No tests yet'",
29
+ "clean": "rm -rf dist"
30
+ }
31
+ }