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.cjs
CHANGED
|
@@ -139,6 +139,20 @@ function inputSignature(input) {
|
|
|
139
139
|
}
|
|
140
140
|
return (0, import_node_crypto.createHash)("sha1").update(`${(0, import_node_path.resolve)(input)}|${size}|${mtime}`).digest("hex");
|
|
141
141
|
}
|
|
142
|
+
function configSignature(o) {
|
|
143
|
+
const relevant = {
|
|
144
|
+
model: o.model ?? DEFAULT_TRANSCRIBE_MODEL,
|
|
145
|
+
reasoner: o.reasoner ?? DEFAULT_REASONER_MODEL,
|
|
146
|
+
instructions: o.instructions ?? "",
|
|
147
|
+
knownSpeakers: o.knownSpeakers ?? [],
|
|
148
|
+
chunkDurationSec: o.chunkDurationSec ?? 600,
|
|
149
|
+
chunkOverlapSec: o.chunkOverlapSec ?? 60,
|
|
150
|
+
screenshotCount: o.screenshotCount ?? 6,
|
|
151
|
+
diarizationLevel: o.diarizationLevel ?? 2,
|
|
152
|
+
timestampedProvider: o.timestampedProvider ?? "assemblyai"
|
|
153
|
+
};
|
|
154
|
+
return (0, import_node_crypto.createHash)("sha1").update(JSON.stringify(relevant)).digest("hex");
|
|
155
|
+
}
|
|
142
156
|
function planChunks(totalDuration, chunkDuration, overlap2) {
|
|
143
157
|
const chunks = [];
|
|
144
158
|
const step = chunkDuration - overlap2;
|
|
@@ -433,6 +447,21 @@ function detectMime(path) {
|
|
|
433
447
|
return MIME_BY_EXT[ext2] ?? "application/octet-stream";
|
|
434
448
|
}
|
|
435
449
|
var sleep = (ms) => new Promise((r) => setTimeout(r, ms));
|
|
450
|
+
function resolveThinking(model) {
|
|
451
|
+
const m = model.toLowerCase();
|
|
452
|
+
if (m.includes("gemini-2.0")) return void 0;
|
|
453
|
+
if (m.includes("gemini-2.5")) {
|
|
454
|
+
return { thinkingBudget: m.includes("pro") ? 128 : 0 };
|
|
455
|
+
}
|
|
456
|
+
if (m.includes("gemini-3") || m.includes("flash-latest") || m.includes("pro-latest")) {
|
|
457
|
+
return { thinkingLevel: m.includes("pro") ? "LOW" : "MINIMAL" };
|
|
458
|
+
}
|
|
459
|
+
return void 0;
|
|
460
|
+
}
|
|
461
|
+
function isThinkingConfigError(message) {
|
|
462
|
+
if (!message) return false;
|
|
463
|
+
return /thinking/i.test(message) && /(not supported|invalid|unsupported|unknown name|unexpected)/i.test(message);
|
|
464
|
+
}
|
|
436
465
|
var GeminiClient = class {
|
|
437
466
|
ai;
|
|
438
467
|
constructor(apiKey) {
|
|
@@ -479,6 +508,8 @@ var GeminiClient = class {
|
|
|
479
508
|
config.responseSchema = responseSchema;
|
|
480
509
|
}
|
|
481
510
|
if (systemInstruction) config.systemInstruction = systemInstruction;
|
|
511
|
+
const thinking = resolveThinking(model);
|
|
512
|
+
if (thinking) config.thinkingConfig = thinking;
|
|
482
513
|
const parts = uploaded.map((f) => ({
|
|
483
514
|
fileData: { fileUri: f.uri, mimeType: f.mimeType }
|
|
484
515
|
}));
|
|
@@ -517,6 +548,11 @@ var GeminiClient = class {
|
|
|
517
548
|
return result;
|
|
518
549
|
} catch (err) {
|
|
519
550
|
lastError = err instanceof Error ? err.message : String(err);
|
|
551
|
+
if (config.thinkingConfig && isThinkingConfigError(lastError)) {
|
|
552
|
+
delete config.thinkingConfig;
|
|
553
|
+
logger.warn(`[gemini] model ${model} rejected thinking config \u2014 retrying without it`);
|
|
554
|
+
continue;
|
|
555
|
+
}
|
|
520
556
|
logger.warn(`[gemini] attempt ${attempt + 1}/${maxRetries} failed: ${lastError}`);
|
|
521
557
|
logLlmCall({
|
|
522
558
|
ts: new Date(t0).toISOString(),
|
|
@@ -1711,6 +1747,12 @@ function has(passes, p) {
|
|
|
1711
1747
|
return passes.includes(p);
|
|
1712
1748
|
}
|
|
1713
1749
|
async function transcribe(opts) {
|
|
1750
|
+
if (!opts || typeof opts.input !== "string" || opts.input.length === 0) {
|
|
1751
|
+
throw new Error("transcribe(options): 'input' (path to the audio/video file) is required");
|
|
1752
|
+
}
|
|
1753
|
+
if (typeof opts.outputDir !== "string" || opts.outputDir.length === 0) {
|
|
1754
|
+
throw new Error("transcribe(options): 'outputDir' (directory for outputs) is required");
|
|
1755
|
+
}
|
|
1714
1756
|
const options = resolveOptions(opts);
|
|
1715
1757
|
const keys = resolveKeys(options.apiKeys);
|
|
1716
1758
|
logger.setLevel(options.logLevel);
|
|
@@ -1722,15 +1764,26 @@ async function transcribe(opts) {
|
|
|
1722
1764
|
setLlmLogPath(options.llmLog ? `${options.intermediatesDir}/llm-calls.jsonl` : null);
|
|
1723
1765
|
const sourcePath = `${options.intermediatesDir}/source.json`;
|
|
1724
1766
|
const sig = inputSignature(options.input);
|
|
1767
|
+
const cfgSig = configSignature(opts);
|
|
1725
1768
|
const prevSig = readJson(sourcePath);
|
|
1726
1769
|
const inputChanged = !prevSig || prevSig.signature !== sig;
|
|
1770
|
+
const configChanged = !prevSig || prevSig.config !== cfgSig;
|
|
1727
1771
|
if (inputChanged && prevSig) {
|
|
1728
1772
|
logger.warn(
|
|
1729
1773
|
`input file changed since last run (was ${prevSig.input ?? "?"}) \u2014 discarding cached intermediates`
|
|
1730
1774
|
);
|
|
1775
|
+
} else if (configChanged && prevSig) {
|
|
1776
|
+
logger.warn(
|
|
1777
|
+
"options changed since last run (model / chunking / instructions / provider) \u2014 discarding cached intermediates"
|
|
1778
|
+
);
|
|
1731
1779
|
}
|
|
1732
|
-
const forceAll = options.force || inputChanged;
|
|
1733
|
-
writeJson(sourcePath, {
|
|
1780
|
+
const forceAll = options.force || inputChanged || configChanged;
|
|
1781
|
+
writeJson(sourcePath, {
|
|
1782
|
+
input: options.input,
|
|
1783
|
+
signature: sig,
|
|
1784
|
+
config: cfgSig,
|
|
1785
|
+
updatedAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
1786
|
+
});
|
|
1734
1787
|
const passes = options.passes;
|
|
1735
1788
|
const models = {
|
|
1736
1789
|
transcribe: options.model ?? DEFAULT_TRANSCRIBE_MODEL,
|
|
@@ -1738,6 +1791,18 @@ async function transcribe(opts) {
|
|
|
1738
1791
|
};
|
|
1739
1792
|
if (!await checkFfmpeg()) throw new Error("ffmpeg/ffprobe not found in PATH");
|
|
1740
1793
|
if (!keys.gemini) throw new Error("GEMINI_API_KEY (or GOOGLE_API_KEY) is required");
|
|
1794
|
+
const tsProvider = options.timestampedProvider ?? "assemblyai";
|
|
1795
|
+
const willTimestamp = has(passes, "timestamped") || has(passes, "align");
|
|
1796
|
+
if (willTimestamp) {
|
|
1797
|
+
if (tsProvider === "assemblyai" && !keys.assemblyai) {
|
|
1798
|
+
throw new Error(
|
|
1799
|
+
"ASSEMBLYAI_API_KEY is required for the timestamped pass (or use --timestamped whisper-groq)"
|
|
1800
|
+
);
|
|
1801
|
+
}
|
|
1802
|
+
if (tsProvider === "whisper-groq" && !keys.groq) {
|
|
1803
|
+
throw new Error("GROQ_API_KEY is required for --timestamped whisper-groq");
|
|
1804
|
+
}
|
|
1805
|
+
}
|
|
1741
1806
|
let probeInfo = null;
|
|
1742
1807
|
const audioPath = `${options.intermediatesDir}/audio.flac`;
|
|
1743
1808
|
const probePath = `${options.intermediatesDir}/probe.json`;
|
|
@@ -1860,6 +1925,13 @@ async function transcribe(opts) {
|
|
|
1860
1925
|
(0, import_node_fs4.writeFileSync)(`${llmDir}/chunk_${String(chunk.index).padStart(2, "0")}_raw.json`, result2.raw);
|
|
1861
1926
|
return tagWith(result2, chunk);
|
|
1862
1927
|
});
|
|
1928
|
+
const errored = llmChunkResults.filter((r) => r.error);
|
|
1929
|
+
const producedSegments = llmChunkResults.reduce((n, r) => n + r.segments.length, 0);
|
|
1930
|
+
if (llmChunkResults.length > 0 && producedSegments === 0 && errored.length === llmChunkResults.length) {
|
|
1931
|
+
throw new Error(
|
|
1932
|
+
`LLM transcription failed for all ${llmChunkResults.length} chunk(s) with model "${models.transcribe}". First error: ${errored[0].error}`
|
|
1933
|
+
);
|
|
1934
|
+
}
|
|
1863
1935
|
} else {
|
|
1864
1936
|
const llmDir = `${options.intermediatesDir}/llm`;
|
|
1865
1937
|
if (!forceAll && (0, import_node_fs4.existsSync)(llmDir)) {
|
|
@@ -1972,7 +2044,10 @@ async function transcribe(opts) {
|
|
|
1972
2044
|
sourceFile: options.input,
|
|
1973
2045
|
duration,
|
|
1974
2046
|
processedAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
1975
|
-
models: {
|
|
2047
|
+
models: {
|
|
2048
|
+
transcribe: models.transcribe,
|
|
2049
|
+
timestamped: tsProvider === "whisper-groq" ? "whisper-large-v3 (groq)" : tsProvider === "none" ? "none" : "assemblyai-universal-2"
|
|
2050
|
+
},
|
|
1976
2051
|
passes
|
|
1977
2052
|
};
|
|
1978
2053
|
const result = { segments: finalSegments, speakers, metadata };
|