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/browser.d.ts
CHANGED
|
@@ -1,740 +1,520 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* Gemini provider (multimodal). Handles file upload + processing poll, text and
|
|
3
|
+
* structured-JSON generation, retries, token tracking, and uploaded-file cleanup.
|
|
3
4
|
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
* - the CONTENT track (from a multimodal LLM): clean diarized text, names, tone.
|
|
7
|
-
* Alignment maps timing onto content to produce the final Transcript.
|
|
5
|
+
* Uses `@google/genai` v1 SDK. Audio is uploaded via the Files API (supports large
|
|
6
|
+
* files) and referenced by URI in the generate request.
|
|
8
7
|
*/
|
|
9
|
-
|
|
10
|
-
interface
|
|
8
|
+
|
|
9
|
+
interface GeminiUsage {
|
|
10
|
+
inputTokens: number;
|
|
11
|
+
outputTokens: number;
|
|
12
|
+
totalTokens: number;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Fetch-based Gemini client (no SDK, no node deps — works in browser AND node).
|
|
17
|
+
* Sends audio as inline base64 (inlineData), which suits chunk-sized files
|
|
18
|
+
* (≤ ~20MB). For larger files, chunk first (ffmpeg.wasm in browser, ffmpeg in node).
|
|
19
|
+
*/
|
|
20
|
+
|
|
21
|
+
interface GeminiFetchOptions {
|
|
22
|
+
apiKey: string;
|
|
23
|
+
/** Override base URL (e.g. a proxy). */
|
|
24
|
+
baseUrl?: string;
|
|
25
|
+
}
|
|
26
|
+
interface GeminiFetchGenerateOptions {
|
|
27
|
+
temperature?: number;
|
|
28
|
+
maxOutputTokens?: number;
|
|
29
|
+
responseSchema?: Record<string, unknown>;
|
|
30
|
+
systemInstruction?: string;
|
|
31
|
+
maxRetries?: number;
|
|
32
|
+
}
|
|
33
|
+
interface GeminiFetchResult {
|
|
11
34
|
text: string;
|
|
12
|
-
|
|
35
|
+
usage: GeminiUsage;
|
|
36
|
+
error?: string;
|
|
37
|
+
}
|
|
38
|
+
declare class GeminiFetchClient {
|
|
39
|
+
private apiKey;
|
|
40
|
+
private baseUrl;
|
|
41
|
+
constructor(opts: GeminiFetchOptions);
|
|
42
|
+
/** Generate from a prompt + inline file parts (ArrayBuffer + mimeType). */
|
|
43
|
+
generate(model: string, prompt: string, files: {
|
|
44
|
+
data: ArrayBuffer | Uint8Array;
|
|
45
|
+
mimeType?: string;
|
|
46
|
+
ext?: string;
|
|
47
|
+
}[], opts?: GeminiFetchGenerateOptions): Promise<GeminiFetchResult>;
|
|
48
|
+
generateJson<T = unknown>(model: string, prompt: string, files: {
|
|
49
|
+
data: ArrayBuffer | Uint8Array;
|
|
50
|
+
mimeType?: string;
|
|
51
|
+
ext?: string;
|
|
52
|
+
}[], responseSchema: Record<string, unknown>, opts?: GeminiFetchGenerateOptions): Promise<{
|
|
53
|
+
data: T | null;
|
|
54
|
+
raw: string;
|
|
55
|
+
error?: string;
|
|
56
|
+
}>;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* Core domain types for offmute-v2.
|
|
61
|
+
*
|
|
62
|
+
* The pipeline produces a timeline of {@link Segment}s, each carrying a speaker,
|
|
63
|
+
* accurate start/end times, the transcribed text, and optional tone/emotion
|
|
64
|
+
* annotations. Segments are the common currency between every stage.
|
|
65
|
+
*/
|
|
66
|
+
/** A single diarized, timestamped, tone-annotated span of speech. */
|
|
67
|
+
interface Segment {
|
|
68
|
+
/** Stable id within the final transcript (assigned at finalize time). */
|
|
69
|
+
id: number;
|
|
70
|
+
/** Start time in seconds (absolute, from the start of the source media). */
|
|
13
71
|
start: number;
|
|
14
|
-
/**
|
|
72
|
+
/** End time in seconds (absolute). */
|
|
15
73
|
end: number;
|
|
16
|
-
/**
|
|
17
|
-
speaker
|
|
18
|
-
/**
|
|
74
|
+
/** Global, consistent speaker label, e.g. "speaker_0" or "Hrishi". */
|
|
75
|
+
speaker: string;
|
|
76
|
+
/** Display name for the speaker (may equal `speaker` until identification). */
|
|
77
|
+
speakerName?: string;
|
|
78
|
+
/** The transcribed words. */
|
|
79
|
+
text: string;
|
|
80
|
+
/** Free-form tone/emotion/behavior annotations, e.g. "hesitant", "laughing". */
|
|
81
|
+
tone?: string[];
|
|
82
|
+
/** Where the timing came from — useful for debugging alignment. */
|
|
83
|
+
timingSource?: "llm" | "aligned" | "timestamped" | "interpolated" | "coarse";
|
|
84
|
+
/** Where the text came from. */
|
|
85
|
+
textSource?: "llm" | "timestamped";
|
|
86
|
+
/** Which chunk produced this segment (pre-merge). */
|
|
87
|
+
sourceChunk?: number;
|
|
88
|
+
/** Alignment confidence in [0,1] when produced by the aligner. */
|
|
19
89
|
confidence?: number;
|
|
90
|
+
/** Per-word timing (for SRT sub-splitting of long turns). */
|
|
91
|
+
words?: {
|
|
92
|
+
text: string;
|
|
93
|
+
start: number;
|
|
94
|
+
end: number;
|
|
95
|
+
matched?: boolean;
|
|
96
|
+
}[];
|
|
20
97
|
}
|
|
21
|
-
/**
|
|
22
|
-
interface
|
|
98
|
+
/** A planned audio chunk with overlap metadata for clean deduplication. */
|
|
99
|
+
interface ChunkPlan {
|
|
100
|
+
index: number;
|
|
101
|
+
/** Absolute start time (seconds). */
|
|
102
|
+
start: number;
|
|
103
|
+
/** Absolute end time (seconds). */
|
|
104
|
+
end: number;
|
|
105
|
+
/** The portion of this chunk that overlaps the previous chunk. */
|
|
106
|
+
overlapWithPrevious: number;
|
|
107
|
+
/**
|
|
108
|
+
* Absolute time after which this chunk's content is "trusted" (i.e. not
|
|
109
|
+
* covered by the previous chunk). Content before this point may be dropped
|
|
110
|
+
* during merge to avoid double-transcription. Equals `start + overlap`.
|
|
111
|
+
*/
|
|
112
|
+
trustedStart: number;
|
|
113
|
+
/** Path to the extracted audio chunk file. */
|
|
114
|
+
path?: string;
|
|
115
|
+
}
|
|
116
|
+
/** A single word with accurate timing (from a timestamped transcriber). */
|
|
117
|
+
interface TimestampedWord {
|
|
23
118
|
text: string;
|
|
24
119
|
start: number;
|
|
25
120
|
end: number;
|
|
26
|
-
/** ASR speaker label (e.g. "A") */
|
|
27
|
-
speaker: string;
|
|
28
121
|
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
122
|
}
|
|
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") */
|
|
123
|
+
/** A speaker as understood by a timestamped diarizer (AssemblyAI/Whisper). */
|
|
124
|
+
interface TimestampedUtterance {
|
|
125
|
+
start: number;
|
|
126
|
+
end: number;
|
|
57
127
|
speaker: string;
|
|
58
128
|
text: string;
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
129
|
+
confidence?: number;
|
|
130
|
+
words?: TimestampedWord[];
|
|
131
|
+
}
|
|
132
|
+
/** The full result of running the pipeline. */
|
|
133
|
+
interface TranscriptResult {
|
|
134
|
+
segments: Segment[];
|
|
135
|
+
speakers: SpeakerInfo[];
|
|
136
|
+
metadata: TranscriptMetadata;
|
|
66
137
|
}
|
|
67
|
-
|
|
68
|
-
/**
|
|
69
|
-
interface Speaker {
|
|
70
|
-
/** stable internal id, e.g. "S1" */
|
|
138
|
+
interface SpeakerInfo {
|
|
139
|
+
/** Global consistent id, e.g. "speaker_0". */
|
|
71
140
|
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 */
|
|
141
|
+
/** Identified name if known, else undefined. */
|
|
142
|
+
name?: string;
|
|
143
|
+
/** Human-readable description from the LLM description pass. */
|
|
79
144
|
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;
|
|
145
|
+
/** Number of segments attributed to this speaker. */
|
|
146
|
+
segmentCount?: number;
|
|
147
|
+
/** Total speaking time in seconds. */
|
|
148
|
+
talkTime?: number;
|
|
149
|
+
/** ASR voice cluster(s) this speaker maps to (voice-anchored evidence for identify). */
|
|
150
|
+
asrVoices?: string[];
|
|
112
151
|
}
|
|
113
152
|
interface TranscriptMetadata {
|
|
114
|
-
|
|
115
|
-
|
|
153
|
+
sourceFile: string;
|
|
154
|
+
duration: number;
|
|
116
155
|
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;
|
|
156
|
+
models: Record<string, string>;
|
|
157
|
+
passes: string[];
|
|
149
158
|
}
|
|
150
159
|
|
|
151
|
-
/** Timestamp helpers. Browser-safe (no node deps). */
|
|
152
|
-
/** seconds -> "HH:MM:SS,mmm" (SRT style, comma decimal). */
|
|
153
|
-
declare function secondsToSrtTime(seconds: number): string;
|
|
154
|
-
/** "HH:MM:SS,mmm" or "HH:MM:SS.mmm" or "MM:SS" -> seconds. */
|
|
155
|
-
declare function srtTimeToSeconds(timestamp: string): number;
|
|
156
|
-
/** "mm:ss" relative timestamp -> seconds, or null. Tolerates "h:mm:ss" too. */
|
|
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;
|
|
162
|
-
|
|
163
|
-
interface SrtCue {
|
|
164
|
-
id: number;
|
|
165
|
-
start: number;
|
|
166
|
-
end: number;
|
|
167
|
-
/** full text (may contain a leading "Speaker: " prefix) */
|
|
168
|
-
text: string;
|
|
169
|
-
/** speaker parsed from a leading "Name: " prefix, if present */
|
|
170
|
-
speaker?: string;
|
|
171
|
-
/** text with the speaker prefix stripped */
|
|
172
|
-
body: string;
|
|
173
|
-
}
|
|
174
|
-
/** Split a "Speaker: text" line into {speaker, body}. Heuristic, conservative. */
|
|
175
|
-
declare function splitSpeakerPrefix(text: string): {
|
|
176
|
-
speaker?: string;
|
|
177
|
-
body: string;
|
|
178
|
-
};
|
|
179
|
-
/** Parse an SRT string into cues. Lenient about blank lines / numbering. */
|
|
180
|
-
declare function parseSrt(content: string): SrtCue[];
|
|
181
|
-
interface SrtFormatOptions {
|
|
182
|
-
/** include "Speaker: " prefix in each cue body */
|
|
183
|
-
includeSpeaker?: boolean;
|
|
184
|
-
}
|
|
185
|
-
/** Format cues (with explicit speaker) into an SRT string. */
|
|
186
|
-
declare function formatSrt(cues: Array<{
|
|
187
|
-
start: number;
|
|
188
|
-
end: number;
|
|
189
|
-
speaker?: string;
|
|
190
|
-
text: string;
|
|
191
|
-
}>, options?: SrtFormatOptions): string;
|
|
192
|
-
|
|
193
160
|
/**
|
|
194
|
-
*
|
|
195
|
-
*
|
|
196
|
-
*
|
|
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).
|
|
161
|
+
* Fetch-based AssemblyAI client (no SDK, no node deps — browser + node). Uploads a
|
|
162
|
+
* Blob, creates a transcript with speaker_labels + universal model, polls, and
|
|
163
|
+
* returns utterances + words. Same shape as the node provider's result.
|
|
204
164
|
*/
|
|
205
165
|
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
ai: number | null;
|
|
213
|
-
/** index into sequence B (ASR words), or null if B had a gap (LLM-only token) */
|
|
214
|
-
bi: number | null;
|
|
215
|
-
/** true if ai and bi are a real (normalized-equal) match */
|
|
216
|
-
match: boolean;
|
|
166
|
+
interface AssemblyAIFetchResult {
|
|
167
|
+
utterances: TimestampedUtterance[];
|
|
168
|
+
words: TimestampedWord[];
|
|
169
|
+
durationSec: number;
|
|
170
|
+
speakers: string[];
|
|
171
|
+
transcriptId: string;
|
|
217
172
|
}
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
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.
|
|
235
|
-
*
|
|
236
|
-
* Matrices are flat Int32Array/Uint8Array (compact, ~5 bytes/cell) but this is
|
|
237
|
-
* still full O(n·m) memory — there is NO banding/Hirschberg here. That is fine per
|
|
238
|
-
* chunk (a few thousand tokens ⇒ tens of MB); whole-file alignment is done per
|
|
239
|
-
* chunk to keep n·m bounded. (Add a banded/Hirschberg variant only if single-shot
|
|
240
|
-
* alignment of very long inputs is ever needed.)
|
|
241
|
-
*/
|
|
242
|
-
declare function alignTokens(a: string[], b: string[]): AlignPair[];
|
|
243
|
-
interface AlignedToken {
|
|
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;
|
|
173
|
+
declare class AssemblyAIFetchClient {
|
|
174
|
+
private apiKey;
|
|
175
|
+
constructor(apiKey: string);
|
|
176
|
+
transcribe(audio: Blob, opts?: {
|
|
177
|
+
speakersExpected?: number;
|
|
178
|
+
}): Promise<AssemblyAIFetchResult>;
|
|
255
179
|
}
|
|
256
|
-
|
|
257
|
-
interface
|
|
258
|
-
|
|
180
|
+
|
|
181
|
+
interface ChatMessage {
|
|
182
|
+
role: "system" | "user" | "assistant";
|
|
183
|
+
content: string;
|
|
259
184
|
}
|
|
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
|
-
interface AlignedSegment {
|
|
272
|
-
turnIndex: number;
|
|
273
|
-
start: number;
|
|
274
|
-
end: number;
|
|
185
|
+
interface ChatResult {
|
|
275
186
|
text: string;
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
interface SegmentOptions {
|
|
282
|
-
/** split into display-sized cues (sentence / gap / length). Default false = one segment per turn. */
|
|
283
|
-
subSegment?: boolean;
|
|
284
|
-
/** max characters per display cue */
|
|
285
|
-
maxChars?: number;
|
|
286
|
-
/** max seconds per display cue */
|
|
287
|
-
maxDuration?: number;
|
|
288
|
-
/** split when the gap before the next token exceeds this (seconds) */
|
|
289
|
-
gapSplit?: number;
|
|
290
|
-
/** minimum characters before allowing a sentence-boundary split */
|
|
291
|
-
minChars?: number;
|
|
187
|
+
usage: {
|
|
188
|
+
inputTokens: number;
|
|
189
|
+
outputTokens: number;
|
|
190
|
+
};
|
|
191
|
+
error?: string;
|
|
292
192
|
}
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
/**
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
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;
|
|
322
|
-
}
|
|
323
|
-
declare function toMarkdown(transcript: Transcript, options?: MarkdownOptions): string;
|
|
324
|
-
declare function toJSON(transcript: Transcript): string;
|
|
325
|
-
/** A compact plain-text transcript (no markdown). */
|
|
326
|
-
declare function toText(transcript: Transcript, options?: {
|
|
327
|
-
includeTimestamps?: boolean;
|
|
328
|
-
}): string;
|
|
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>;
|
|
341
|
-
}
|
|
342
|
-
interface BuiltSpeakers {
|
|
343
|
-
speakers: Speaker[];
|
|
344
|
-
/** raw turn label -> speaker id */
|
|
345
|
-
labelToId: Map<string, string>;
|
|
193
|
+
interface ChatOptions {
|
|
194
|
+
temperature?: number;
|
|
195
|
+
maxTokens?: number;
|
|
196
|
+
responseJson?: boolean;
|
|
197
|
+
maxRetries?: number;
|
|
198
|
+
/** What this call is for (logged): identify | … */
|
|
199
|
+
logKind?: string;
|
|
200
|
+
}
|
|
201
|
+
declare class OpenAICompatClient {
|
|
202
|
+
private baseUrl;
|
|
203
|
+
private apiKey;
|
|
204
|
+
private defaultModel;
|
|
205
|
+
private providerName;
|
|
206
|
+
constructor(baseUrl: string, apiKey: string, defaultModel: string, providerName?: string);
|
|
207
|
+
static fromProvider(provider: string, apiKey: string, defaultModel: string): OpenAICompatClient;
|
|
208
|
+
chat(model: string | undefined, messages: ChatMessage[], opts?: ChatOptions): Promise<ChatResult>;
|
|
209
|
+
chatJson<T = unknown>(model: string | undefined, messages: ChatMessage[], opts?: ChatOptions): Promise<{
|
|
210
|
+
data: T | null;
|
|
211
|
+
raw: string;
|
|
212
|
+
error?: string;
|
|
213
|
+
}>;
|
|
346
214
|
}
|
|
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
215
|
|
|
353
216
|
/**
|
|
354
|
-
*
|
|
355
|
-
*
|
|
356
|
-
*
|
|
357
|
-
* Browser-safe.
|
|
217
|
+
* LLM transcription prompt + response schema. Asks Gemini for diarized segments with
|
|
218
|
+
* relative `mm:ss` timestamps (ipgu-style — coarse but good enough to validate span
|
|
219
|
+
* and gate alignment), speaker labels, verbatim text, and tone tags.
|
|
358
220
|
*/
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
221
|
+
interface LlmSegmentRaw {
|
|
222
|
+
speaker: string;
|
|
223
|
+
start: string;
|
|
224
|
+
end: string;
|
|
225
|
+
text: string;
|
|
226
|
+
tone?: string[];
|
|
227
|
+
}
|
|
228
|
+
interface LlmTranscriptJson {
|
|
229
|
+
segments: LlmSegmentRaw[];
|
|
230
|
+
}
|
|
231
|
+
/** JSON schema for Gemini structured output. String-typed enum values match `Type`. */
|
|
232
|
+
declare const TRANSCRIPT_SCHEMA: {
|
|
233
|
+
readonly type: "OBJECT";
|
|
234
|
+
readonly properties: {
|
|
235
|
+
readonly segments: {
|
|
236
|
+
readonly type: "ARRAY";
|
|
237
|
+
readonly items: {
|
|
238
|
+
readonly type: "OBJECT";
|
|
239
|
+
readonly properties: {
|
|
240
|
+
readonly speaker: {
|
|
241
|
+
readonly type: "STRING";
|
|
242
|
+
readonly description: "Speaker label. Use an identified name from the roster if confident, else 'Speaker A', 'Speaker B', etc.";
|
|
243
|
+
};
|
|
244
|
+
readonly start: {
|
|
245
|
+
readonly type: "STRING";
|
|
246
|
+
readonly description: "Relative start time as mm:ss (00:00 = start of this audio chunk)";
|
|
247
|
+
};
|
|
248
|
+
readonly end: {
|
|
249
|
+
readonly type: "STRING";
|
|
250
|
+
readonly description: "Relative end time as mm:ss";
|
|
251
|
+
};
|
|
252
|
+
readonly text: {
|
|
253
|
+
readonly type: "STRING";
|
|
254
|
+
readonly description: "Verbatim transcribed words, including fillers and false starts";
|
|
255
|
+
};
|
|
256
|
+
readonly tone: {
|
|
257
|
+
readonly type: "ARRAY";
|
|
258
|
+
readonly items: {
|
|
259
|
+
readonly type: "STRING";
|
|
260
|
+
};
|
|
261
|
+
readonly description: "Tone/behavior tags e.g. hesitant, laughing, contemplating, urgent, sarcastic. Empty array if neutral.";
|
|
262
|
+
};
|
|
263
|
+
};
|
|
264
|
+
readonly required: readonly ["speaker", "start", "end", "text"];
|
|
265
|
+
};
|
|
266
|
+
};
|
|
383
267
|
};
|
|
384
|
-
|
|
268
|
+
readonly required: readonly ["segments"];
|
|
269
|
+
};
|
|
270
|
+
interface ChunkContext {
|
|
271
|
+
/** Meeting description (from describe pass). */
|
|
272
|
+
description?: string;
|
|
273
|
+
/** Speaker roster / hints. */
|
|
274
|
+
roster?: string;
|
|
275
|
+
/** Tail of the previous chunk's transcript for continuity (last few segments). */
|
|
385
276
|
previousTail?: string;
|
|
277
|
+
/** Chunk index (1-based) and total. */
|
|
278
|
+
index: number;
|
|
279
|
+
total: number;
|
|
280
|
+
/** Free-form user instructions. */
|
|
281
|
+
instructions?: string;
|
|
386
282
|
}
|
|
387
|
-
declare
|
|
388
|
-
declare function buildDiarizationPrompt(input: DiarizationPromptInput): string;
|
|
389
|
-
/** Build a compact ASR hint string from utterances, trimming long ones. */
|
|
390
|
-
declare function buildAsrHint(asr: AsrResult, maxUtterances?: number, maxCharsPerUtterance?: number): string;
|
|
283
|
+
declare function transcriptionPrompt(ctx: ChunkContext): string;
|
|
391
284
|
|
|
392
|
-
/** Chunk-time calculation and overlap-merge of aligned segments. Browser-safe. */
|
|
393
|
-
|
|
394
|
-
/**
|
|
395
|
-
* Split a duration into overlapping time chunks.
|
|
396
|
-
* A trailing chunk shorter than 1/3 of chunkSeconds is merged into the previous one.
|
|
397
|
-
*/
|
|
398
|
-
declare function calculateChunks(totalSeconds: number, chunkSeconds: number, overlapSeconds: number): TimeChunk[];
|
|
399
285
|
/**
|
|
400
|
-
*
|
|
401
|
-
*
|
|
402
|
-
* each output segment to the chunk that owns its center time means every piece of
|
|
403
|
-
* speech is emitted exactly once — no overlap duplication — without fuzzy dedup.
|
|
286
|
+
* Per-chunk LLM transcription: call Gemini, parse relative mm:ss timestamps to
|
|
287
|
+
* absolute seconds (chunk offset), validate span + monotonicity, retry on failure.
|
|
404
288
|
*/
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
speakerLabel: string;
|
|
413
|
-
tone?: string;
|
|
289
|
+
|
|
290
|
+
interface ParsedLlmSegment {
|
|
291
|
+
speaker: string;
|
|
292
|
+
/** Absolute start (seconds), chunk offset applied. */
|
|
293
|
+
startSec: number;
|
|
294
|
+
/** Absolute end (seconds). */
|
|
295
|
+
endSec: number;
|
|
414
296
|
text: string;
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
297
|
+
tone: string[];
|
|
298
|
+
rawStart: string;
|
|
299
|
+
rawEnd: string;
|
|
300
|
+
/** Source chunk index (set by the pipeline; used for ownership partitioning). */
|
|
301
|
+
chunkIndex?: number;
|
|
302
|
+
/** Trusted-start (absolute) of the source chunk — content before this is overlap
|
|
303
|
+
* owned by the previous chunk. Segments whose center is before this are dropped to
|
|
304
|
+
* avoid double-printing the overlap region. */
|
|
305
|
+
trustedStart?: number;
|
|
306
|
+
}
|
|
307
|
+
/** Parse + offset-adjust raw LLM segments. Drops unparseable ones (with a warning). */
|
|
308
|
+
declare function parseLlmSegments(data: LlmTranscriptJson, chunkOffsetSec: number): {
|
|
309
|
+
segments: ParsedLlmSegment[];
|
|
310
|
+
dropped: number;
|
|
311
|
+
};
|
|
312
|
+
|
|
419
313
|
/**
|
|
420
|
-
*
|
|
421
|
-
*
|
|
422
|
-
*
|
|
423
|
-
*
|
|
424
|
-
*
|
|
314
|
+
* Aligner: transfers accurate word-level timestamps from an ASR transcript onto the
|
|
315
|
+
* richer LLM transcript (diarized, tone-annotated).
|
|
316
|
+
*
|
|
317
|
+
* Approach (ts-aligner): align the ENTIRE LLM token stream (all segments, in order)
|
|
318
|
+
* against the ASR word stream in a single edit-distance DP pass, then split the
|
|
319
|
+
* timed result back into segments. Long, ordered sequences pin common words ("the",
|
|
320
|
+
* "as") to their correct occurrence — a per-segment windowed alignment scatters them
|
|
321
|
+
* to later occurrences and drifts. One DP over the chunk is O(tokens × asrWords).
|
|
425
322
|
*/
|
|
426
|
-
declare function mergeChunkSegments(segments: MergeableSegment[], chunkBoundaries: TimeChunk[]): MergeableSegment[];
|
|
427
323
|
|
|
428
|
-
interface
|
|
429
|
-
|
|
324
|
+
interface AlignedWord {
|
|
325
|
+
text: string;
|
|
430
326
|
start: number;
|
|
431
327
|
end: number;
|
|
432
|
-
|
|
433
|
-
/** true if this is the first word of its source segment (a real boundary) */
|
|
434
|
-
isBoundary?: boolean;
|
|
328
|
+
matched: boolean;
|
|
435
329
|
}
|
|
436
|
-
|
|
437
|
-
|
|
330
|
+
interface AlignedSegment {
|
|
331
|
+
speaker: string;
|
|
332
|
+
/** Display name (set by the consistency/identification pass). */
|
|
333
|
+
speakerName?: string;
|
|
438
334
|
start: number;
|
|
439
335
|
end: number;
|
|
440
|
-
speaker: string;
|
|
441
336
|
text: string;
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
matchedForSpeaker: number;
|
|
458
|
-
/** timestamp error stats (seconds) over matched words */
|
|
459
|
-
timeMedian: number;
|
|
460
|
-
timeP90: number;
|
|
461
|
-
timeMean: number;
|
|
462
|
-
timedMatches: number;
|
|
463
|
-
/** boundary error: |hyp - ref| at REAL ref cue-start times (clean timing signal) */
|
|
464
|
-
boundaryMedian: number;
|
|
465
|
-
boundaryP90: number;
|
|
466
|
-
boundaryMean: number;
|
|
467
|
-
boundaryMatches: number;
|
|
468
|
-
}
|
|
337
|
+
tone: string[];
|
|
338
|
+
confidence: number;
|
|
339
|
+
timingSource: "aligned" | "interpolated" | "coarse" | "timestamped";
|
|
340
|
+
words: AlignedWord[];
|
|
341
|
+
sourceIndex: number;
|
|
342
|
+
}
|
|
343
|
+
interface AlignOptions {
|
|
344
|
+
/** Below this confidence, mark timing as interpolated (flag for repair). */
|
|
345
|
+
confidenceThreshold?: number;
|
|
346
|
+
/** Gate ASR to words within this many seconds of the LLM span (0 = use all). */
|
|
347
|
+
timeMarginSec?: number;
|
|
348
|
+
}
|
|
349
|
+
/** Align LLM segments to ASR words (single DP over the chunk). Segments need not be sorted. */
|
|
350
|
+
declare function alignSegments(llmSegments: ParsedLlmSegment[], asrWords: TimestampedWord[], opts?: AlignOptions): AlignedSegment[];
|
|
351
|
+
|
|
469
352
|
/**
|
|
470
|
-
*
|
|
471
|
-
*
|
|
353
|
+
* Speaker-consistency pass (diarization level 2: anonymous-but-consistent).
|
|
354
|
+
*
|
|
355
|
+
* The ASR diarizer (AssemblyAI) labels speakers over the WHOLE file, so its labels
|
|
356
|
+
* are already globally consistent. We use them as the backbone: each aligned LLM
|
|
357
|
+
* segment inherits the ASR speaker that dominates its time window. The LLM's richer
|
|
358
|
+
* per-chunk labels (role/name) become display names. This gives consistent A/B/C
|
|
359
|
+
* labels across chunks for free, and survives LLM label drift between chunks.
|
|
472
360
|
*/
|
|
473
|
-
declare function evaluateWords(ref: EvalWord[], hyp: EvalWord[]): EvalResult;
|
|
474
361
|
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
declare function withRetry<T>(fn: () => Promise<T>, opts?: RetryOptions): Promise<T>;
|
|
362
|
+
interface ConsistencyResult {
|
|
363
|
+
segments: AlignedSegment[];
|
|
364
|
+
speakers: SpeakerInfo[];
|
|
365
|
+
/** ASR speaker id → chosen display name. */
|
|
366
|
+
displayNames: Record<string, string>;
|
|
367
|
+
/** LLM label → ASR speaker id (for debugging / identification). */
|
|
368
|
+
llmLabelToAsr: Record<string, string>;
|
|
369
|
+
}
|
|
370
|
+
/** Assign globally-consistent speaker ids to aligned segments via ASR time overlap,
|
|
371
|
+
* merging ASR speakers that the LLM consistently labels the same specific name/role
|
|
372
|
+
* (handles ASR over-splitting, e.g. one presenter split into speaker_A + speaker_B).
|
|
373
|
+
* Global ids "Speaker A", "Speaker B", … are assigned by total talk time. */
|
|
374
|
+
declare function assignGlobalSpeakers(segments: AlignedSegment[], asrUtterances: TimestampedUtterance[], opts?: {
|
|
375
|
+
hasDiarization?: boolean;
|
|
376
|
+
}): ConsistencyResult;
|
|
491
377
|
|
|
492
378
|
/**
|
|
493
|
-
*
|
|
494
|
-
*
|
|
495
|
-
*
|
|
379
|
+
* Speaker-identification pass (diarization level 3). A text reasoner (DeepSeek) reads
|
|
380
|
+
* the consistent transcript + roster and names speakers from content cues — e.g.
|
|
381
|
+
* "my name is Rishi, I run Southbridge" identifies the presenter. A speaker may
|
|
382
|
+
* self-identify in only one chunk, so the reasoner must see the whole transcript.
|
|
496
383
|
*/
|
|
497
384
|
|
|
498
|
-
/** Minimal
|
|
499
|
-
interface
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
thinkingBudget?: number;
|
|
509
|
-
thinkingLevel?: "MINIMAL" | "LOW" | "MEDIUM" | "HIGH";
|
|
510
|
-
/** JSON schema → structured-output (JSON) mode */
|
|
511
|
-
schema?: unknown;
|
|
512
|
-
/** label for call logging */
|
|
513
|
-
label?: string;
|
|
514
|
-
}): Promise<{
|
|
515
|
-
text: string;
|
|
516
|
-
}>;
|
|
385
|
+
/** Minimal segment shape needed for identification. */
|
|
386
|
+
interface IdentifySegment {
|
|
387
|
+
speaker: string;
|
|
388
|
+
text: string;
|
|
389
|
+
}
|
|
390
|
+
interface IdentifiedSpeaker {
|
|
391
|
+
id: string;
|
|
392
|
+
name: string;
|
|
393
|
+
confidence: "high" | "medium" | "low";
|
|
394
|
+
evidence: string;
|
|
517
395
|
}
|
|
518
396
|
interface IdentifyResult {
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
descriptions: Record<string, string>;
|
|
397
|
+
nameMap: Record<string, string>;
|
|
398
|
+
speakers: IdentifiedSpeaker[];
|
|
399
|
+
reasoning: string;
|
|
523
400
|
}
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
llmModel?: string;
|
|
527
|
-
/** per raw-label distribution of ASR speaker labels (voice anchor) */
|
|
528
|
-
asrSpeakerByLabel?: Record<string, Record<string, number>>;
|
|
529
|
-
}
|
|
530
|
-
/** Strip code fences and parse the first JSON object found. */
|
|
531
|
-
declare function parseIdentifyJson(text: string): {
|
|
532
|
-
speakers: Array<{
|
|
533
|
-
rawLabels: string[];
|
|
534
|
-
name: string;
|
|
535
|
-
description?: string;
|
|
536
|
-
}>;
|
|
537
|
-
} | null;
|
|
538
|
-
declare function identifySpeakersLLM(gen: TextGenerator, turns: LlmLine[], options?: IdentifyOptions): Promise<IdentifyResult>;
|
|
401
|
+
/** Identify speakers via a text reasoner. Returns a name map (speaker id → name). */
|
|
402
|
+
declare function identifySpeakers(client: OpenAICompatClient, model: string, segments: IdentifySegment[], speakers: SpeakerInfo[], roster: string, knownSpeakers?: string[]): Promise<IdentifyResult>;
|
|
539
403
|
|
|
540
404
|
/**
|
|
541
|
-
*
|
|
542
|
-
*
|
|
543
|
-
*
|
|
405
|
+
* Finalize: dedup chunk-overlap duplicates, fix timestamp overlaps, clamp durations,
|
|
406
|
+
* and produce the final renumbered Segment list ready for formatting.
|
|
407
|
+
*
|
|
408
|
+
* Improvements over ipgu's finalizer: (1) fuzzy near-duplicate dedup (we have no
|
|
409
|
+
* reference SRT ids to dedup by), (2) a FINAL overlap re-check pass after clamping
|
|
410
|
+
* (ipgu noted clamping can re-introduce overlaps but didn't re-check).
|
|
544
411
|
*/
|
|
545
412
|
|
|
546
|
-
interface
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
speakerLabel: string;
|
|
550
|
-
tone?: string;
|
|
551
|
-
text: string;
|
|
552
|
-
matchRatio: number;
|
|
553
|
-
}
|
|
554
|
-
/**
|
|
555
|
-
* Align a list of LLM turns to ASR words (or fall back to the LLM's coarse
|
|
556
|
-
* timestamps when no ASR words are given) and produce flat timed segments plus a
|
|
557
|
-
* per-label ASR-voice distribution (for downstream speaker identification).
|
|
558
|
-
*/
|
|
559
|
-
declare function alignTurnsToSegments(turns: LlmLine[], asrWords: TimedWord[] | undefined, totalDuration: number, subSegment: boolean): {
|
|
560
|
-
segments: PlainSegment[];
|
|
561
|
-
voiceDist: Record<string, Record<string, number>>;
|
|
562
|
-
};
|
|
563
|
-
interface AssembleOptions {
|
|
564
|
-
knownSpeakers?: Record<string, string>;
|
|
565
|
-
resolvedNames?: Record<string, string>;
|
|
566
|
-
descriptions?: Record<string, string>;
|
|
413
|
+
interface FinalizeOptions {
|
|
414
|
+
/** Drop segments shorter than this (seconds). */
|
|
415
|
+
minSegmentSec?: number;
|
|
567
416
|
}
|
|
568
|
-
/**
|
|
569
|
-
declare function
|
|
417
|
+
/** Convert aligned+consistent segments into the final Segment list (renumbered, deduped, clamped). */
|
|
418
|
+
declare function finalizeSegments(segments: AlignedSegment[], opts?: FinalizeOptions): Segment[];
|
|
419
|
+
|
|
570
420
|
/**
|
|
571
|
-
*
|
|
572
|
-
*
|
|
573
|
-
*
|
|
421
|
+
* Output formatting: diarized SRT (with tone), Markdown transcript, and JSON.
|
|
422
|
+
*
|
|
423
|
+
* SRT breaking (spec §5): each finalized segment is one speaker turn. Long turns are
|
|
424
|
+
* split into readable blocks (≤ maxChars / ≤ maxSec) using per-word timing so block
|
|
425
|
+
* boundaries stay time-accurate. The speaker label prefixes each block.
|
|
574
426
|
*/
|
|
575
|
-
declare function assembleTranscript(input: {
|
|
576
|
-
turns: LlmLine[];
|
|
577
|
-
asr?: AsrResult;
|
|
578
|
-
durationSeconds: number;
|
|
579
|
-
}, options?: AssembleOptions): {
|
|
580
|
-
transcript: Transcript;
|
|
581
|
-
voiceDist: Record<string, Record<string, number>>;
|
|
582
|
-
};
|
|
583
427
|
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
mimeType: string;
|
|
592
|
-
displayName?: string;
|
|
593
|
-
};
|
|
594
|
-
/** an already-uploaded file */
|
|
595
|
-
uploaded?: {
|
|
596
|
-
uri: string;
|
|
597
|
-
mimeType: string;
|
|
598
|
-
};
|
|
599
|
-
}
|
|
600
|
-
interface UploadedFile {
|
|
601
|
-
uri: string;
|
|
602
|
-
mimeType: string;
|
|
603
|
-
name: string;
|
|
604
|
-
state: string;
|
|
605
|
-
}
|
|
606
|
-
interface GeminiFetchOptions {
|
|
607
|
-
model?: string;
|
|
608
|
-
temperature?: number;
|
|
609
|
-
maxOutputTokens?: number;
|
|
610
|
-
systemInstruction?: string;
|
|
611
|
-
thinkingLevel?: "MINIMAL" | "LOW" | "MEDIUM" | "HIGH";
|
|
612
|
-
thinkingBudget?: number;
|
|
613
|
-
retries?: number;
|
|
614
|
-
/** JSON schema for structured output */
|
|
615
|
-
schema?: unknown;
|
|
616
|
-
/** label for this call, surfaced in onCall */
|
|
617
|
-
label?: string;
|
|
618
|
-
}
|
|
619
|
-
interface GeminiFetchResult {
|
|
620
|
-
text: string;
|
|
621
|
-
usage?: {
|
|
622
|
-
inputTokens?: number;
|
|
623
|
-
outputTokens?: number;
|
|
624
|
-
thoughtsTokens?: number;
|
|
625
|
-
};
|
|
626
|
-
model: string;
|
|
627
|
-
raw: unknown;
|
|
628
|
-
}
|
|
629
|
-
declare class GeminiFetchClient {
|
|
630
|
-
private key;
|
|
631
|
-
private base;
|
|
632
|
-
/** if set, invoked once per generate() with the prompt/response/usage (for logging). */
|
|
633
|
-
onCall?: (rec: LlmCallRecord) => void;
|
|
634
|
-
constructor(apiKey?: string, baseUrl?: string);
|
|
635
|
-
/** Upload media via the Files API resumable protocol; poll until ACTIVE. */
|
|
636
|
-
uploadFile(bytes: Bytes, mimeType: string, displayName?: string): Promise<UploadedFile>;
|
|
637
|
-
deleteFile(name: string): Promise<void>;
|
|
638
|
-
generate(parts: GeminiFetchPart[], options?: GeminiFetchOptions): Promise<GeminiFetchResult>;
|
|
428
|
+
interface FormatOptions {
|
|
429
|
+
/** Prefix each SRT block with "Speaker: ". Default true. */
|
|
430
|
+
labelSpeakers?: boolean;
|
|
431
|
+
/** Append "(tone)" to blocks that have tone tags. Default true. */
|
|
432
|
+
showTone?: boolean;
|
|
433
|
+
/** Title for the markdown transcript. */
|
|
434
|
+
title?: string;
|
|
639
435
|
}
|
|
436
|
+
/** Format the transcript as a diarized SRT. */
|
|
437
|
+
declare function formatSrt(result: TranscriptResult, opts?: FormatOptions): string;
|
|
438
|
+
/** Format as a readable markdown transcript. */
|
|
439
|
+
declare function formatMarkdown(result: TranscriptResult, opts?: FormatOptions): string;
|
|
440
|
+
/** Format as JSON (full structured result). */
|
|
441
|
+
declare function formatJson(result: TranscriptResult): string;
|
|
640
442
|
|
|
641
443
|
/**
|
|
642
|
-
*
|
|
643
|
-
*
|
|
644
|
-
*
|
|
444
|
+
* In-browser preprocessing via ffmpeg.wasm — the piece the browser bundle punted on.
|
|
445
|
+
* Extracts mono 16kHz audio (for ASR + chunking) and keyframes (for video) from a raw
|
|
446
|
+
* media Blob, so the full pipeline can run in-browser.
|
|
447
|
+
*
|
|
448
|
+
* Requires the optional peer deps `@ffmpeg/ffmpeg` and `@ffmpeg/util`, loaded dynamically
|
|
449
|
+
* (so they're not bundled into the Node build). The ffmpeg-core is fetched from a CDN at
|
|
450
|
+
* runtime (configurable via `coreBase`).
|
|
451
|
+
*
|
|
452
|
+
* ⚠️ Verification note: this adapter follows the @ffmpeg/ffmpeg 0.12 API and compiles clean,
|
|
453
|
+
* but wasm execution can only be verified in a real browser (no browser in the dev env here).
|
|
454
|
+
* See examples/browser/index.html for a runnable wiring, and verify in your browser.
|
|
645
455
|
*/
|
|
646
456
|
|
|
647
|
-
interface
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
457
|
+
interface FfmpegWasmOptions {
|
|
458
|
+
/** Base URL for the ffmpeg-core files (default: unpkg @ffmpeg/core 0.12.x). */
|
|
459
|
+
coreBase?: string;
|
|
460
|
+
}
|
|
461
|
+
interface BrowserPreprocessResult {
|
|
462
|
+
/** Whole mono 16kHz FLAC audio (for the ASR whole-file pass). */
|
|
463
|
+
audio: Blob;
|
|
464
|
+
/** Per-chunk mono 16kHz FLAC Blobs + absolute [start,end] (for per-chunk LLM). */
|
|
465
|
+
chunks: {
|
|
466
|
+
data: Blob;
|
|
467
|
+
start: number;
|
|
468
|
+
end: number;
|
|
469
|
+
}[];
|
|
470
|
+
/** Keyframe JPEG Blobs (video only). */
|
|
471
|
+
keyframes: Blob[];
|
|
662
472
|
}
|
|
663
|
-
interface AaiTranscript {
|
|
664
|
-
status: string;
|
|
665
|
-
error?: string;
|
|
666
|
-
audio_duration?: number;
|
|
667
|
-
language_code?: string;
|
|
668
|
-
words?: AaiWord[];
|
|
669
|
-
utterances?: Array<AaiWord & {
|
|
670
|
-
words?: AaiWord[];
|
|
671
|
-
}> | null;
|
|
672
|
-
}
|
|
673
|
-
declare function transcribeWithAssemblyAIFetch(audio: Bytes, options?: AssemblyAiFetchOptions): Promise<{
|
|
674
|
-
asr: AsrResult;
|
|
675
|
-
raw: AaiTranscript;
|
|
676
|
-
}>;
|
|
677
|
-
|
|
678
473
|
/**
|
|
679
|
-
*
|
|
680
|
-
*
|
|
681
|
-
* the bundle. Functions operate on the instance's in-memory FS.
|
|
682
|
-
*
|
|
683
|
-
* import { FFmpeg } from "@ffmpeg/ffmpeg";
|
|
684
|
-
* const ff = new FFmpeg(); await ff.load();
|
|
685
|
-
* const audio = await extractAudioWasm(ff, new Uint8Array(await file.arrayBuffer()));
|
|
474
|
+
* Preprocess a raw media Blob in-browser: extract mono 16kHz FLAC, slice it into chunks,
|
|
475
|
+
* and (for video) extract keyframes. Returns what the browser pipeline needs.
|
|
686
476
|
*/
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
exec(args: string[]): Promise<unknown>;
|
|
692
|
-
deleteFile?(path: string): Promise<unknown>;
|
|
693
|
-
}
|
|
477
|
+
declare function preprocessInBrowser(input: Blob, chunks: ChunkPlan[], opts?: FfmpegWasmOptions & {
|
|
478
|
+
keyframeCount?: number;
|
|
479
|
+
isVideo?: boolean;
|
|
480
|
+
}): Promise<BrowserPreprocessResult>;
|
|
694
481
|
|
|
695
482
|
/**
|
|
696
|
-
*
|
|
697
|
-
*
|
|
698
|
-
*
|
|
699
|
-
*
|
|
483
|
+
* offmute-v2 — browser entry.
|
|
484
|
+
*
|
|
485
|
+
* The core logic (alignment, consistency, identification, finalize, formatting) is
|
|
486
|
+
* pure TypeScript with no node deps, so it runs unchanged in the browser. This entry
|
|
487
|
+
* re-exports it alongside fetch-based providers (no SDK, no node), plus a
|
|
488
|
+
* `transcribeBrowser` orchestrator.
|
|
489
|
+
*
|
|
490
|
+
* Browser constraints:
|
|
491
|
+
* - No ffmpeg: the caller provides an already-extracted mono audio Blob (use
|
|
492
|
+
* ffmpeg.wasm to extract/chunk from a video file). `transcribeBrowser` sends the
|
|
493
|
+
* whole Blob to AssemblyAI (whole-file) and to Gemini inline (base64), which suits
|
|
494
|
+
* files ≤ ~20MB. For longer files, chunk with ffmpeg.wasm and call the stages
|
|
495
|
+
* directly (alignSegments etc.) per chunk.
|
|
496
|
+
* - API keys are supplied by the caller (e.g. from user input / your backend).
|
|
700
497
|
*/
|
|
701
498
|
|
|
702
|
-
interface
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
/**
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
gemini: string;
|
|
711
|
-
assemblyai: string;
|
|
712
|
-
};
|
|
499
|
+
interface TranscribeBrowserOptions {
|
|
500
|
+
/** Mono audio Blob (caller extracts via ffmpeg.wasm). ≤ ~20MB for inline Gemini. */
|
|
501
|
+
audio: Blob;
|
|
502
|
+
geminiApiKey: string;
|
|
503
|
+
assemblyaiApiKey: string;
|
|
504
|
+
/** Audio file extension for MIME detection (default "flac"). */
|
|
505
|
+
audioExt?: string;
|
|
506
|
+
model?: string;
|
|
713
507
|
instructions?: string;
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
onProgress?: (e: BrowserProgress) => void;
|
|
726
|
-
/** invoked once per LLM call with its prompt/response/usage (for inspection/debug) */
|
|
727
|
-
onLlmCall?: (rec: LlmCallRecord) => void;
|
|
728
|
-
/** cancel the run (cooperatively, at stage and chunk boundaries) */
|
|
729
|
-
signal?: AbortSignal;
|
|
730
|
-
}
|
|
731
|
-
interface BrowserTranscribeResult {
|
|
732
|
-
transcript: Transcript;
|
|
733
|
-
srt: string;
|
|
734
|
-
markdown: string;
|
|
735
|
-
json: string;
|
|
736
|
-
asr: AsrResult;
|
|
737
|
-
}
|
|
738
|
-
declare function transcribeInBrowser(input: Blob | Uint8Array, options: TranscribeInBrowserOptions): Promise<BrowserTranscribeResult>;
|
|
508
|
+
level?: 1 | 2 | 3;
|
|
509
|
+
deepseekApiKey?: string;
|
|
510
|
+
knownSpeakers?: string[];
|
|
511
|
+
}
|
|
512
|
+
/**
|
|
513
|
+
* Run the full pipeline in the browser from a mono audio Blob. Uses one Gemini call
|
|
514
|
+
* (whole audio inline) + one AssemblyAI transcript (whole file) + alignment. Best for
|
|
515
|
+
* files whose audio fits the inline limit (~20MB); for longer, chunk and call the
|
|
516
|
+
* stages directly.
|
|
517
|
+
*/
|
|
518
|
+
declare function transcribeBrowser(opts: TranscribeBrowserOptions): Promise<TranscriptResult>;
|
|
739
519
|
|
|
740
|
-
export {
|
|
520
|
+
export { AssemblyAIFetchClient, type BrowserPreprocessResult, type FfmpegWasmOptions, GeminiFetchClient, OpenAICompatClient, type Segment, type SpeakerInfo, TRANSCRIPT_SCHEMA, type TranscribeBrowserOptions, type TranscriptResult, alignSegments, assignGlobalSpeakers, finalizeSegments, formatJson, formatMarkdown, formatSrt, identifySpeakers, parseLlmSegments, preprocessInBrowser, transcribeBrowser, transcriptionPrompt };
|