offmute-v2 0.0.1 → 0.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +201 -0
- package/README.md +240 -120
- package/dist/browser.browser.js.map +1 -1
- package/dist/cli.cjs +84 -4
- package/dist/cli.cjs.map +1 -1
- package/dist/cli.js +84 -4
- package/dist/cli.js.map +1 -1
- package/dist/index.cjs +78 -3
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +78 -3
- package/dist/index.js.map +1 -1
- package/package.json +3 -7
package/dist/index.js
CHANGED
|
@@ -94,6 +94,20 @@ function inputSignature(input) {
|
|
|
94
94
|
}
|
|
95
95
|
return createHash("sha1").update(`${resolve(input)}|${size}|${mtime}`).digest("hex");
|
|
96
96
|
}
|
|
97
|
+
function configSignature(o) {
|
|
98
|
+
const relevant = {
|
|
99
|
+
model: o.model ?? DEFAULT_TRANSCRIBE_MODEL,
|
|
100
|
+
reasoner: o.reasoner ?? DEFAULT_REASONER_MODEL,
|
|
101
|
+
instructions: o.instructions ?? "",
|
|
102
|
+
knownSpeakers: o.knownSpeakers ?? [],
|
|
103
|
+
chunkDurationSec: o.chunkDurationSec ?? 600,
|
|
104
|
+
chunkOverlapSec: o.chunkOverlapSec ?? 60,
|
|
105
|
+
screenshotCount: o.screenshotCount ?? 6,
|
|
106
|
+
diarizationLevel: o.diarizationLevel ?? 2,
|
|
107
|
+
timestampedProvider: o.timestampedProvider ?? "assemblyai"
|
|
108
|
+
};
|
|
109
|
+
return createHash("sha1").update(JSON.stringify(relevant)).digest("hex");
|
|
110
|
+
}
|
|
97
111
|
function planChunks(totalDuration, chunkDuration, overlap2) {
|
|
98
112
|
const chunks = [];
|
|
99
113
|
const step = chunkDuration - overlap2;
|
|
@@ -388,6 +402,21 @@ function detectMime(path) {
|
|
|
388
402
|
return MIME_BY_EXT[ext2] ?? "application/octet-stream";
|
|
389
403
|
}
|
|
390
404
|
var sleep = (ms) => new Promise((r) => setTimeout(r, ms));
|
|
405
|
+
function resolveThinking(model) {
|
|
406
|
+
const m = model.toLowerCase();
|
|
407
|
+
if (m.includes("gemini-2.0")) return void 0;
|
|
408
|
+
if (m.includes("gemini-2.5")) {
|
|
409
|
+
return { thinkingBudget: m.includes("pro") ? 128 : 0 };
|
|
410
|
+
}
|
|
411
|
+
if (m.includes("gemini-3") || m.includes("flash-latest") || m.includes("pro-latest")) {
|
|
412
|
+
return { thinkingLevel: m.includes("pro") ? "LOW" : "MINIMAL" };
|
|
413
|
+
}
|
|
414
|
+
return void 0;
|
|
415
|
+
}
|
|
416
|
+
function isThinkingConfigError(message) {
|
|
417
|
+
if (!message) return false;
|
|
418
|
+
return /thinking/i.test(message) && /(not supported|invalid|unsupported|unknown name|unexpected)/i.test(message);
|
|
419
|
+
}
|
|
391
420
|
var GeminiClient = class {
|
|
392
421
|
ai;
|
|
393
422
|
constructor(apiKey) {
|
|
@@ -434,6 +463,8 @@ var GeminiClient = class {
|
|
|
434
463
|
config.responseSchema = responseSchema;
|
|
435
464
|
}
|
|
436
465
|
if (systemInstruction) config.systemInstruction = systemInstruction;
|
|
466
|
+
const thinking = resolveThinking(model);
|
|
467
|
+
if (thinking) config.thinkingConfig = thinking;
|
|
437
468
|
const parts = uploaded.map((f) => ({
|
|
438
469
|
fileData: { fileUri: f.uri, mimeType: f.mimeType }
|
|
439
470
|
}));
|
|
@@ -472,6 +503,11 @@ var GeminiClient = class {
|
|
|
472
503
|
return result;
|
|
473
504
|
} catch (err) {
|
|
474
505
|
lastError = err instanceof Error ? err.message : String(err);
|
|
506
|
+
if (config.thinkingConfig && isThinkingConfigError(lastError)) {
|
|
507
|
+
delete config.thinkingConfig;
|
|
508
|
+
logger.warn(`[gemini] model ${model} rejected thinking config \u2014 retrying without it`);
|
|
509
|
+
continue;
|
|
510
|
+
}
|
|
475
511
|
logger.warn(`[gemini] attempt ${attempt + 1}/${maxRetries} failed: ${lastError}`);
|
|
476
512
|
logLlmCall({
|
|
477
513
|
ts: new Date(t0).toISOString(),
|
|
@@ -1666,6 +1702,12 @@ function has(passes, p) {
|
|
|
1666
1702
|
return passes.includes(p);
|
|
1667
1703
|
}
|
|
1668
1704
|
async function transcribe(opts) {
|
|
1705
|
+
if (!opts || typeof opts.input !== "string" || opts.input.length === 0) {
|
|
1706
|
+
throw new Error("transcribe(options): 'input' (path to the audio/video file) is required");
|
|
1707
|
+
}
|
|
1708
|
+
if (typeof opts.outputDir !== "string" || opts.outputDir.length === 0) {
|
|
1709
|
+
throw new Error("transcribe(options): 'outputDir' (directory for outputs) is required");
|
|
1710
|
+
}
|
|
1669
1711
|
const options = resolveOptions(opts);
|
|
1670
1712
|
const keys = resolveKeys(options.apiKeys);
|
|
1671
1713
|
logger.setLevel(options.logLevel);
|
|
@@ -1677,15 +1719,26 @@ async function transcribe(opts) {
|
|
|
1677
1719
|
setLlmLogPath(options.llmLog ? `${options.intermediatesDir}/llm-calls.jsonl` : null);
|
|
1678
1720
|
const sourcePath = `${options.intermediatesDir}/source.json`;
|
|
1679
1721
|
const sig = inputSignature(options.input);
|
|
1722
|
+
const cfgSig = configSignature(opts);
|
|
1680
1723
|
const prevSig = readJson(sourcePath);
|
|
1681
1724
|
const inputChanged = !prevSig || prevSig.signature !== sig;
|
|
1725
|
+
const configChanged = !prevSig || prevSig.config !== cfgSig;
|
|
1682
1726
|
if (inputChanged && prevSig) {
|
|
1683
1727
|
logger.warn(
|
|
1684
1728
|
`input file changed since last run (was ${prevSig.input ?? "?"}) \u2014 discarding cached intermediates`
|
|
1685
1729
|
);
|
|
1730
|
+
} else if (configChanged && prevSig) {
|
|
1731
|
+
logger.warn(
|
|
1732
|
+
"options changed since last run (model / chunking / instructions / provider) \u2014 discarding cached intermediates"
|
|
1733
|
+
);
|
|
1686
1734
|
}
|
|
1687
|
-
const forceAll = options.force || inputChanged;
|
|
1688
|
-
writeJson(sourcePath, {
|
|
1735
|
+
const forceAll = options.force || inputChanged || configChanged;
|
|
1736
|
+
writeJson(sourcePath, {
|
|
1737
|
+
input: options.input,
|
|
1738
|
+
signature: sig,
|
|
1739
|
+
config: cfgSig,
|
|
1740
|
+
updatedAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
1741
|
+
});
|
|
1689
1742
|
const passes = options.passes;
|
|
1690
1743
|
const models = {
|
|
1691
1744
|
transcribe: options.model ?? DEFAULT_TRANSCRIBE_MODEL,
|
|
@@ -1693,6 +1746,18 @@ async function transcribe(opts) {
|
|
|
1693
1746
|
};
|
|
1694
1747
|
if (!await checkFfmpeg()) throw new Error("ffmpeg/ffprobe not found in PATH");
|
|
1695
1748
|
if (!keys.gemini) throw new Error("GEMINI_API_KEY (or GOOGLE_API_KEY) is required");
|
|
1749
|
+
const tsProvider = options.timestampedProvider ?? "assemblyai";
|
|
1750
|
+
const willTimestamp = has(passes, "timestamped") || has(passes, "align");
|
|
1751
|
+
if (willTimestamp) {
|
|
1752
|
+
if (tsProvider === "assemblyai" && !keys.assemblyai) {
|
|
1753
|
+
throw new Error(
|
|
1754
|
+
"ASSEMBLYAI_API_KEY is required for the timestamped pass (or use --timestamped whisper-groq)"
|
|
1755
|
+
);
|
|
1756
|
+
}
|
|
1757
|
+
if (tsProvider === "whisper-groq" && !keys.groq) {
|
|
1758
|
+
throw new Error("GROQ_API_KEY is required for --timestamped whisper-groq");
|
|
1759
|
+
}
|
|
1760
|
+
}
|
|
1696
1761
|
let probeInfo = null;
|
|
1697
1762
|
const audioPath = `${options.intermediatesDir}/audio.flac`;
|
|
1698
1763
|
const probePath = `${options.intermediatesDir}/probe.json`;
|
|
@@ -1815,6 +1880,13 @@ async function transcribe(opts) {
|
|
|
1815
1880
|
writeFileSync(`${llmDir}/chunk_${String(chunk.index).padStart(2, "0")}_raw.json`, result2.raw);
|
|
1816
1881
|
return tagWith(result2, chunk);
|
|
1817
1882
|
});
|
|
1883
|
+
const errored = llmChunkResults.filter((r) => r.error);
|
|
1884
|
+
const producedSegments = llmChunkResults.reduce((n, r) => n + r.segments.length, 0);
|
|
1885
|
+
if (llmChunkResults.length > 0 && producedSegments === 0 && errored.length === llmChunkResults.length) {
|
|
1886
|
+
throw new Error(
|
|
1887
|
+
`LLM transcription failed for all ${llmChunkResults.length} chunk(s) with model "${models.transcribe}". First error: ${errored[0].error}`
|
|
1888
|
+
);
|
|
1889
|
+
}
|
|
1818
1890
|
} else {
|
|
1819
1891
|
const llmDir = `${options.intermediatesDir}/llm`;
|
|
1820
1892
|
if (!forceAll && existsSync2(llmDir)) {
|
|
@@ -1927,7 +1999,10 @@ async function transcribe(opts) {
|
|
|
1927
1999
|
sourceFile: options.input,
|
|
1928
2000
|
duration,
|
|
1929
2001
|
processedAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
1930
|
-
models: {
|
|
2002
|
+
models: {
|
|
2003
|
+
transcribe: models.transcribe,
|
|
2004
|
+
timestamped: tsProvider === "whisper-groq" ? "whisper-large-v3 (groq)" : tsProvider === "none" ? "none" : "assemblyai-universal-2"
|
|
2005
|
+
},
|
|
1931
2006
|
passes
|
|
1932
2007
|
};
|
|
1933
2008
|
const result = { segments: finalSegments, speakers, metadata };
|