@framers/agentos-ext-diarization 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +23 -0
- package/SKILL.md +71 -0
- package/dist/ClusteringStrategy.d.ts +56 -0
- package/dist/ClusteringStrategy.d.ts.map +1 -0
- package/dist/ClusteringStrategy.js +123 -0
- package/dist/ClusteringStrategy.js.map +1 -0
- package/dist/DiarizationEngine.d.ts +45 -0
- package/dist/DiarizationEngine.d.ts.map +1 -0
- package/dist/DiarizationEngine.js +84 -0
- package/dist/DiarizationEngine.js.map +1 -0
- package/dist/DiarizationSession.d.ts +90 -0
- package/dist/DiarizationSession.d.ts.map +1 -0
- package/dist/DiarizationSession.js +139 -0
- package/dist/DiarizationSession.js.map +1 -0
- package/dist/LocalDiarizationBackend.d.ts +90 -0
- package/dist/LocalDiarizationBackend.d.ts.map +1 -0
- package/dist/LocalDiarizationBackend.js +177 -0
- package/dist/LocalDiarizationBackend.js.map +1 -0
- package/dist/ProviderDiarizationBackend.d.ts +54 -0
- package/dist/ProviderDiarizationBackend.d.ts.map +1 -0
- package/dist/ProviderDiarizationBackend.js +101 -0
- package/dist/ProviderDiarizationBackend.js.map +1 -0
- package/dist/SlidingWindowExtractor.d.ts +85 -0
- package/dist/SlidingWindowExtractor.d.ts.map +1 -0
- package/dist/SlidingWindowExtractor.js +140 -0
- package/dist/SlidingWindowExtractor.js.map +1 -0
- package/dist/SpeakerEmbeddingCache.d.ts +117 -0
- package/dist/SpeakerEmbeddingCache.d.ts.map +1 -0
- package/dist/SpeakerEmbeddingCache.js +193 -0
- package/dist/SpeakerEmbeddingCache.js.map +1 -0
- package/dist/index.d.ts +67 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +73 -0
- package/dist/index.js.map +1 -0
- package/dist/types.d.ts +177 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +13 -0
- package/dist/types.js.map +1 -0
- package/manifest.json +8 -0
- package/package.json +48 -0
- package/src/ClusteringStrategy.ts +139 -0
- package/src/DiarizationEngine.ts +94 -0
- package/src/DiarizationSession.ts +178 -0
- package/src/LocalDiarizationBackend.ts +201 -0
- package/src/ProviderDiarizationBackend.ts +119 -0
- package/src/SlidingWindowExtractor.ts +174 -0
- package/src/SpeakerEmbeddingCache.ts +228 -0
- package/src/index.ts +105 -0
- package/src/types.ts +221 -0
package/src/types.ts
ADDED
|
@@ -0,0 +1,221 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file types.ts
|
|
3
|
+
* @description Core types for the diarization extension pack.
|
|
4
|
+
*
|
|
5
|
+
* These types define the public contract shared between the engine, session
|
|
6
|
+
* implementations, and calling code. They intentionally avoid importing from
|
|
7
|
+
* `@framers/agentos` so the pack can boot in environments where the core
|
|
8
|
+
* package is not yet available.
|
|
9
|
+
*
|
|
10
|
+
* @module diarization/types
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
import type { EventEmitter } from 'node:events';
|
|
14
|
+
|
|
15
|
+
// ---------------------------------------------------------------------------
|
|
16
|
+
// Audio primitive
|
|
17
|
+
// ---------------------------------------------------------------------------
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Minimal audio frame type used by the diarization pipeline.
|
|
21
|
+
*
|
|
22
|
+
* Matches the `AudioFrame` shape from `@framers/agentos` voice types so that
|
|
23
|
+
* frames can be forwarded without conversion.
|
|
24
|
+
*/
|
|
25
|
+
export interface AudioFrame {
|
|
26
|
+
/** Raw 32-bit float PCM samples, normalised to the range `[-1, 1]`. */
|
|
27
|
+
samples: Float32Array;
|
|
28
|
+
/** Sample rate in Hz (e.g. 16000). */
|
|
29
|
+
sampleRate: number;
|
|
30
|
+
/** Wall-clock timestamp in milliseconds when the frame was captured. */
|
|
31
|
+
timestamp: number;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
// ---------------------------------------------------------------------------
|
|
35
|
+
// Transcript primitive
|
|
36
|
+
// ---------------------------------------------------------------------------
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* A single word or token produced by an STT provider, optionally annotated
|
|
40
|
+
* with a speaker label.
|
|
41
|
+
*/
|
|
42
|
+
export interface TranscriptWord {
|
|
43
|
+
/** The recognised word text. */
|
|
44
|
+
word: string;
|
|
45
|
+
/** Start time of the word in seconds (relative to session start). */
|
|
46
|
+
start: number;
|
|
47
|
+
/** End time of the word in seconds (relative to session start). */
|
|
48
|
+
end: number;
|
|
49
|
+
/** Provider-assigned speaker label, e.g. `'0'` or `'Speaker_1'`. */
|
|
50
|
+
speaker?: string;
|
|
51
|
+
/** Per-word confidence in the range `[0, 1]`. */
|
|
52
|
+
confidence?: number;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* A transcript event as emitted by an STT provider session.
|
|
57
|
+
*
|
|
58
|
+
* Diarization operates on these events when running in provider-delegated
|
|
59
|
+
* mode; the `words` array carries word-level speaker annotations.
|
|
60
|
+
*/
|
|
61
|
+
export interface TranscriptEvent {
|
|
62
|
+
/** Full transcript text for this event. */
|
|
63
|
+
text: string;
|
|
64
|
+
/** Whether this is a finalised (stable) transcript hypothesis. */
|
|
65
|
+
isFinal: boolean;
|
|
66
|
+
/** Word-level tokens with optional speaker labels. */
|
|
67
|
+
words?: TranscriptWord[];
|
|
68
|
+
/** Session-relative timestamp in milliseconds. */
|
|
69
|
+
timestamp: number;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
// ---------------------------------------------------------------------------
|
|
73
|
+
// Diarized segment
|
|
74
|
+
// ---------------------------------------------------------------------------
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* A contiguous audio or text segment attributed to a single speaker.
|
|
78
|
+
*/
|
|
79
|
+
export interface DiarizedSegment {
|
|
80
|
+
/** Resolved speaker identifier (e.g. `'Alice'` or `'Speaker_0'`). */
|
|
81
|
+
speakerId: string;
|
|
82
|
+
/** Transcript text for this segment, if available. */
|
|
83
|
+
text?: string;
|
|
84
|
+
/** Segment start time in milliseconds (wall clock). */
|
|
85
|
+
startMs: number;
|
|
86
|
+
/** Segment end time in milliseconds (wall clock). */
|
|
87
|
+
endMs: number;
|
|
88
|
+
/** Confidence score for the speaker attribution in the range `[0, 1]`. */
|
|
89
|
+
confidence: number;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
// ---------------------------------------------------------------------------
|
|
93
|
+
// Speaker identified event
|
|
94
|
+
// ---------------------------------------------------------------------------
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* Payload for the `speaker_identified` event emitted by a
|
|
98
|
+
* {@link IDiarizationSession}.
|
|
99
|
+
*/
|
|
100
|
+
export interface SpeakerIdentified {
|
|
101
|
+
/** Resolved speaker identifier. */
|
|
102
|
+
speakerId: string;
|
|
103
|
+
/** Confidence in the range `[0, 1]`. */
|
|
104
|
+
confidence: number;
|
|
105
|
+
/** Wall-clock timestamp in milliseconds when this identification was made. */
|
|
106
|
+
timestamp: number;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
// ---------------------------------------------------------------------------
|
|
110
|
+
// Session configuration
|
|
111
|
+
// ---------------------------------------------------------------------------
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
* Configuration object for {@link IDiarizationEngine.startSession}.
|
|
115
|
+
*/
|
|
116
|
+
export interface DiarizationConfig {
|
|
117
|
+
/**
|
|
118
|
+
* Backend to use.
|
|
119
|
+
* - `'provider'` — extract speaker labels from STT provider word results.
|
|
120
|
+
* - `'local'` — use the built-in spectral-centroid sliding-window backend.
|
|
121
|
+
* @defaultValue 'local'
|
|
122
|
+
*/
|
|
123
|
+
backend?: 'provider' | 'local';
|
|
124
|
+
|
|
125
|
+
/**
|
|
126
|
+
* Cosine similarity threshold for speaker matching.
|
|
127
|
+
* Embeddings with similarity above this value are attributed to the same
|
|
128
|
+
* speaker.
|
|
129
|
+
* @defaultValue 0.7
|
|
130
|
+
*/
|
|
131
|
+
similarityThreshold?: number;
|
|
132
|
+
|
|
133
|
+
/**
|
|
134
|
+
* Hint for the clustering strategy — how many distinct speakers are expected
|
|
135
|
+
* in this session. When set, the engine will try to merge centroids until
|
|
136
|
+
* this count is reached.
|
|
137
|
+
*/
|
|
138
|
+
expectedSpeakers?: number;
|
|
139
|
+
|
|
140
|
+
/**
|
|
141
|
+
* Chunk duration in milliseconds for the sliding-window extractor.
|
|
142
|
+
* @defaultValue 1500
|
|
143
|
+
*/
|
|
144
|
+
chunkSizeMs?: number;
|
|
145
|
+
|
|
146
|
+
/**
|
|
147
|
+
* Overlap between consecutive chunks in milliseconds.
|
|
148
|
+
* @defaultValue 500
|
|
149
|
+
*/
|
|
150
|
+
overlapMs?: number;
|
|
151
|
+
|
|
152
|
+
/**
|
|
153
|
+
* Audio sample rate in Hz.
|
|
154
|
+
* @defaultValue 16000
|
|
155
|
+
*/
|
|
156
|
+
sampleRate?: number;
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
// ---------------------------------------------------------------------------
|
|
160
|
+
// Session interface
|
|
161
|
+
// ---------------------------------------------------------------------------
|
|
162
|
+
|
|
163
|
+
/**
|
|
164
|
+
* A live diarization session.
|
|
165
|
+
*
|
|
166
|
+
* Extends `EventEmitter` so callers can subscribe to `speaker_identified`,
|
|
167
|
+
* `segment_ready`, `error`, and `close` events.
|
|
168
|
+
*/
|
|
169
|
+
export interface IDiarizationSession extends EventEmitter {
|
|
170
|
+
/**
|
|
171
|
+
* Push a raw audio frame into the diarization pipeline.
|
|
172
|
+
*
|
|
173
|
+
* In local mode, frames are accumulated in a sliding window and processed
|
|
174
|
+
* when a full chunk is ready. In provider mode, this is a no-op (speaker
|
|
175
|
+
* labels come from {@link labelTranscript}).
|
|
176
|
+
*/
|
|
177
|
+
pushAudio(frame: AudioFrame): void;
|
|
178
|
+
|
|
179
|
+
/**
|
|
180
|
+
* Attach provider-supplied speaker labels to a transcript event and return
|
|
181
|
+
* the resulting {@link DiarizedSegment} (if enough information is present).
|
|
182
|
+
*
|
|
183
|
+
* In provider mode this is the primary data path. In local mode, the engine
|
|
184
|
+
* merges the text with the most recent speaker identification.
|
|
185
|
+
*/
|
|
186
|
+
labelTranscript(event: TranscriptEvent): DiarizedSegment | null;
|
|
187
|
+
|
|
188
|
+
/**
|
|
189
|
+
* Pre-register a known speaker voiceprint so the engine can label them by
|
|
190
|
+
* name rather than an auto-generated `Speaker_N` identifier.
|
|
191
|
+
*
|
|
192
|
+
* @param id - Human-readable speaker name or identifier.
|
|
193
|
+
* @param voiceprint - 32-bit float embedding vector representing the
|
|
194
|
+
* speaker's vocal characteristics.
|
|
195
|
+
*/
|
|
196
|
+
enrollSpeaker(id: string, voiceprint: Float32Array): void;
|
|
197
|
+
|
|
198
|
+
/**
|
|
199
|
+
* Terminate the session and release all resources.
|
|
200
|
+
*
|
|
201
|
+
* After `close()` is called, no further events will be emitted.
|
|
202
|
+
*/
|
|
203
|
+
close(): void;
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
// ---------------------------------------------------------------------------
|
|
207
|
+
// Engine interface
|
|
208
|
+
// ---------------------------------------------------------------------------
|
|
209
|
+
|
|
210
|
+
/**
|
|
211
|
+
* Factory interface for creating diarization sessions.
|
|
212
|
+
*/
|
|
213
|
+
export interface IDiarizationEngine {
|
|
214
|
+
/**
|
|
215
|
+
* Create and start a new {@link IDiarizationSession}.
|
|
216
|
+
*
|
|
217
|
+
* @param config - Optional session configuration.
|
|
218
|
+
* @returns A ready-to-use diarization session.
|
|
219
|
+
*/
|
|
220
|
+
startSession(config?: DiarizationConfig): IDiarizationSession;
|
|
221
|
+
}
|