offmute-v2 0.0.2 → 0.0.4
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 +250 -58
- package/dist/cli.cjs +16 -14
- package/dist/cli.cjs.map +1 -1
- package/dist/cli.js +25 -23
- package/dist/cli.js.map +1 -1
- package/dist/index.cjs +16 -14
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +23 -21
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -50,6 +50,7 @@ var import_node_fs4 = require("fs");
|
|
|
50
50
|
var import_node_crypto = require("crypto");
|
|
51
51
|
var import_node_path = require("path");
|
|
52
52
|
var import_node_fs = require("fs");
|
|
53
|
+
var import_node_os = require("os");
|
|
53
54
|
var DEFAULT_PASSES = [
|
|
54
55
|
"preprocess",
|
|
55
56
|
"describe",
|
|
@@ -122,7 +123,7 @@ function deriveIntermediatesDir(input) {
|
|
|
122
123
|
const abs = (0, import_node_path.resolve)(input);
|
|
123
124
|
const hash = (0, import_node_crypto.createHash)("sha1").update(abs).digest("hex").slice(0, 8);
|
|
124
125
|
const base = (0, import_node_path.basename)(input, extOf(input)) || "input";
|
|
125
|
-
return `${(0,
|
|
126
|
+
return `${(0, import_node_os.tmpdir)()}/offmute-v2-${base}-${hash}`;
|
|
126
127
|
}
|
|
127
128
|
function extOf(p) {
|
|
128
129
|
const i = p.lastIndexOf(".");
|
|
@@ -209,7 +210,7 @@ var import_node_child_process = require("child_process");
|
|
|
209
210
|
var import_promises = require("fs/promises");
|
|
210
211
|
var import_node_path2 = require("path");
|
|
211
212
|
function run(cmd, args, _opts = {}) {
|
|
212
|
-
return new Promise((
|
|
213
|
+
return new Promise((resolve3, reject) => {
|
|
213
214
|
const child = (0, import_node_child_process.spawn)(cmd, args, { stdio: ["ignore", "pipe", "pipe"] });
|
|
214
215
|
let stdout = "";
|
|
215
216
|
let stderr = "";
|
|
@@ -217,7 +218,7 @@ function run(cmd, args, _opts = {}) {
|
|
|
217
218
|
child.stderr.on("data", (d) => stderr += d.toString());
|
|
218
219
|
child.on("error", reject);
|
|
219
220
|
child.on("close", (code) => {
|
|
220
|
-
if (code === 0)
|
|
221
|
+
if (code === 0) resolve3({ stdout, stderr });
|
|
221
222
|
else {
|
|
222
223
|
const tail = stderr.slice(-800);
|
|
223
224
|
reject(new Error(`${cmd} exited ${code}: ${tail}`));
|
|
@@ -1761,6 +1762,7 @@ async function transcribe(opts) {
|
|
|
1761
1762
|
}
|
|
1762
1763
|
(0, import_node_fs4.mkdirSync)(options.intermediatesDir, { recursive: true });
|
|
1763
1764
|
(0, import_node_fs4.mkdirSync)(options.outputDir, { recursive: true });
|
|
1765
|
+
logger.info(`intermediates: ${(0, import_node_path5.resolve)(options.intermediatesDir)} (file://${(0, import_node_path5.resolve)(options.intermediatesDir)})`);
|
|
1764
1766
|
setLlmLogPath(options.llmLog ? `${options.intermediatesDir}/llm-calls.jsonl` : null);
|
|
1765
1767
|
const sourcePath = `${options.intermediatesDir}/source.json`;
|
|
1766
1768
|
const sig = inputSignature(options.input);
|
|
@@ -1804,7 +1806,8 @@ async function transcribe(opts) {
|
|
|
1804
1806
|
}
|
|
1805
1807
|
}
|
|
1806
1808
|
let probeInfo = null;
|
|
1807
|
-
const
|
|
1809
|
+
const AUDIO_OPTS = { format: "mp3", bitrate: "64k" };
|
|
1810
|
+
const audioPath = `${options.intermediatesDir}/audio.mp3`;
|
|
1808
1811
|
const probePath = `${options.intermediatesDir}/probe.json`;
|
|
1809
1812
|
if (has(passes, "preprocess")) {
|
|
1810
1813
|
logger.info("=== preprocess ===");
|
|
@@ -1814,8 +1817,8 @@ async function transcribe(opts) {
|
|
|
1814
1817
|
writeJson(probePath, probeInfo);
|
|
1815
1818
|
}
|
|
1816
1819
|
if (!(0, import_node_fs4.existsSync)(audioPath) || forceAll) {
|
|
1817
|
-
logger.info("extracting audio (mono 16kHz
|
|
1818
|
-
await extractAudio(options.input, audioPath,
|
|
1820
|
+
logger.info("extracting audio (mono 16kHz mp3)...");
|
|
1821
|
+
await extractAudio(options.input, audioPath, AUDIO_OPTS);
|
|
1819
1822
|
}
|
|
1820
1823
|
if (probeInfo.hasVideo) {
|
|
1821
1824
|
const kfDir = `${options.intermediatesDir}/keyframes`;
|
|
@@ -1836,9 +1839,9 @@ async function transcribe(opts) {
|
|
|
1836
1839
|
if (!description) {
|
|
1837
1840
|
logger.info("=== describe ===");
|
|
1838
1841
|
const client = new GeminiClient(keys.gemini);
|
|
1839
|
-
const samplePath = `${options.intermediatesDir}/sample.
|
|
1842
|
+
const samplePath = `${options.intermediatesDir}/sample.mp3`;
|
|
1840
1843
|
if (!(0, import_node_fs4.existsSync)(samplePath) || forceAll) {
|
|
1841
|
-
await extractChunk(audioPath, samplePath, 0, Math.min(300, duration),
|
|
1844
|
+
await extractChunk(audioPath, samplePath, 0, Math.min(300, duration), AUDIO_OPTS);
|
|
1842
1845
|
}
|
|
1843
1846
|
const files = [{ path: samplePath }];
|
|
1844
1847
|
const kfDir = `${options.intermediatesDir}/keyframes`;
|
|
@@ -1892,9 +1895,9 @@ async function transcribe(opts) {
|
|
|
1892
1895
|
logger.info(`chunk ${chunk.index}: cached (${cached.segments.length} segments)`);
|
|
1893
1896
|
return tagWith(cached, chunk);
|
|
1894
1897
|
}
|
|
1895
|
-
const chunkPath = `${llmDir}/chunk_${String(chunk.index).padStart(2, "0")}.
|
|
1898
|
+
const chunkPath = `${llmDir}/chunk_${String(chunk.index).padStart(2, "0")}.mp3`;
|
|
1896
1899
|
if (!(0, import_node_fs4.existsSync)(chunkPath) || forceAll) {
|
|
1897
|
-
await extractChunk(audioPath, chunkPath, chunk.start, chunk.end,
|
|
1900
|
+
await extractChunk(audioPath, chunkPath, chunk.start, chunk.end, AUDIO_OPTS);
|
|
1898
1901
|
}
|
|
1899
1902
|
let previousTail;
|
|
1900
1903
|
if (chunk.index > 0) {
|
|
@@ -1957,12 +1960,11 @@ async function transcribe(opts) {
|
|
|
1957
1960
|
if (provider === "whisper-groq") {
|
|
1958
1961
|
logger.info("=== timestamped (Groq Whisper \u2014 no diarization) ===");
|
|
1959
1962
|
if (!keys.groq) throw new Error("GROQ_API_KEY is required for whisper-groq");
|
|
1960
|
-
|
|
1961
|
-
|
|
1962
|
-
await extractAudio(options.input, mp3Path, { format: "mp3", bitrate: "64k" });
|
|
1963
|
+
if (!(0, import_node_fs4.existsSync)(audioPath) || forceAll) {
|
|
1964
|
+
await extractAudio(options.input, audioPath, AUDIO_OPTS);
|
|
1963
1965
|
}
|
|
1964
1966
|
const { readFile: readFile2 } = await import("fs/promises");
|
|
1965
|
-
const buf = await readFile2(
|
|
1967
|
+
const buf = await readFile2(audioPath);
|
|
1966
1968
|
const groq = new WhisperGroqClient(keys.groq);
|
|
1967
1969
|
asrResult = await groq.transcribe(buf);
|
|
1968
1970
|
writeJson(`${options.intermediatesDir}/timestamped.json`, asrResult);
|