offmute-v2 0.0.1-opus.0 → 0.0.2
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/README.md +67 -91
- package/dist/browser.browser.js +1149 -0
- package/dist/browser.browser.js.map +1 -0
- package/dist/browser.d.ts +437 -657
- package/dist/cli.cjs +2098 -0
- package/dist/cli.cjs.map +1 -0
- package/dist/cli.d.cts +1 -0
- package/dist/cli.js +1903 -1361
- package/dist/cli.js.map +1 -1
- package/dist/index.cjs +2110 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +371 -0
- package/dist/index.d.ts +311 -453
- package/dist/index.js +1912 -1381
- package/dist/index.js.map +1 -1
- package/package.json +42 -34
- package/dist/browser.js +0 -1494
- package/dist/browser.js.map +0 -1
package/dist/index.d.ts
CHANGED
|
@@ -1,513 +1,371 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Core
|
|
2
|
+
* Core domain types for offmute-v2.
|
|
3
3
|
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
* Alignment maps timing onto content to produce the final Transcript.
|
|
4
|
+
* The pipeline produces a timeline of {@link Segment}s, each carrying a speaker,
|
|
5
|
+
* accurate start/end times, the transcribed text, and optional tone/emotion
|
|
6
|
+
* annotations. Segments are the common currency between every stage.
|
|
8
7
|
*/
|
|
9
|
-
/** A single
|
|
10
|
-
interface
|
|
11
|
-
|
|
12
|
-
|
|
8
|
+
/** A single diarized, timestamped, tone-annotated span of speech. */
|
|
9
|
+
interface Segment {
|
|
10
|
+
/** Stable id within the final transcript (assigned at finalize time). */
|
|
11
|
+
id: number;
|
|
12
|
+
/** Start time in seconds (absolute, from the start of the source media). */
|
|
13
13
|
start: number;
|
|
14
|
-
/**
|
|
14
|
+
/** End time in seconds (absolute). */
|
|
15
15
|
end: number;
|
|
16
|
-
/**
|
|
17
|
-
speaker
|
|
18
|
-
/**
|
|
16
|
+
/** Global, consistent speaker label, e.g. "speaker_0" or "Hrishi". */
|
|
17
|
+
speaker: string;
|
|
18
|
+
/** Display name for the speaker (may equal `speaker` until identification). */
|
|
19
|
+
speakerName?: string;
|
|
20
|
+
/** The transcribed words. */
|
|
21
|
+
text: string;
|
|
22
|
+
/** Free-form tone/emotion/behavior annotations, e.g. "hesitant", "laughing". */
|
|
23
|
+
tone?: string[];
|
|
24
|
+
/** Where the timing came from — useful for debugging alignment. */
|
|
25
|
+
timingSource?: "llm" | "aligned" | "timestamped" | "interpolated" | "coarse";
|
|
26
|
+
/** Where the text came from. */
|
|
27
|
+
textSource?: "llm" | "timestamped";
|
|
28
|
+
/** Which chunk produced this segment (pre-merge). */
|
|
29
|
+
sourceChunk?: number;
|
|
30
|
+
/** Alignment confidence in [0,1] when produced by the aligner. */
|
|
19
31
|
confidence?: number;
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
32
|
+
/** Per-word timing (for SRT sub-splitting of long turns). */
|
|
33
|
+
words?: {
|
|
34
|
+
text: string;
|
|
35
|
+
start: number;
|
|
36
|
+
end: number;
|
|
37
|
+
matched?: boolean;
|
|
38
|
+
}[];
|
|
39
|
+
}
|
|
40
|
+
/** A planned audio chunk with overlap metadata for clean deduplication. */
|
|
41
|
+
interface ChunkPlan {
|
|
42
|
+
index: number;
|
|
43
|
+
/** Absolute start time (seconds). */
|
|
44
|
+
start: number;
|
|
45
|
+
/** Absolute end time (seconds). */
|
|
46
|
+
end: number;
|
|
47
|
+
/** The portion of this chunk that overlaps the previous chunk. */
|
|
48
|
+
overlapWithPrevious: number;
|
|
49
|
+
/**
|
|
50
|
+
* Absolute time after which this chunk's content is "trusted" (i.e. not
|
|
51
|
+
* covered by the previous chunk). Content before this point may be dropped
|
|
52
|
+
* during merge to avoid double-transcription. Equals `start + overlap`.
|
|
53
|
+
*/
|
|
54
|
+
trustedStart: number;
|
|
55
|
+
/** Path to the extracted audio chunk file. */
|
|
56
|
+
path?: string;
|
|
57
|
+
}
|
|
58
|
+
/** A single word with accurate timing (from a timestamped transcriber). */
|
|
59
|
+
interface TimestampedWord {
|
|
23
60
|
text: string;
|
|
24
61
|
start: number;
|
|
25
62
|
end: number;
|
|
26
|
-
/** ASR speaker label (e.g. "A") */
|
|
27
|
-
speaker: string;
|
|
28
63
|
confidence?: number;
|
|
29
|
-
/** Per-utterance words — OPTIONAL on purpose: alignment uses the flat
|
|
30
|
-
* AsrResult.words instead, and not every provider/config populates this. */
|
|
31
|
-
words?: TimedWord[];
|
|
32
64
|
}
|
|
33
|
-
/**
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
* aligned against to read precise timings. (Required.)
|
|
38
|
-
* - `utterances`: speaker-grouped turns — used to build the prompt's "ASR hint"
|
|
39
|
-
* and to render the provider's own diarization. (Required.)
|
|
40
|
-
*/
|
|
41
|
-
interface AsrResult {
|
|
42
|
-
provider: string;
|
|
43
|
-
/** model / config used, for provenance */
|
|
44
|
-
model?: string;
|
|
45
|
-
words: TimedWord[];
|
|
46
|
-
utterances: AsrUtterance[];
|
|
47
|
-
/** distinct ASR speaker labels observed */
|
|
48
|
-
speakers: string[];
|
|
49
|
-
durationSeconds: number;
|
|
50
|
-
language?: string;
|
|
51
|
-
/** whether diarization (speaker labels) was actually available */
|
|
52
|
-
diarized: boolean;
|
|
53
|
-
}
|
|
54
|
-
/** A diarized line as emitted by the LLM for a chunk (timestamps are rough/optional). */
|
|
55
|
-
interface LlmLine {
|
|
56
|
-
/** speaker as the LLM sees it — a name ("Hrishi") or anonymous ("Speaker 1") */
|
|
65
|
+
/** A speaker as understood by a timestamped diarizer (AssemblyAI/Whisper). */
|
|
66
|
+
interface TimestampedUtterance {
|
|
67
|
+
start: number;
|
|
68
|
+
end: number;
|
|
57
69
|
speaker: string;
|
|
58
70
|
text: string;
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
71
|
+
confidence?: number;
|
|
72
|
+
words?: TimestampedWord[];
|
|
73
|
+
}
|
|
74
|
+
/** The full result of running the pipeline. */
|
|
75
|
+
interface TranscriptResult {
|
|
76
|
+
segments: Segment[];
|
|
77
|
+
speakers: SpeakerInfo[];
|
|
78
|
+
metadata: TranscriptMetadata;
|
|
66
79
|
}
|
|
67
|
-
|
|
68
|
-
/**
|
|
69
|
-
interface Speaker {
|
|
70
|
-
/** stable internal id, e.g. "S1" */
|
|
80
|
+
interface SpeakerInfo {
|
|
81
|
+
/** Global consistent id, e.g. "speaker_0". */
|
|
71
82
|
id: string;
|
|
72
|
-
/**
|
|
73
|
-
|
|
74
|
-
/**
|
|
75
|
-
named: boolean;
|
|
76
|
-
/** ASR labels that map to this speaker */
|
|
77
|
-
asrLabels?: string[];
|
|
78
|
-
/** short description (role/appearance/voice) if inferred */
|
|
83
|
+
/** Identified name if known, else undefined. */
|
|
84
|
+
name?: string;
|
|
85
|
+
/** Human-readable description from the LLM description pass. */
|
|
79
86
|
description?: string;
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
/**
|
|
85
|
-
|
|
86
|
-
end: number;
|
|
87
|
-
/** resolved speaker id (see Transcript.speakers) */
|
|
88
|
-
speakerId: string;
|
|
89
|
-
text: string;
|
|
90
|
-
/** tone/emotion annotation if any */
|
|
91
|
-
tone?: string;
|
|
92
|
-
timingSource: TimingSource;
|
|
93
|
-
/** 0..1 — how confident the text↔timing alignment was for this segment */
|
|
94
|
-
alignmentConfidence?: number;
|
|
95
|
-
}
|
|
96
|
-
/** A record of one LLM call, for debugging/inspection (prompt + response + usage). */
|
|
97
|
-
interface LlmCallRecord {
|
|
98
|
-
/** which stage made the call, e.g. "diarize", "diarize-chunk-2", "identify" */
|
|
99
|
-
label?: string;
|
|
100
|
-
model: string;
|
|
101
|
-
/** the text portion(s) of the prompt (files are noted, not inlined) */
|
|
102
|
-
promptText: string;
|
|
103
|
-
/** number of non-text (file/image) parts sent */
|
|
104
|
-
fileParts?: number;
|
|
105
|
-
responseText: string;
|
|
106
|
-
usage?: {
|
|
107
|
-
inputTokens?: number;
|
|
108
|
-
outputTokens?: number;
|
|
109
|
-
thoughtsTokens?: number;
|
|
110
|
-
};
|
|
111
|
-
error?: string;
|
|
87
|
+
/** Number of segments attributed to this speaker. */
|
|
88
|
+
segmentCount?: number;
|
|
89
|
+
/** Total speaking time in seconds. */
|
|
90
|
+
talkTime?: number;
|
|
91
|
+
/** ASR voice cluster(s) this speaker maps to (voice-anchored evidence for identify). */
|
|
92
|
+
asrVoices?: string[];
|
|
112
93
|
}
|
|
113
94
|
interface TranscriptMetadata {
|
|
114
|
-
|
|
115
|
-
|
|
95
|
+
sourceFile: string;
|
|
96
|
+
duration: number;
|
|
116
97
|
processedAt: string;
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
userInstructions?: string;
|
|
120
|
-
language?: string;
|
|
121
|
-
}
|
|
122
|
-
interface Transcript {
|
|
123
|
-
segments: TranscriptSegment[];
|
|
124
|
-
speakers: Speaker[];
|
|
125
|
-
metadata: TranscriptMetadata;
|
|
126
|
-
}
|
|
127
|
-
interface TimeChunk {
|
|
128
|
-
index: number;
|
|
129
|
-
startSeconds: number;
|
|
130
|
-
endSeconds: number;
|
|
131
|
-
}
|
|
132
|
-
interface MediaChunk extends TimeChunk {
|
|
133
|
-
/** path (node) or handle to the extracted audio for this chunk */
|
|
134
|
-
audioPath: string;
|
|
135
|
-
/** optional keyframe image paths covering this chunk */
|
|
136
|
-
keyframePaths?: string[];
|
|
137
|
-
}
|
|
138
|
-
interface MediaInfo {
|
|
139
|
-
durationSeconds: number;
|
|
140
|
-
hasVideo: boolean;
|
|
141
|
-
hasAudio: boolean;
|
|
142
|
-
width?: number;
|
|
143
|
-
height?: number;
|
|
144
|
-
videoCodec?: string;
|
|
145
|
-
audioCodec?: string;
|
|
146
|
-
sampleRate?: number;
|
|
147
|
-
channels?: number;
|
|
148
|
-
sizeBytes?: number;
|
|
98
|
+
models: Record<string, string>;
|
|
99
|
+
passes: string[];
|
|
149
100
|
}
|
|
150
101
|
|
|
151
|
-
/**
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
declare function relTimeToSeconds(timeStr: string): number | null;
|
|
158
|
-
/** seconds -> "M:SS" compact (for markdown headers). */
|
|
159
|
-
declare function secondsToCompact(seconds: number): string;
|
|
160
|
-
/** Format "start --> end" SRT timing line. */
|
|
161
|
-
declare function formatSrtTiming(start: number, end: number): string;
|
|
102
|
+
/**
|
|
103
|
+
* Configuration: model presets, API-key resolution, pipeline options.
|
|
104
|
+
*
|
|
105
|
+
* Security model (instr. #11): keys are read from the environment by default, but
|
|
106
|
+
* every key can also be injected via the options object. Injected keys always win.
|
|
107
|
+
*/
|
|
162
108
|
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
/**
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
/**
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
109
|
+
/** All supported provider keys. */
|
|
110
|
+
interface ApiKeys {
|
|
111
|
+
gemini?: string;
|
|
112
|
+
google?: string;
|
|
113
|
+
openai?: string;
|
|
114
|
+
deepseek?: string;
|
|
115
|
+
groq?: string;
|
|
116
|
+
assemblyai?: string;
|
|
117
|
+
anthropic?: string;
|
|
118
|
+
}
|
|
119
|
+
interface PipelineOptions {
|
|
120
|
+
/** Input file path. */
|
|
121
|
+
input: string;
|
|
122
|
+
/** Output directory. */
|
|
123
|
+
outputDir: string;
|
|
124
|
+
/** Directory for intermediates (resumable). If omitted, derived per-input so
|
|
125
|
+
* different files never share a cache (see deriveIntermediatesDir). */
|
|
126
|
+
intermediatesDir?: string;
|
|
127
|
+
/** Free-form instructions forwarded to the LLM. */
|
|
128
|
+
instructions?: string;
|
|
129
|
+
/** Known speaker names (skip identification, map by best effort). */
|
|
130
|
+
knownSpeakers?: string[];
|
|
131
|
+
/** Which passes to run. */
|
|
132
|
+
passes?: Pass[];
|
|
133
|
+
/** Chunk duration in seconds (LLM transcription). */
|
|
134
|
+
chunkDurationSec?: number;
|
|
135
|
+
/** Overlap between chunks in seconds. */
|
|
136
|
+
chunkOverlapSec?: number;
|
|
137
|
+
/** Number of screenshots/keyframes to extract (video). */
|
|
138
|
+
screenshotCount?: number;
|
|
139
|
+
/** Max concurrent chunk requests. */
|
|
140
|
+
concurrency?: number;
|
|
141
|
+
/** Save intermediates (default true). */
|
|
142
|
+
saveIntermediates?: boolean;
|
|
143
|
+
/** Output formats. */
|
|
144
|
+
formats?: ("srt" | "md" | "json")[];
|
|
145
|
+
/** Target diarization level. */
|
|
146
|
+
diarizationLevel?: 1 | 2 | 3;
|
|
147
|
+
/** Injected API keys (override env). */
|
|
148
|
+
apiKeys?: ApiKeys;
|
|
149
|
+
/** Override the multimodal transcription model. */
|
|
150
|
+
model?: string;
|
|
151
|
+
/** Override the text-reasoner model (identification pass). */
|
|
152
|
+
reasoner?: string;
|
|
153
|
+
/** Timestamped provider. */
|
|
154
|
+
timestampedProvider?: "assemblyai" | "whisper-groq" | "none";
|
|
155
|
+
/** Force reprocessing of cached chunk outputs. */
|
|
156
|
+
force?: boolean;
|
|
157
|
+
/** Process only a specific chunk index (debugging). */
|
|
158
|
+
onlyChunk?: number;
|
|
159
|
+
/** Show progress. */
|
|
160
|
+
showProgress?: boolean;
|
|
161
|
+
/** Log every LLM call (prompt+response+usage+timing) to <intermediates>/llm-calls.jsonl. */
|
|
162
|
+
llmLog?: boolean;
|
|
163
|
+
/** Log level. */
|
|
164
|
+
logLevel?: "debug" | "info" | "warn" | "error";
|
|
165
|
+
}
|
|
166
|
+
type Pass = "preprocess" | "describe" | "llm-transcribe" | "timestamped" | "align" | "consistency" | "identify" | "finalize";
|
|
167
|
+
/** Build a chunk plan with overlap + trustedStart (for clean dedup). */
|
|
168
|
+
declare function planChunks(totalDuration: number, chunkDuration: number, overlap: number): ChunkPlan[];
|
|
169
|
+
|
|
170
|
+
declare function transcribe(opts: PipelineOptions): Promise<TranscriptResult>;
|
|
192
171
|
|
|
193
172
|
/**
|
|
194
|
-
*
|
|
195
|
-
*
|
|
196
|
-
* The multimodal LLM gives high-quality diarized text but only coarse/sparse
|
|
197
|
-
* timestamps. The ASR gives precise word-level timings but unreliable diarization.
|
|
198
|
-
* We align the LLM's token stream to the ASR's word stream (both describe the same
|
|
199
|
-
* audio, so the sequences are ~90%+ similar) and read precise timings off the ASR
|
|
200
|
-
* words that match each LLM segment. This is "forced alignment" using an existing
|
|
201
|
-
* ASR transcript as the timing reference rather than an acoustic model.
|
|
202
|
-
*
|
|
203
|
-
* Browser-safe (pure functions, no deps).
|
|
173
|
+
* Per-chunk LLM transcription: call Gemini, parse relative mm:ss timestamps to
|
|
174
|
+
* absolute seconds (chunk offset), validate span + monotonicity, retry on failure.
|
|
204
175
|
*/
|
|
205
176
|
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
/**
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
177
|
+
interface ParsedLlmSegment {
|
|
178
|
+
speaker: string;
|
|
179
|
+
/** Absolute start (seconds), chunk offset applied. */
|
|
180
|
+
startSec: number;
|
|
181
|
+
/** Absolute end (seconds). */
|
|
182
|
+
endSec: number;
|
|
183
|
+
text: string;
|
|
184
|
+
tone: string[];
|
|
185
|
+
rawStart: string;
|
|
186
|
+
rawEnd: string;
|
|
187
|
+
/** Source chunk index (set by the pipeline; used for ownership partitioning). */
|
|
188
|
+
chunkIndex?: number;
|
|
189
|
+
/** Trusted-start (absolute) of the source chunk — content before this is overlap
|
|
190
|
+
* owned by the previous chunk. Segments whose center is before this are dropped to
|
|
191
|
+
* avoid double-printing the overlap region. */
|
|
192
|
+
trustedStart?: number;
|
|
217
193
|
}
|
|
194
|
+
|
|
218
195
|
/**
|
|
219
|
-
*
|
|
220
|
-
*
|
|
221
|
-
* each consume one token from `a` (a diagonal/up move) and/or one from `b`
|
|
222
|
-
* (diagonal/left), so reading the pairs in order reconstructs how the two
|
|
223
|
-
* sequences line up. Reference: https://en.wikipedia.org/wiki/Needleman–Wunsch_algorithm
|
|
224
|
-
*
|
|
225
|
-
* How it works (textbook NW, O(n·m) time and space):
|
|
226
|
-
* 1. `score[i][j]` = best alignment score of a[0..i) against b[0..j). The first
|
|
227
|
-
* row/column are seeded with cumulative gap penalties (aligning a prefix to
|
|
228
|
-
* nothing costs one gap per token).
|
|
229
|
-
* 2. Fill each cell as the best of three moves:
|
|
230
|
-
* diagonal = score[i-1][j-1] + (a[i-1]==b[j-1] ? MATCH : MISMATCH) // consume both
|
|
231
|
-
* up = score[i-1][j] + GAP // consume a[i-1], skip b
|
|
232
|
-
* left = score[i][j-1] + GAP // consume b[j-1], skip a
|
|
233
|
-
* `back[i][j]` remembers which move won (0=diag, 1=up, 2=left); ties prefer diag.
|
|
234
|
-
* 3. Trace `back` from the bottom-right (n,m) to (0,0) and reverse to get the path.
|
|
196
|
+
* Aligner: transfers accurate word-level timestamps from an ASR transcript onto the
|
|
197
|
+
* richer LLM transcript (diarized, tone-annotated).
|
|
235
198
|
*
|
|
236
|
-
*
|
|
237
|
-
*
|
|
238
|
-
*
|
|
239
|
-
*
|
|
240
|
-
*
|
|
199
|
+
* Approach (ts-aligner): align the ENTIRE LLM token stream (all segments, in order)
|
|
200
|
+
* against the ASR word stream in a single edit-distance DP pass, then split the
|
|
201
|
+
* timed result back into segments. Long, ordered sequences pin common words ("the",
|
|
202
|
+
* "as") to their correct occurrence — a per-segment windowed alignment scatters them
|
|
203
|
+
* to later occurrences and drifts. One DP over the chunk is O(tokens × asrWords).
|
|
241
204
|
*/
|
|
242
|
-
|
|
243
|
-
interface
|
|
244
|
-
/** original LLM surface token (with punctuation) */
|
|
245
|
-
surface: string;
|
|
246
|
-
norm: string;
|
|
247
|
-
/** index of the turn this token belongs to */
|
|
248
|
-
turnIndex: number;
|
|
249
|
-
/** matched ASR word time (seconds), or null if unmatched (filled by interpolation) */
|
|
250
|
-
start: number | null;
|
|
251
|
-
end: number | null;
|
|
252
|
-
matched: boolean;
|
|
253
|
-
/** ASR speaker label of the matched word (for voice-anchored identity) */
|
|
254
|
-
asrSpeaker?: string;
|
|
255
|
-
}
|
|
256
|
-
/** Something with text we can tokenize (an LLM turn). */
|
|
257
|
-
interface HasText {
|
|
205
|
+
|
|
206
|
+
interface AlignedWord {
|
|
258
207
|
text: string;
|
|
208
|
+
start: number;
|
|
209
|
+
end: number;
|
|
210
|
+
matched: boolean;
|
|
259
211
|
}
|
|
260
|
-
/**
|
|
261
|
-
* Align the concatenated LLM turn token stream to ASR words and return every LLM
|
|
262
|
-
* token tagged with its turn index and matched ASR time (null where unmatched).
|
|
263
|
-
*/
|
|
264
|
-
declare function alignLlmToAsr(turns: HasText[], asrWords: TimedWord[]): AlignedToken[];
|
|
265
|
-
/**
|
|
266
|
-
* Fill null token times by interpolating between matched neighbors. Tokens before
|
|
267
|
-
* the first match take the first matched start; after the last match take the last
|
|
268
|
-
* matched end. Returns the same array (mutated).
|
|
269
|
-
*/
|
|
270
|
-
declare function fillTokenTimes(tokens: AlignedToken[], totalDuration: number): AlignedToken[];
|
|
271
212
|
interface AlignedSegment {
|
|
272
|
-
|
|
213
|
+
speaker: string;
|
|
214
|
+
/** Display name (set by the consistency/identification pass). */
|
|
215
|
+
speakerName?: string;
|
|
273
216
|
start: number;
|
|
274
217
|
end: number;
|
|
275
218
|
text: string;
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
minChars?: number;
|
|
292
|
-
}
|
|
293
|
-
/**
|
|
294
|
-
* Group aligned tokens into output segments. Tokens already carry filled times.
|
|
295
|
-
* One segment per turn by default; if subSegment, cut turns into readable cues.
|
|
296
|
-
*/
|
|
297
|
-
declare function buildSegmentsFromTokens(turns: HasText[], tokens: AlignedToken[], options?: SegmentOptions): AlignedSegment[];
|
|
219
|
+
tone: string[];
|
|
220
|
+
confidence: number;
|
|
221
|
+
timingSource: "aligned" | "interpolated" | "coarse" | "timestamped";
|
|
222
|
+
words: AlignedWord[];
|
|
223
|
+
sourceIndex: number;
|
|
224
|
+
}
|
|
225
|
+
interface AlignOptions {
|
|
226
|
+
/** Below this confidence, mark timing as interpolated (flag for repair). */
|
|
227
|
+
confidenceThreshold?: number;
|
|
228
|
+
/** Gate ASR to words within this many seconds of the LLM span (0 = use all). */
|
|
229
|
+
timeMarginSec?: number;
|
|
230
|
+
}
|
|
231
|
+
/** Align LLM segments to ASR words (single DP over the chunk). Segments need not be sorted. */
|
|
232
|
+
declare function alignSegments(llmSegments: ParsedLlmSegment[], asrWords: TimestampedWord[], opts?: AlignOptions): AlignedSegment[];
|
|
233
|
+
|
|
298
234
|
/**
|
|
299
|
-
*
|
|
300
|
-
*
|
|
301
|
-
*
|
|
235
|
+
* Speaker-consistency pass (diarization level 2: anonymous-but-consistent).
|
|
236
|
+
*
|
|
237
|
+
* The ASR diarizer (AssemblyAI) labels speakers over the WHOLE file, so its labels
|
|
238
|
+
* are already globally consistent. We use them as the backbone: each aligned LLM
|
|
239
|
+
* segment inherits the ASR speaker that dominates its time window. The LLM's richer
|
|
240
|
+
* per-chunk labels (role/name) become display names. This gives consistent A/B/C
|
|
241
|
+
* labels across chunks for free, and survives LLM label drift between chunks.
|
|
302
242
|
*/
|
|
303
|
-
declare function asrSpeakerByLabel(tokens: AlignedToken[], labelByTurn: string[]): Record<string, Record<string, number>>;
|
|
304
243
|
|
|
305
|
-
|
|
244
|
+
interface ConsistencyResult {
|
|
245
|
+
segments: AlignedSegment[];
|
|
246
|
+
speakers: SpeakerInfo[];
|
|
247
|
+
/** ASR speaker id → chosen display name. */
|
|
248
|
+
displayNames: Record<string, string>;
|
|
249
|
+
/** LLM label → ASR speaker id (for debugging / identification). */
|
|
250
|
+
llmLabelToAsr: Record<string, string>;
|
|
251
|
+
}
|
|
252
|
+
/** Assign globally-consistent speaker ids to aligned segments via ASR time overlap,
|
|
253
|
+
* merging ASR speakers that the LLM consistently labels the same specific name/role
|
|
254
|
+
* (handles ASR over-splitting, e.g. one presenter split into speaker_A + speaker_B).
|
|
255
|
+
* Global ids "Speaker A", "Speaker B", … are assigned by total talk time. */
|
|
256
|
+
declare function assignGlobalSpeakers(segments: AlignedSegment[], asrUtterances: TimestampedUtterance[], opts?: {
|
|
257
|
+
hasDiarization?: boolean;
|
|
258
|
+
}): ConsistencyResult;
|
|
306
259
|
|
|
307
|
-
interface
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
/** include tone annotations inline (default false for SRT) */
|
|
311
|
-
includeTone?: boolean;
|
|
312
|
-
}
|
|
313
|
-
/** Make text safe for one SRT cue: collapse blank lines (they separate cues) + trim. */
|
|
314
|
-
declare function srtCueText(s: string): string;
|
|
315
|
-
declare function toSRT(transcript: Transcript, options?: SrtOptions): string;
|
|
316
|
-
interface MarkdownOptions {
|
|
317
|
-
includeTimestamps?: boolean;
|
|
318
|
-
includeTone?: boolean;
|
|
319
|
-
title?: string;
|
|
320
|
-
/** merge consecutive segments by the same speaker into one paragraph */
|
|
321
|
-
mergeBySpeaker?: boolean;
|
|
260
|
+
interface ChatMessage {
|
|
261
|
+
role: "system" | "user" | "assistant";
|
|
262
|
+
content: string;
|
|
322
263
|
}
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
}
|
|
329
|
-
|
|
330
|
-
/** Speaker canonicalization. Browser-safe (deterministic base; LLM pass lives in pipeline). */
|
|
331
|
-
|
|
332
|
-
declare function slugLabel(label: string): string;
|
|
333
|
-
declare function isProvisional(label: string): boolean;
|
|
334
|
-
interface BuildSpeakersOptions {
|
|
335
|
-
/** explicit canonical name per raw label (overrides) */
|
|
336
|
-
knownSpeakers?: Record<string, string>;
|
|
337
|
-
/** resolved-name map: raw label -> identified name (e.g. {"Speaker 1": "Rishi"}) from the identify pass */
|
|
338
|
-
resolvedNames?: Record<string, string>;
|
|
339
|
-
/** descriptions per canonical label */
|
|
340
|
-
descriptions?: Record<string, string>;
|
|
264
|
+
interface ChatResult {
|
|
265
|
+
text: string;
|
|
266
|
+
usage: {
|
|
267
|
+
inputTokens: number;
|
|
268
|
+
outputTokens: number;
|
|
269
|
+
};
|
|
270
|
+
error?: string;
|
|
341
271
|
}
|
|
342
|
-
interface
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
272
|
+
interface ChatOptions {
|
|
273
|
+
temperature?: number;
|
|
274
|
+
maxTokens?: number;
|
|
275
|
+
responseJson?: boolean;
|
|
276
|
+
maxRetries?: number;
|
|
277
|
+
/** What this call is for (logged): identify | … */
|
|
278
|
+
logKind?: string;
|
|
279
|
+
}
|
|
280
|
+
declare class OpenAICompatClient {
|
|
281
|
+
private baseUrl;
|
|
282
|
+
private apiKey;
|
|
283
|
+
private defaultModel;
|
|
284
|
+
private providerName;
|
|
285
|
+
constructor(baseUrl: string, apiKey: string, defaultModel: string, providerName?: string);
|
|
286
|
+
static fromProvider(provider: string, apiKey: string, defaultModel: string): OpenAICompatClient;
|
|
287
|
+
chat(model: string | undefined, messages: ChatMessage[], opts?: ChatOptions): Promise<ChatResult>;
|
|
288
|
+
chatJson<T = unknown>(model: string | undefined, messages: ChatMessage[], opts?: ChatOptions): Promise<{
|
|
289
|
+
data: T | null;
|
|
290
|
+
raw: string;
|
|
291
|
+
error?: string;
|
|
292
|
+
}>;
|
|
346
293
|
}
|
|
347
|
-
/**
|
|
348
|
-
* Build canonical speakers from the raw turn labels (in order of first appearance).
|
|
349
|
-
* Applies resolvedNames (merge provisional labels into a name) and known-speaker overrides.
|
|
350
|
-
*/
|
|
351
|
-
declare function buildSpeakers(rawLabels: string[], options?: BuildSpeakersOptions): BuiltSpeakers;
|
|
352
294
|
|
|
353
295
|
/**
|
|
354
|
-
*
|
|
355
|
-
*
|
|
356
|
-
*
|
|
357
|
-
*
|
|
296
|
+
* Speaker-identification pass (diarization level 3). A text reasoner (DeepSeek) reads
|
|
297
|
+
* the consistent transcript + roster and names speakers from content cues — e.g.
|
|
298
|
+
* "my name is Rishi, I run Southbridge" identifies the presenter. A speaker may
|
|
299
|
+
* self-identify in only one chunk, so the reasoner must see the whole transcript.
|
|
358
300
|
*/
|
|
359
301
|
|
|
360
|
-
|
|
302
|
+
/** Minimal segment shape needed for identification. */
|
|
303
|
+
interface IdentifySegment {
|
|
304
|
+
speaker: string;
|
|
305
|
+
text: string;
|
|
306
|
+
}
|
|
307
|
+
interface IdentifiedSpeaker {
|
|
308
|
+
id: string;
|
|
309
|
+
name: string;
|
|
310
|
+
confidence: "high" | "medium" | "low";
|
|
311
|
+
evidence: string;
|
|
312
|
+
}
|
|
313
|
+
interface IdentifyResult {
|
|
314
|
+
nameMap: Record<string, string>;
|
|
315
|
+
speakers: IdentifiedSpeaker[];
|
|
316
|
+
reasoning: string;
|
|
317
|
+
}
|
|
318
|
+
/** Identify speakers via a text reasoner. Returns a name map (speaker id → name). */
|
|
319
|
+
declare function identifySpeakers(client: OpenAICompatClient, model: string, segments: IdentifySegment[], speakers: SpeakerInfo[], roster: string, knownSpeakers?: string[]): Promise<IdentifyResult>;
|
|
361
320
|
|
|
362
321
|
/**
|
|
363
|
-
*
|
|
322
|
+
* Finalize: dedup chunk-overlap duplicates, fix timestamp overlaps, clamp durations,
|
|
323
|
+
* and produce the final renumbered Segment list ready for formatting.
|
|
364
324
|
*
|
|
365
|
-
*
|
|
366
|
-
*
|
|
367
|
-
*
|
|
368
|
-
* gracefully under truncation (you lose the tail, not the whole parse), whereas a
|
|
369
|
-
* truncated JSON array is unrecoverable. The lenient parser (parse-diarized.ts)
|
|
370
|
-
* tolerates the variations. (Hard-won lesson from ipgu's parser pain.)
|
|
325
|
+
* Improvements over ipgu's finalizer: (1) fuzzy near-duplicate dedup (we have no
|
|
326
|
+
* reference SRT ids to dedup by), (2) a FINAL overlap re-check pass after clamping
|
|
327
|
+
* (ipgu noted clamping can re-introduce overlaps but didn't re-check).
|
|
371
328
|
*/
|
|
372
329
|
|
|
373
|
-
interface
|
|
374
|
-
/**
|
|
375
|
-
|
|
376
|
-
/** compact ASR diarized transcript used as a HINT (not authority) */
|
|
377
|
-
asrHint?: string;
|
|
378
|
-
/** for chunked processing: which chunk and how many */
|
|
379
|
-
chunk?: {
|
|
380
|
-
index: number;
|
|
381
|
-
total: number;
|
|
382
|
-
startSeconds: number;
|
|
383
|
-
};
|
|
384
|
-
/** tail of the previous chunk's transcript for continuity */
|
|
385
|
-
previousTail?: string;
|
|
330
|
+
interface FinalizeOptions {
|
|
331
|
+
/** Drop segments shorter than this (seconds). */
|
|
332
|
+
minSegmentSec?: number;
|
|
386
333
|
}
|
|
387
|
-
|
|
388
|
-
declare function
|
|
389
|
-
/** Build a compact ASR hint string from utterances, trimming long ones. */
|
|
390
|
-
declare function buildAsrHint(asr: AsrResult, maxUtterances?: number, maxCharsPerUtterance?: number): string;
|
|
334
|
+
/** Convert aligned+consistent segments into the final Segment list (renumbered, deduped, clamped). */
|
|
335
|
+
declare function finalizeSegments(segments: AlignedSegment[], opts?: FinalizeOptions): Segment[];
|
|
391
336
|
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
asr?: "assemblyai" | "none";
|
|
400
|
-
asrModel?: string;
|
|
401
|
-
llmModel?: string;
|
|
402
|
-
/** thinking level for the LLM (Gemini 3.x): MINIMAL|LOW|MEDIUM|HIGH (default MINIMAL).
|
|
403
|
-
* NOTE: LOW+ can over-think on long audio and starve the output — MINIMAL is reliable. */
|
|
404
|
-
llmThinkingLevel?: "MINIMAL" | "LOW" | "MEDIUM" | "HIGH";
|
|
405
|
-
useVideo?: boolean;
|
|
406
|
-
keyframeCount?: number;
|
|
407
|
-
/** split turns into display-sized cues (default true) */
|
|
408
|
-
subSegment?: boolean;
|
|
409
|
-
/** run the LLM speaker-identification/merge pass (default true) */
|
|
410
|
-
identifySpeakers?: boolean;
|
|
411
|
-
knownSpeakers?: Record<string, string>;
|
|
412
|
-
intermediatesDir?: string;
|
|
413
|
-
cache?: boolean;
|
|
414
|
-
onProgress?: (e: ProgressEvent) => void;
|
|
415
|
-
/** invoked once per LLM call with its prompt/response/usage (for inspection/debug) */
|
|
416
|
-
onLlmCall?: (rec: LlmCallRecord) => void;
|
|
417
|
-
/** write every LLM call (prompt + response) to intermediates/llm/ (default true) */
|
|
418
|
-
logLlm?: boolean;
|
|
419
|
-
/** cancel the run (cooperatively, at stage and chunk boundaries) */
|
|
420
|
-
signal?: AbortSignal;
|
|
421
|
-
apiKeys?: {
|
|
422
|
-
gemini?: string;
|
|
423
|
-
assemblyai?: string;
|
|
424
|
-
};
|
|
425
|
-
/** force chunking threshold in minutes (default 35; longer files are chunked) */
|
|
426
|
-
maxSinglePassMinutes?: number;
|
|
427
|
-
/** chunk length in minutes when chunking (default 15) */
|
|
428
|
-
chunkMinutes?: number;
|
|
429
|
-
/** overlap between chunks in minutes (default 2) */
|
|
430
|
-
chunkOverlapMinutes?: number;
|
|
431
|
-
}
|
|
432
|
-
interface TranscribeResult {
|
|
433
|
-
transcript: Transcript;
|
|
434
|
-
srt: string;
|
|
435
|
-
markdown: string;
|
|
436
|
-
json: string;
|
|
437
|
-
/** plain-text transcript (speaker-grouped) */
|
|
438
|
-
text: string;
|
|
439
|
-
intermediatesDir: string;
|
|
440
|
-
asr?: AsrResult;
|
|
441
|
-
}
|
|
442
|
-
declare function transcribe(input: string, options?: TranscribeOptions): Promise<TranscribeResult>;
|
|
337
|
+
/**
|
|
338
|
+
* Output formatting: diarized SRT (with tone), Markdown transcript, and JSON.
|
|
339
|
+
*
|
|
340
|
+
* SRT breaking (spec §5): each finalized segment is one speaker turn. Long turns are
|
|
341
|
+
* split into readable blocks (≤ maxChars / ≤ maxSec) using per-word timing so block
|
|
342
|
+
* boundaries stay time-accurate. The speaker label prefixes each block.
|
|
343
|
+
*/
|
|
443
344
|
|
|
444
|
-
interface
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
speechModel?: string;
|
|
452
|
-
/** language code hint, e.g. "en" */
|
|
453
|
-
languageCode?: string;
|
|
345
|
+
interface FormatOptions {
|
|
346
|
+
/** Prefix each SRT block with "Speaker: ". Default true. */
|
|
347
|
+
labelSpeakers?: boolean;
|
|
348
|
+
/** Append "(tone)" to blocks that have tone tags. Default true. */
|
|
349
|
+
showTone?: boolean;
|
|
350
|
+
/** Title for the markdown transcript. */
|
|
351
|
+
title?: string;
|
|
454
352
|
}
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
353
|
+
/** Format the transcript as a diarized SRT. */
|
|
354
|
+
declare function formatSrt(result: TranscriptResult, opts?: FormatOptions): string;
|
|
355
|
+
/** Format as a readable markdown transcript. */
|
|
356
|
+
declare function formatMarkdown(result: TranscriptResult, opts?: FormatOptions): string;
|
|
357
|
+
/** Format as JSON (full structured result). */
|
|
358
|
+
declare function formatJson(result: TranscriptResult): string;
|
|
459
359
|
|
|
460
|
-
interface
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
}
|
|
465
|
-
interface GeminiPart {
|
|
466
|
-
/** a local file path to upload, OR */
|
|
467
|
-
filePath?: string;
|
|
468
|
-
/** an already-uploaded file, OR */
|
|
469
|
-
uploaded?: UploadedFile;
|
|
470
|
-
/** plain text */
|
|
471
|
-
text?: string;
|
|
472
|
-
}
|
|
473
|
-
interface GeminiOptions {
|
|
474
|
-
apiKey?: string;
|
|
475
|
-
model?: string;
|
|
476
|
-
temperature?: number;
|
|
477
|
-
maxOutputTokens?: number;
|
|
478
|
-
/** JSON schema for structured output; if set, responseMimeType=application/json */
|
|
479
|
-
schema?: unknown;
|
|
480
|
-
/** system instruction */
|
|
481
|
-
systemInstruction?: string;
|
|
482
|
-
/** thinking budget in tokens (Gemini 2.5 family). Ignored by Gemini 3.x. */
|
|
483
|
-
thinkingBudget?: number;
|
|
484
|
-
/** thinking level (Gemini 3.x family): "MINIMAL" | "LOW" | "MEDIUM" | "HIGH". */
|
|
485
|
-
thinkingLevel?: "MINIMAL" | "LOW" | "MEDIUM" | "HIGH";
|
|
486
|
-
/** retries on transient API errors (default 4) */
|
|
487
|
-
retries?: number;
|
|
488
|
-
/** label for this call, surfaced in the onCall log record */
|
|
489
|
-
label?: string;
|
|
490
|
-
}
|
|
491
|
-
interface GeminiResult {
|
|
360
|
+
interface ParsedSrtEntry {
|
|
361
|
+
id: number;
|
|
362
|
+
start: number;
|
|
363
|
+
end: number;
|
|
492
364
|
text: string;
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
outputTokens?: number;
|
|
496
|
-
thoughtsTokens?: number;
|
|
497
|
-
};
|
|
498
|
-
model: string;
|
|
499
|
-
raw: unknown;
|
|
500
|
-
}
|
|
501
|
-
declare class GeminiClient {
|
|
502
|
-
private ai;
|
|
503
|
-
/** if set, invoked once per generate() with the prompt/response/usage (for logging). */
|
|
504
|
-
onCall?: (rec: LlmCallRecord) => void;
|
|
505
|
-
constructor(apiKey?: string);
|
|
506
|
-
/** Upload a local file via the Files API and wait until it's ACTIVE. */
|
|
507
|
-
uploadFile(filePath: string, mimeType?: string): Promise<UploadedFile>;
|
|
508
|
-
deleteFile(name: string): Promise<void>;
|
|
509
|
-
/** Generate content from a mix of files (paths or pre-uploaded) and text. */
|
|
510
|
-
generate(parts: GeminiPart[], options?: GeminiOptions): Promise<GeminiResult>;
|
|
365
|
+
/** Raw timing string as it appeared in the file. */
|
|
366
|
+
timingString: string;
|
|
511
367
|
}
|
|
368
|
+
/** Parse an SRT file string into entries. Tolerant of BOM and \r\n. */
|
|
369
|
+
declare function parseSrt(content: string): ParsedSrtEntry[];
|
|
512
370
|
|
|
513
|
-
export { type
|
|
371
|
+
export { type AlignedSegment, type ApiKeys, type ChunkPlan, type Pass, type PipelineOptions, type Segment, type SpeakerInfo, type TimestampedUtterance, type TimestampedWord, type TranscriptMetadata, type TranscriptResult, alignSegments, assignGlobalSpeakers, finalizeSegments, formatJson, formatMarkdown, formatSrt, identifySpeakers, parseSrt, planChunks, transcribe };
|