offmute-v2 0.1.1 → 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/README.md +95 -43
- package/dist/browser.browser.js +168 -69
- package/dist/browser.browser.js.map +1 -1
- package/dist/browser.d.ts +72 -19
- package/dist/cli.js +1714 -649
- package/dist/cli.js.map +1 -1
- package/dist/index.cjs +1211 -441
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +238 -18
- package/dist/index.d.ts +238 -18
- package/dist/index.js +1207 -437
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -19,7 +19,7 @@ npx offmute-v2 meeting.mp4
|
|
|
19
19
|
[](#requirements)
|
|
20
20
|
[](#the-story)
|
|
21
21
|
|
|
22
|
-
**[Quick start](#quick-start)** · **[What you get](#what-you-get)** · **[Why it's accurate](#why-its-accurate)** · **[Daemon](#daemon-mode)** · **[Costs](#costs-you-can-see)** · **[CLI](#cli-reference)** · **[Library](#library)** · **[The story](#the-story)**
|
|
22
|
+
**[Quick start](#quick-start)** · **[What you get](#what-you-get)** · **[Why it's accurate](#why-its-accurate)** · **[Zero storage](#zero-storage)** · **[Daemon](#daemon-mode)** · **[Costs](#costs-you-can-see)** · **[CLI](#cli-reference)** · **[Library](#library)** · **[The story](#the-story)**
|
|
23
23
|
|
|
24
24
|
</div>
|
|
25
25
|
<!-- prettier-ignore-end -->
|
|
@@ -54,28 +54,40 @@ npx offmute-v2 meeting.mp4
|
|
|
54
54
|
```
|
|
55
55
|
|
|
56
56
|
That's the whole thing. First run checks your setup and tells you what any missing keys would
|
|
57
|
-
unlock. Every run shows you what it will cost before spending,
|
|
57
|
+
unlock. Every run shows you what it will cost before spending, works through the meeting in
|
|
58
|
+
front of you (one cell per ten-minute chunk, with the word clock running alongside), and says
|
|
59
|
+
what it spent after:
|
|
58
60
|
|
|
59
61
|
```text
|
|
60
|
-
offmute-v2 0.
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
✓
|
|
67
|
-
✓
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
✓
|
|
71
|
-
✓
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
62
|
+
offmute-v2 0.2.0 design-review.m4a
|
|
63
|
+
cache /var/folders/…/offmute-v2-design-review-5d2e81c0
|
|
64
|
+
✓ prepared the media 1s
|
|
65
|
+
16 min of audio · gemini-4-hydrogen · timed by AssemblyAI · ~$0.25 estimated
|
|
66
|
+
zero storage
|
|
67
|
+
|
|
68
|
+
✓ timed every word · AssemblyAI · 2,549 words · 2 voices · English 13s
|
|
69
|
+
✓ listened for who's there 17s
|
|
70
|
+
A product design review: two engineers walk through the onboarding flow and agree what…
|
|
71
|
+
✓ transcribed ▰▰ 2 chunks 46s
|
|
72
|
+
✓ matched lines to the word times 0s
|
|
73
|
+
✓ told the voices apart 0s
|
|
74
|
+
◆ Speaker A → Priya · Speaker B → Jay
|
|
75
|
+
✓ named the speakers · gemini-flash-latest 3s
|
|
76
|
+
✓ finished 0s
|
|
77
|
+
|
|
78
|
+
receipt 4 LLM calls · 53k in / 21k out · ~$0.27 · 1m12s
|
|
79
|
+
gemini-4-hydrogen: 3 calls · 47.1k in / 20.4k out · $0.22
|
|
80
|
+
gemini-flash-latest: 1 call · 5.6k in / 157 out · $0.01
|
|
81
|
+
assemblyai: 16min · $0.04
|
|
82
|
+
|
|
83
|
+
✓ 212 segments · 2 speakers · 15m 38s of audio · ~$0.27 · 1m 12s
|
|
84
|
+
|
|
85
|
+
→ /Users/you/design-review.md
|
|
77
86
|
```
|
|
78
87
|
|
|
88
|
+
Stop it whenever you like (Ctrl-C, a closed laptop): run the same command again and it carries
|
|
89
|
+
on from what finished, AssemblyAI's job included.
|
|
90
|
+
|
|
79
91
|
## What you get
|
|
80
92
|
|
|
81
93
|
A transcript that reads like a person took minutes, timed like a machine kept the clock:
|
|
@@ -150,7 +162,12 @@ the seams that actually determine day-to-day quality:
|
|
|
150
162
|
into another speaker's turn, word-level timing exposes the foreign voice and the segment is
|
|
151
163
|
split at the exact word.
|
|
152
164
|
- **Chunk seams never double-print.** Segments are ownership-partitioned across chunk overlaps,
|
|
153
|
-
and boundary-spanning duplicates are trimmed word-by-word.
|
|
165
|
+
and boundary-spanning duplicates are trimmed word-by-word. Each chunk's own timestamps are
|
|
166
|
+
moved onto the ASR's clock first, so a chunk whose clock runs early keeps its opening lines.
|
|
167
|
+
- **A chunk that comes back short is redone.** Every chunk's word count is checked against what
|
|
168
|
+
the ASR heard in the same stretch. A reply that stopped early, a `[silence]` placeholder over
|
|
169
|
+
real talk, or a repetition loop leaves too few words; the chunk is transcribed again in two
|
|
170
|
+
halves and the fuller version kept.
|
|
154
171
|
- **Nothing silently goes stale.** Every stage caches to disk, keyed on the input file _and_ the
|
|
155
172
|
config — change the model and the cache invalidates itself. Re-run for a new format and it's
|
|
156
173
|
~2 seconds and $0.00. Kill it mid-run and it resumes where it stopped.
|
|
@@ -182,8 +199,29 @@ An honest tool tells you what it's about to spend:
|
|
|
182
199
|
- **lifetime accounting** — `offmute-v2 stats` shows hours processed, characters produced, and
|
|
183
200
|
cost by model, accumulated in `~/.offmute`
|
|
184
201
|
|
|
185
|
-
Typical numbers: a 30-minute meeting on the default
|
|
186
|
-
|
|
202
|
+
Typical numbers: a 30-minute meeting on the default model, `gemini-4-hydrogen`, runs
|
|
203
|
+
≈ **$0.40–0.80**, thinking tokens included. `--pro` uses `gemini-4-argon`, which kept a little
|
|
204
|
+
more speech in our tests at about 1.7× the time, and costs about twice as much from 1 December 2026. `--model gemini-3.8-flash` costs about a third as much (until 1 January 2027) but dropped
|
|
205
|
+
more speech on hard audio.
|
|
206
|
+
|
|
207
|
+
## Zero storage
|
|
208
|
+
|
|
209
|
+
Google's Gemini API now keeps the requests of new paid projects for 55 days by default (from
|
|
210
|
+
26 October 2026), unless a request asks it not to. offmute asks, on every call, unless you turn
|
|
211
|
+
it off:
|
|
212
|
+
|
|
213
|
+
- **Gemini** — every request carries `store: false`, and each uploaded audio file is deleted as
|
|
214
|
+
soon as its call returns. Speaker naming on Gemini goes through Gemini's own API, where the
|
|
215
|
+
ask is honoured (its OpenAI-compatible endpoint rejects it).
|
|
216
|
+
- **AssemblyAI** — the transcript is deleted from AssemblyAI the moment offmute has its own copy
|
|
217
|
+
(AssemblyAI deletes uploaded audio within 48 hours either way).
|
|
218
|
+
- **Everyone else** — DeepSeek, OpenAI, Groq, ElevenLabs and the rest have no way to be asked
|
|
219
|
+
per request, so each run's plan line names the ones it will use:
|
|
220
|
+
`zero storage · deepseek-chat can't be asked to keep nothing`. For a run that stays on
|
|
221
|
+
providers that can be asked: `--reasoner gemini-flash-latest --identify single`, with the
|
|
222
|
+
default `--timestamped assemblyai`.
|
|
223
|
+
|
|
224
|
+
`--no-zero-storage` turns the asks off and leaves each provider to its own retention.
|
|
187
225
|
|
|
188
226
|
## Fix a name in two seconds
|
|
189
227
|
|
|
@@ -204,22 +242,25 @@ name is left over and one voice unnamed, they bind by elimination.
|
|
|
204
242
|
offmute-v2 <input> [options] # transcribe (default command)
|
|
205
243
|
```
|
|
206
244
|
|
|
207
|
-
| option | default
|
|
208
|
-
| --------------------------------------- |
|
|
209
|
-
| `-o, --output <dir>` | next to input
|
|
210
|
-
| `--formats <list>` | `md`
|
|
211
|
-
| `--summary` | off
|
|
212
|
-
| `--instructions <text>` | –
|
|
213
|
-
| `--speakers <names>` | –
|
|
214
|
-
| `--model <name>` | `gemini-
|
|
215
|
-
| `--
|
|
216
|
-
| `--
|
|
217
|
-
| `--
|
|
218
|
-
| `--
|
|
219
|
-
| `--
|
|
220
|
-
| `--
|
|
221
|
-
| `--
|
|
222
|
-
|
|
|
245
|
+
| option | default | |
|
|
246
|
+
| --------------------------------------- | --------------------- | --------------------------------------------------------------- |
|
|
247
|
+
| `-o, --output <dir>` | next to input | where transcripts land |
|
|
248
|
+
| `--formats <list>` | `md` | any of `md,srt,txt,html,json` |
|
|
249
|
+
| `--summary` | off | also write TL;DR / decisions / action items |
|
|
250
|
+
| `--instructions <text>` | – | guide the ear: _"the host is Alice; spell it Xiao, not Shao"_ |
|
|
251
|
+
| `--speakers <names>` | – | who was in the room (helps naming; comma-separated) |
|
|
252
|
+
| `--model <name>` | `gemini-4-hydrogen` | any Gemini model id · `gemini-3.8-flash` ~⅓ the cost |
|
|
253
|
+
| `--pro` | off | `gemini-4-argon`: a little more speech, ~1.7× the time |
|
|
254
|
+
| `--no-zero-storage` | asks for zero storage | let providers keep requests under their own retention |
|
|
255
|
+
| `--language <code>` | detected by the ASR | the recording's language, e.g. `ko`, `ml`, `hi` |
|
|
256
|
+
| `--timestamped <p>` | `assemblyai` | `elevenlabs` (Scribe v2) · `whisper-groq` (free) · `none` |
|
|
257
|
+
| `--reasoner <name>` | `deepseek-chat` | naming/summary model — DeepSeek, Gemini, GLM, Kimi, GPT, Claude |
|
|
258
|
+
| `--level <1\|2\|3>` | `3` | 1 separation · 2 anonymous-consistent · 3 **verified names** |
|
|
259
|
+
| `--identify <mode>` | `dual` | two reasoners + adjudication · `single` |
|
|
260
|
+
| `--md-style <s>` | `merged` | merged paragraphs · `turns` for one block per turn |
|
|
261
|
+
| `--chunk-seconds` / `--overlap-seconds` | `600` / `60` | chunking |
|
|
262
|
+
| `--force` | – | ignore caches and recompute |
|
|
263
|
+
| `-i <dir>` | OS temp, per input | cache location (printed each run) |
|
|
223
264
|
|
|
224
265
|
```bash
|
|
225
266
|
offmute-v2 watch <dir> # daemon: transcribe files as they appear
|
|
@@ -239,6 +280,10 @@ const { segments, speakers, metadata } = await transcribe({
|
|
|
239
280
|
formats: ["md", "json"],
|
|
240
281
|
instructions: "Three-person panel; label by name.",
|
|
241
282
|
apiKeys: { gemini: "...", assemblyai: "..." }, // optional — falls back to env
|
|
283
|
+
// zeroStorage: false, // on by default, as in the CLI
|
|
284
|
+
onProgress: (e) => {
|
|
285
|
+
if (e.type === "chunk") console.log(`chunk ${e.index + 1}: ${e.state}`);
|
|
286
|
+
},
|
|
242
287
|
});
|
|
243
288
|
|
|
244
289
|
console.log(segments[0]);
|
|
@@ -247,9 +292,12 @@ console.log(segments[0]);
|
|
|
247
292
|
console.log(metadata.cost); // { estimatedUsd, actualUsd, lines, ... }
|
|
248
293
|
```
|
|
249
294
|
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
295
|
+
`onProgress` receives the same events the terminal display is drawn from: the plan (model,
|
|
296
|
+
estimate, which providers zero storage couldn't ask), each stage, each chunk, the ASR, the
|
|
297
|
+
coverage check redoing a chunk, the names, and the files written. Every pipeline stage
|
|
298
|
+
(`alignSegments`, `assignGlobalSpeakers`, `identifySpeakersV2`, the formatters) is exported
|
|
299
|
+
individually — bring your own pipeline if you like. A browser build of the pure fusion core
|
|
300
|
+
ships as `offmute-v2/browser` (fetch providers + optional ffmpeg.wasm).
|
|
253
301
|
|
|
254
302
|
## What can go wrong (honestly)
|
|
255
303
|
|
|
@@ -259,8 +307,11 @@ the pure fusion core ships as `offmute-v2/browser` (fetch providers + optional f
|
|
|
259
307
|
recording's filename and your `--instructions` both feed the namer; `rename` fixes stragglers.
|
|
260
308
|
- **Network blips** → every upload retries with backoff for ~90s; if a run still dies, re-running
|
|
261
309
|
resumes from cache and re-pays nothing that finished.
|
|
262
|
-
- **It costs money** — roughly a dollar an hour of audio on the best models, a
|
|
310
|
+
- **It costs money** — roughly a dollar an hour of audio on the best models, a third of that on
|
|
263
311
|
flash. The estimate prints before anything is spent.
|
|
312
|
+
- **A language the ASR mishears** → AssemblyAI now detects each file's language, but if the ASR
|
|
313
|
+
still hears almost nothing, offmute says so and times the lines from the LLM alone;
|
|
314
|
+
`--language ko` (or `ml`, `hi`, …) pins the language.
|
|
264
315
|
|
|
265
316
|
## Requirements
|
|
266
317
|
|
|
@@ -268,7 +319,8 @@ the pure fusion core ships as `offmute-v2/browser` (fetch providers + optional f
|
|
|
268
319
|
- `GEMINI_API_KEY` (or `GOOGLE_API_KEY`) — required, the ears
|
|
269
320
|
- One clock, strongly recommended: `ASSEMBLYAI_API_KEY` (default) · `ELEVENLABS_API_KEY`
|
|
270
321
|
(Scribe v2 — the sharpest diarization we've tested) · `GROQ_API_KEY` (free whisper timing)
|
|
271
|
-
- Nice-to-have: `DEEPSEEK_API_KEY` — makes speaker naming cost ~$0.003 a run
|
|
322
|
+
- Nice-to-have: `DEEPSEEK_API_KEY` — makes speaker naming cost ~$0.003 a run (DeepSeek can't be
|
|
323
|
+
asked for zero storage)
|
|
272
324
|
|
|
273
325
|
Keys can also be injected via the library API instead of the environment. Run
|
|
274
326
|
`offmute-v2 doctor` to see where you stand.
|
package/dist/browser.browser.js
CHANGED
|
@@ -1,3 +1,38 @@
|
|
|
1
|
+
// src/providers/gemini-usage.ts
|
|
2
|
+
function usageFromMetadata(meta) {
|
|
3
|
+
const thoughtTokens = meta?.thoughtsTokenCount ?? 0;
|
|
4
|
+
return {
|
|
5
|
+
inputTokens: meta?.promptTokenCount ?? 0,
|
|
6
|
+
outputTokens: (meta?.candidatesTokenCount ?? 0) + thoughtTokens,
|
|
7
|
+
thoughtTokens,
|
|
8
|
+
totalTokens: meta?.totalTokenCount ?? 0
|
|
9
|
+
};
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
// src/providers/gemini-models.ts
|
|
13
|
+
function resolveThinking(model) {
|
|
14
|
+
const m = model.toLowerCase();
|
|
15
|
+
if (m.includes("gemini-2.0")) return void 0;
|
|
16
|
+
if (m.includes("gemini-4")) return { thinkingLevel: "LOW" };
|
|
17
|
+
if (m.includes("gemini-2.5")) {
|
|
18
|
+
return { thinkingBudget: m.includes("pro") ? 128 : 0 };
|
|
19
|
+
}
|
|
20
|
+
if (m.includes("-latest")) return { thinkingLevel: "LOW" };
|
|
21
|
+
if (m.includes("gemini-3"))
|
|
22
|
+
return { thinkingLevel: m.includes("pro") ? "LOW" : "MINIMAL" };
|
|
23
|
+
return void 0;
|
|
24
|
+
}
|
|
25
|
+
function fallbackThinking(rejected) {
|
|
26
|
+
return rejected.thinkingLevel === "MINIMAL" ? { thinkingLevel: "LOW" } : void 0;
|
|
27
|
+
}
|
|
28
|
+
function isThinkingConfigError(message) {
|
|
29
|
+
if (!message) return false;
|
|
30
|
+
return /thinking/i.test(message) && /(not supported|invalid|unsupported|unknown name|unexpected)/i.test(message);
|
|
31
|
+
}
|
|
32
|
+
function maxNonStreamingOutput(model) {
|
|
33
|
+
return /gemini-4-(argon|carbon)/i.test(model) ? 32768 : 65536;
|
|
34
|
+
}
|
|
35
|
+
|
|
1
36
|
// src/providers/gemini-fetch.ts
|
|
2
37
|
var MIME_BY_EXT = {
|
|
3
38
|
flac: "audio/flac",
|
|
@@ -26,9 +61,11 @@ function toBase64(data) {
|
|
|
26
61
|
var GeminiFetchClient = class {
|
|
27
62
|
apiKey;
|
|
28
63
|
baseUrl;
|
|
64
|
+
zeroStorage;
|
|
29
65
|
constructor(opts) {
|
|
30
66
|
this.apiKey = opts.apiKey;
|
|
31
67
|
this.baseUrl = opts.baseUrl ?? "https://generativelanguage.googleapis.com/v1beta";
|
|
68
|
+
this.zeroStorage = opts.zeroStorage ?? true;
|
|
32
69
|
}
|
|
33
70
|
/** Generate from a prompt + inline file parts (ArrayBuffer + mimeType). */
|
|
34
71
|
async generate(model, prompt, files, opts = {}) {
|
|
@@ -39,18 +76,26 @@ var GeminiFetchClient = class {
|
|
|
39
76
|
parts.push({ inlineData: { mimeType, data: toBase64(f.data) } });
|
|
40
77
|
}
|
|
41
78
|
parts.push({ text: prompt });
|
|
42
|
-
const
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
79
|
+
const generationConfig = {
|
|
80
|
+
// A plain (non-streaming) REST call: Argon and Carbon reject more than 32,768 here.
|
|
81
|
+
maxOutputTokens: Math.min(
|
|
82
|
+
opts.maxOutputTokens ?? 65536,
|
|
83
|
+
maxNonStreamingOutput(model)
|
|
84
|
+
),
|
|
85
|
+
temperature: opts.temperature ?? 0.2
|
|
48
86
|
};
|
|
49
87
|
if (opts.responseSchema) {
|
|
50
|
-
|
|
51
|
-
|
|
88
|
+
generationConfig.responseMimeType = "application/json";
|
|
89
|
+
generationConfig.responseSchema = opts.responseSchema;
|
|
52
90
|
}
|
|
91
|
+
let thinking = resolveThinking(model);
|
|
92
|
+
if (thinking) generationConfig.thinkingConfig = thinking;
|
|
93
|
+
const body = {
|
|
94
|
+
contents: [{ role: "user", parts }],
|
|
95
|
+
generationConfig
|
|
96
|
+
};
|
|
53
97
|
if (opts.systemInstruction) body.systemInstruction = opts.systemInstruction;
|
|
98
|
+
if (this.zeroStorage) body.store = false;
|
|
54
99
|
let lastError;
|
|
55
100
|
for (let attempt = 0; attempt < maxRetries; attempt++) {
|
|
56
101
|
try {
|
|
@@ -68,17 +113,15 @@ var GeminiFetchClient = class {
|
|
|
68
113
|
}
|
|
69
114
|
const data = await res.json();
|
|
70
115
|
const text = data.candidates?.[0]?.content?.parts?.map((p) => p.text || "").join("") ?? "";
|
|
71
|
-
|
|
72
|
-
return {
|
|
73
|
-
text,
|
|
74
|
-
usage: {
|
|
75
|
-
inputTokens: u.promptTokenCount ?? 0,
|
|
76
|
-
outputTokens: u.candidatesTokenCount ?? 0,
|
|
77
|
-
totalTokens: u.totalTokenCount ?? 0
|
|
78
|
-
}
|
|
79
|
-
};
|
|
116
|
+
return { text, usage: usageFromMetadata(data.usageMetadata) };
|
|
80
117
|
} catch (err) {
|
|
81
118
|
lastError = err instanceof Error ? err.message : String(err);
|
|
119
|
+
if (thinking && isThinkingConfigError(lastError)) {
|
|
120
|
+
thinking = fallbackThinking(thinking);
|
|
121
|
+
if (thinking) generationConfig.thinkingConfig = thinking;
|
|
122
|
+
else delete generationConfig.thinkingConfig;
|
|
123
|
+
continue;
|
|
124
|
+
}
|
|
82
125
|
if (attempt < maxRetries - 1)
|
|
83
126
|
await new Promise((r) => setTimeout(r, 1500 * (attempt + 1)));
|
|
84
127
|
}
|
|
@@ -110,10 +153,14 @@ var GeminiFetchClient = class {
|
|
|
110
153
|
// src/providers/assemblyai-fetch.ts
|
|
111
154
|
var BASE = "https://api.assemblyai.com/v2";
|
|
112
155
|
var AssemblyAIFetchClient = class {
|
|
113
|
-
|
|
156
|
+
/** `zeroStorage` (default true): delete the transcript from AssemblyAI once its words
|
|
157
|
+
* are read. AssemblyAI otherwise keeps it for 30 days. */
|
|
158
|
+
constructor(apiKey, opts = {}) {
|
|
114
159
|
this.apiKey = apiKey;
|
|
160
|
+
this.zeroStorage = opts.zeroStorage ?? true;
|
|
115
161
|
}
|
|
116
162
|
apiKey;
|
|
163
|
+
zeroStorage;
|
|
117
164
|
async transcribe(audio, opts = {}) {
|
|
118
165
|
const upRes = await fetch(`${BASE}/upload`, {
|
|
119
166
|
method: "POST",
|
|
@@ -129,6 +176,8 @@ var AssemblyAIFetchClient = class {
|
|
|
129
176
|
speech_model: "universal"
|
|
130
177
|
};
|
|
131
178
|
if (opts.speakersExpected) params.speakers_expected = opts.speakersExpected;
|
|
179
|
+
if (opts.language) params.language_code = opts.language;
|
|
180
|
+
else params.language_detection = true;
|
|
132
181
|
const cr = await fetch(`${BASE}/transcript`, {
|
|
133
182
|
method: "POST",
|
|
134
183
|
headers: { authorization: this.apiKey, "content-type": "application/json" },
|
|
@@ -167,6 +216,12 @@ var AssemblyAIFetchClient = class {
|
|
|
167
216
|
}
|
|
168
217
|
const words = (t.words || []).map(toWord);
|
|
169
218
|
const durationSec = words.length ? words[words.length - 1].end : 0;
|
|
219
|
+
if (this.zeroStorage) {
|
|
220
|
+
await fetch(`${BASE}/transcript/${t.id}`, {
|
|
221
|
+
method: "DELETE",
|
|
222
|
+
headers: { authorization: this.apiKey }
|
|
223
|
+
}).catch(() => void 0);
|
|
224
|
+
}
|
|
170
225
|
return {
|
|
171
226
|
utterances,
|
|
172
227
|
words,
|
|
@@ -208,6 +263,25 @@ function logLlmCall(entry) {
|
|
|
208
263
|
}
|
|
209
264
|
|
|
210
265
|
// src/providers/openai-compat.ts
|
|
266
|
+
async function chatJsonWith(client, model, messages, opts) {
|
|
267
|
+
let lastRaw = "";
|
|
268
|
+
let lastError;
|
|
269
|
+
for (let attempt = 0; attempt < 2; attempt++) {
|
|
270
|
+
const res = await client.chat(model, messages, { ...opts, responseJson: true });
|
|
271
|
+
lastRaw = res.text;
|
|
272
|
+
lastError = res.error;
|
|
273
|
+
if (res.error || !res.text) continue;
|
|
274
|
+
try {
|
|
275
|
+
let txt = res.text.trim();
|
|
276
|
+
const fence = txt.match(/```(?:json)?\s*([\s\S]*?)\s*```/);
|
|
277
|
+
if (fence && fence[1]) txt = fence[1];
|
|
278
|
+
return { data: JSON.parse(txt), raw: res.text };
|
|
279
|
+
} catch (err) {
|
|
280
|
+
lastError = `JSON parse: ${err instanceof Error ? err.message : String(err)}`;
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
return { data: null, raw: lastRaw, error: lastError };
|
|
284
|
+
}
|
|
211
285
|
var PROVIDER_BASE = {
|
|
212
286
|
deepseek: "https://api.deepseek.com/v1",
|
|
213
287
|
groq: "https://api.groq.com/openai/v1",
|
|
@@ -305,24 +379,8 @@ var OpenAICompatClient = class _OpenAICompatClient {
|
|
|
305
379
|
}
|
|
306
380
|
return { text: "", usage: { inputTokens: 0, outputTokens: 0 }, error: lastError };
|
|
307
381
|
}
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
let lastError;
|
|
311
|
-
for (let attempt = 0; attempt < 2; attempt++) {
|
|
312
|
-
const res = await this.chat(model, messages, { ...opts, responseJson: true });
|
|
313
|
-
lastRaw = res.text;
|
|
314
|
-
lastError = res.error;
|
|
315
|
-
if (res.error || !res.text) continue;
|
|
316
|
-
try {
|
|
317
|
-
let txt = res.text.trim();
|
|
318
|
-
const fence = txt.match(/```(?:json)?\s*([\s\S]*?)\s*```/);
|
|
319
|
-
if (fence && fence[1]) txt = fence[1];
|
|
320
|
-
return { data: JSON.parse(txt), raw: res.text };
|
|
321
|
-
} catch (err) {
|
|
322
|
-
lastError = `JSON parse: ${err instanceof Error ? err.message : String(err)}`;
|
|
323
|
-
}
|
|
324
|
-
}
|
|
325
|
-
return { data: null, raw: lastRaw, error: lastError };
|
|
382
|
+
chatJson(model, messages, opts = {}) {
|
|
383
|
+
return chatJsonWith(this, model, messages, opts);
|
|
326
384
|
}
|
|
327
385
|
};
|
|
328
386
|
|
|
@@ -416,13 +474,6 @@ function transcriptionPrompt(ctx) {
|
|
|
416
474
|
"Use a roster name ONLY when the voice itself tells you it's that person (they self-identify, are addressed by name, or the voice description clearly matches). If two speakers sound similar and you are not sure which name belongs to which voice, use 'Speaker A' / 'Speaker B' instead \u2014 a WRONG name is much worse than a generic label; a later pass verifies names."
|
|
417
475
|
);
|
|
418
476
|
}
|
|
419
|
-
if (ctx.previousTail) {
|
|
420
|
-
parts.push("");
|
|
421
|
-
parts.push(
|
|
422
|
-
"TRANSCRIPT OF THE END OF THE PREVIOUS CHUNK (for continuity \u2014 do NOT repeat this content, continue from where it leaves off):"
|
|
423
|
-
);
|
|
424
|
-
parts.push(ctx.previousTail);
|
|
425
|
-
}
|
|
426
477
|
if (ctx.instructions) {
|
|
427
478
|
parts.push("");
|
|
428
479
|
parts.push("ADDITIONAL INSTRUCTIONS:");
|
|
@@ -436,7 +487,9 @@ function transcriptionPrompt(ctx) {
|
|
|
436
487
|
}
|
|
437
488
|
|
|
438
489
|
// src/providers/gemini.ts
|
|
439
|
-
import {
|
|
490
|
+
import {
|
|
491
|
+
GoogleGenAI
|
|
492
|
+
} from "@google/genai";
|
|
440
493
|
import { basename } from "path";
|
|
441
494
|
|
|
442
495
|
// src/utils/logger.ts
|
|
@@ -540,20 +593,21 @@ function parseLlmSegments(data, chunkOffsetSec) {
|
|
|
540
593
|
}
|
|
541
594
|
|
|
542
595
|
// src/align/normalize.ts
|
|
543
|
-
function
|
|
544
|
-
return word.toLowerCase().replace(
|
|
596
|
+
function normalizeWord(word) {
|
|
597
|
+
return word.normalize("NFKC").toLowerCase().replace(/[’‘`]/g, "'").replace(/^[^\p{L}\p{M}\p{N}']+|[^\p{L}\p{M}\p{N}']+$/gu, "").replace(/^'+|'+$/g, "");
|
|
545
598
|
}
|
|
546
599
|
function tokenize(text) {
|
|
547
600
|
const out = [];
|
|
548
601
|
for (const raw of text.split(/\s+/)) {
|
|
549
602
|
if (!raw) continue;
|
|
550
|
-
const norm =
|
|
603
|
+
const norm = normalizeWord(raw);
|
|
551
604
|
if (norm) out.push({ original: raw, norm });
|
|
552
605
|
}
|
|
553
606
|
return out;
|
|
554
607
|
}
|
|
555
608
|
function fuzzyEqual(a, b) {
|
|
556
609
|
if (a === b) return true;
|
|
610
|
+
if (!a || !b) return false;
|
|
557
611
|
if (Math.abs(a.length - b.length) <= 1) {
|
|
558
612
|
return editDistanceChars(a, b, 1) <= 1;
|
|
559
613
|
}
|
|
@@ -581,7 +635,10 @@ function editDistanceChars(a, b, max) {
|
|
|
581
635
|
|
|
582
636
|
// src/align/edit-distance.ts
|
|
583
637
|
var INDEL = 2;
|
|
638
|
+
var OUT_OF_WINDOW = { cost: 2 * INDEL + 1, fuzzy: false };
|
|
584
639
|
function matchCost(a, b) {
|
|
640
|
+
if (a.window && b.start !== void 0 && (b.start < a.window.lo || b.start > a.window.hi))
|
|
641
|
+
return OUT_OF_WINDOW;
|
|
585
642
|
if (a.norm === b.norm) return { cost: 0, fuzzy: false };
|
|
586
643
|
if (fuzzyEqual(a.norm, b.norm)) return { cost: 1, fuzzy: true };
|
|
587
644
|
return { cost: 2, fuzzy: false };
|
|
@@ -659,12 +716,19 @@ function alignWords(llm, asr) {
|
|
|
659
716
|
}
|
|
660
717
|
|
|
661
718
|
// src/align/aligner.ts
|
|
719
|
+
var WINDOW_SLACK_SEC = 2;
|
|
720
|
+
var UNANCHORED_MAX_DRIFT_SEC = 15;
|
|
721
|
+
var STRETCH_MIN_SEC = 30;
|
|
722
|
+
var STRETCH_SEC_PER_WORD = 3;
|
|
723
|
+
var MAX_INNER_GAP_SEC = 8;
|
|
724
|
+
var SPOKEN_SEC_PER_WORD = 0.5;
|
|
725
|
+
var UNCONFIRMED_MAX_SEC = 5;
|
|
662
726
|
function toAsrTokens(words) {
|
|
663
727
|
return words.map((w) => ({
|
|
664
728
|
text: w.text,
|
|
665
729
|
start: w.start,
|
|
666
730
|
end: w.end,
|
|
667
|
-
norm: w.text
|
|
731
|
+
norm: normalizeWord(w.text)
|
|
668
732
|
}));
|
|
669
733
|
}
|
|
670
734
|
function transferTiming(llm, asr, ops) {
|
|
@@ -723,7 +787,9 @@ function alignSegments(llmSegments, asrWords, opts = {}) {
|
|
|
723
787
|
for (const { s, i } of sorted) {
|
|
724
788
|
const toks = tokenize(s.text);
|
|
725
789
|
const start = flat.length;
|
|
726
|
-
|
|
790
|
+
const window = s.chunkStart !== void 0 && s.chunkEnd !== void 0 ? { lo: s.chunkStart - WINDOW_SLACK_SEC, hi: s.chunkEnd + WINDOW_SLACK_SEC } : void 0;
|
|
791
|
+
for (const t of toks)
|
|
792
|
+
flat.push({ original: t.original, norm: t.norm, segIdx: i, window });
|
|
727
793
|
segRanges.push({ src: i, start, end: flat.length });
|
|
728
794
|
}
|
|
729
795
|
if (flat.length === 0 || asrWords.length === 0) {
|
|
@@ -768,21 +834,53 @@ function alignSegments(llmSegments, asrWords, opts = {}) {
|
|
|
768
834
|
let end;
|
|
769
835
|
let timingSource;
|
|
770
836
|
const confidence = tokenCount ? exact / tokenCount : 0;
|
|
771
|
-
|
|
837
|
+
const unanchoredDrift = segOps.length === 0 && firstTimed ? Math.abs(firstTimed.start - s.startSec) : 0;
|
|
838
|
+
if (firstTimed && lastTimed && unanchoredDrift <= UNANCHORED_MAX_DRIFT_SEC) {
|
|
772
839
|
start = firstTimed.start;
|
|
773
840
|
end = lastTimed.end;
|
|
774
841
|
timingSource = confidence >= confThreshold ? "aligned" : "interpolated";
|
|
842
|
+
if (end - start > Math.max(STRETCH_MIN_SEC, STRETCH_SEC_PER_WORD * tokenCount)) {
|
|
843
|
+
const runs = [];
|
|
844
|
+
for (const t of segTimes) {
|
|
845
|
+
if (isNaN(t.start)) continue;
|
|
846
|
+
const run = runs[runs.length - 1];
|
|
847
|
+
if (run && t.start - run.end <= MAX_INNER_GAP_SEC) {
|
|
848
|
+
run.end = Math.max(run.end, t.end);
|
|
849
|
+
if (t.matched) run.matched++;
|
|
850
|
+
} else {
|
|
851
|
+
runs.push({ start: t.start, end: t.end, matched: t.matched ? 1 : 0 });
|
|
852
|
+
}
|
|
853
|
+
}
|
|
854
|
+
const best = runs.reduce(
|
|
855
|
+
(a, b) => b.matched > a.matched || b.matched === a.matched && Math.abs(b.start - s.startSec) < Math.abs(a.start - s.startSec) ? b : a
|
|
856
|
+
);
|
|
857
|
+
start = best.start;
|
|
858
|
+
end = best.end;
|
|
859
|
+
}
|
|
860
|
+
const spoken = Math.max(1, SPOKEN_SEC_PER_WORD * tokenCount);
|
|
861
|
+
if (exact === 0 && end - start > Math.max(UNCONFIRMED_MAX_SEC, 3 * spoken)) {
|
|
862
|
+
end = start + spoken;
|
|
863
|
+
}
|
|
775
864
|
} else {
|
|
776
865
|
start = s.startSec;
|
|
777
866
|
end = s.endSec;
|
|
778
867
|
timingSource = "coarse";
|
|
779
868
|
}
|
|
780
|
-
const
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
869
|
+
const step = timingSource === "coarse" && tokenCount ? (end - start) / tokenCount : 0;
|
|
870
|
+
const inside = (x) => Math.min(Math.max(x, start), end);
|
|
871
|
+
const words = segTimes.map(
|
|
872
|
+
(t, idx) => timingSource === "coarse" ? {
|
|
873
|
+
text: flat[range.start + idx].original,
|
|
874
|
+
start: start + step * idx,
|
|
875
|
+
end: start + step * (idx + 1),
|
|
876
|
+
matched: false
|
|
877
|
+
} : {
|
|
878
|
+
text: flat[range.start + idx].original,
|
|
879
|
+
start: isNaN(t.start) ? start : inside(t.start),
|
|
880
|
+
end: isNaN(t.end) ? end : inside(t.end),
|
|
881
|
+
matched: t.matched
|
|
882
|
+
}
|
|
883
|
+
);
|
|
786
884
|
out.push({
|
|
787
885
|
speaker: s.speaker,
|
|
788
886
|
start,
|
|
@@ -1028,7 +1126,6 @@ async function identifySpeakers(client, model, segments, speakers, roster, known
|
|
|
1028
1126
|
|
|
1029
1127
|
// src/finalize/finalize.ts
|
|
1030
1128
|
var MIN_DUR = 0.5;
|
|
1031
|
-
var MAX_DUR = 7;
|
|
1032
1129
|
var OVERLAP_GAP = 0.05;
|
|
1033
1130
|
function textSimilarity(a, b) {
|
|
1034
1131
|
const ta = new Set(tokenize(a).map((t) => t.norm));
|
|
@@ -1172,16 +1269,14 @@ function fixOverlaps(segments) {
|
|
|
1172
1269
|
}
|
|
1173
1270
|
function clampAndFix(segments) {
|
|
1174
1271
|
for (const s of segments) {
|
|
1175
|
-
|
|
1176
|
-
if (dur < MIN_DUR) s.end = s.start + MIN_DUR;
|
|
1177
|
-
else if (dur > MAX_DUR) s.end = s.start + MAX_DUR;
|
|
1272
|
+
if (s.end - s.start < MIN_DUR) s.end = s.start + MIN_DUR;
|
|
1178
1273
|
}
|
|
1179
1274
|
return fixOverlaps(segments);
|
|
1180
1275
|
}
|
|
1181
|
-
function finalizeSegments(segments
|
|
1182
|
-
const
|
|
1183
|
-
|
|
1184
|
-
|
|
1276
|
+
function finalizeSegments(segments) {
|
|
1277
|
+
const deduped = dedupSegments(trimSeamOverlaps(segments)).filter(
|
|
1278
|
+
(s) => s.text.trim().length > 0
|
|
1279
|
+
);
|
|
1185
1280
|
const out = deduped.map((s, i) => ({
|
|
1186
1281
|
id: i + 1,
|
|
1187
1282
|
start: s.start,
|
|
@@ -1354,6 +1449,9 @@ function formatJson(result) {
|
|
|
1354
1449
|
return JSON.stringify(result, null, 2);
|
|
1355
1450
|
}
|
|
1356
1451
|
|
|
1452
|
+
// src/core/models.ts
|
|
1453
|
+
var DEFAULT_TRANSCRIBE_MODEL = "gemini-4-hydrogen";
|
|
1454
|
+
|
|
1357
1455
|
// src/browser-ffmpeg.ts
|
|
1358
1456
|
var DEFAULT_CORE_BASE = "https://unpkg.com/@ffmpeg/core@0.12.10/dist/umd";
|
|
1359
1457
|
var ffmpegInstance = null;
|
|
@@ -1457,13 +1555,14 @@ async function preprocessInBrowser(input, chunks, opts = {}) {
|
|
|
1457
1555
|
|
|
1458
1556
|
// src/browser.ts
|
|
1459
1557
|
async function transcribeBrowser(opts) {
|
|
1460
|
-
const model = opts.model ??
|
|
1558
|
+
const model = opts.model ?? DEFAULT_TRANSCRIBE_MODEL;
|
|
1559
|
+
const zeroStorage = opts.zeroStorage ?? true;
|
|
1461
1560
|
const level = opts.level ?? 2;
|
|
1462
|
-
const asr = await new AssemblyAIFetchClient(opts.assemblyaiApiKey
|
|
1463
|
-
|
|
1464
|
-
);
|
|
1561
|
+
const asr = await new AssemblyAIFetchClient(opts.assemblyaiApiKey, {
|
|
1562
|
+
zeroStorage
|
|
1563
|
+
}).transcribe(opts.audio);
|
|
1465
1564
|
const audioBuf = await opts.audio.arrayBuffer();
|
|
1466
|
-
const gemini = new GeminiFetchClient({ apiKey: opts.geminiApiKey });
|
|
1565
|
+
const gemini = new GeminiFetchClient({ apiKey: opts.geminiApiKey, zeroStorage });
|
|
1467
1566
|
const gen = await gemini.generateJson(
|
|
1468
1567
|
model,
|
|
1469
1568
|
transcriptionPrompt({ index: 1, total: 1, instructions: opts.instructions }),
|