offmute-v2 0.0.3 → 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/README.md +6 -5
- 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.js
CHANGED
|
@@ -3,8 +3,9 @@ import { existsSync as existsSync2, mkdirSync, readFileSync, writeFileSync } fro
|
|
|
3
3
|
|
|
4
4
|
// src/core/config.ts
|
|
5
5
|
import { createHash } from "crypto";
|
|
6
|
-
import { basename,
|
|
6
|
+
import { basename, resolve } from "path";
|
|
7
7
|
import { statSync } from "fs";
|
|
8
|
+
import { tmpdir } from "os";
|
|
8
9
|
var DEFAULT_PASSES = [
|
|
9
10
|
"preprocess",
|
|
10
11
|
"describe",
|
|
@@ -77,7 +78,7 @@ function deriveIntermediatesDir(input) {
|
|
|
77
78
|
const abs = resolve(input);
|
|
78
79
|
const hash = createHash("sha1").update(abs).digest("hex").slice(0, 8);
|
|
79
80
|
const base = basename(input, extOf(input)) || "input";
|
|
80
|
-
return `${
|
|
81
|
+
return `${tmpdir()}/offmute-v2-${base}-${hash}`;
|
|
81
82
|
}
|
|
82
83
|
function extOf(p) {
|
|
83
84
|
const i = p.lastIndexOf(".");
|
|
@@ -162,9 +163,9 @@ var logger = {
|
|
|
162
163
|
// src/audio/ffmpeg.ts
|
|
163
164
|
import { spawn } from "child_process";
|
|
164
165
|
import { mkdir } from "fs/promises";
|
|
165
|
-
import { dirname
|
|
166
|
+
import { dirname } from "path";
|
|
166
167
|
function run(cmd, args, _opts = {}) {
|
|
167
|
-
return new Promise((
|
|
168
|
+
return new Promise((resolve3, reject) => {
|
|
168
169
|
const child = spawn(cmd, args, { stdio: ["ignore", "pipe", "pipe"] });
|
|
169
170
|
let stdout = "";
|
|
170
171
|
let stderr = "";
|
|
@@ -172,7 +173,7 @@ function run(cmd, args, _opts = {}) {
|
|
|
172
173
|
child.stderr.on("data", (d) => stderr += d.toString());
|
|
173
174
|
child.on("error", reject);
|
|
174
175
|
child.on("close", (code) => {
|
|
175
|
-
if (code === 0)
|
|
176
|
+
if (code === 0) resolve3({ stdout, stderr });
|
|
176
177
|
else {
|
|
177
178
|
const tail = stderr.slice(-800);
|
|
178
179
|
reject(new Error(`${cmd} exited ${code}: ${tail}`));
|
|
@@ -233,12 +234,12 @@ function audioArgs(opts) {
|
|
|
233
234
|
}
|
|
234
235
|
}
|
|
235
236
|
async function extractAudio(input, output, opts = {}) {
|
|
236
|
-
await mkdir(
|
|
237
|
+
await mkdir(dirname(output), { recursive: true });
|
|
237
238
|
const args = ["-y", "-i", input, ...audioArgs(opts), output];
|
|
238
239
|
await run("ffmpeg", args);
|
|
239
240
|
}
|
|
240
241
|
async function extractChunk(input, output, startSec, endSec, opts = {}) {
|
|
241
|
-
await mkdir(
|
|
242
|
+
await mkdir(dirname(output), { recursive: true });
|
|
242
243
|
const duration = Math.max(0, endSec - startSec);
|
|
243
244
|
const args = [
|
|
244
245
|
"-y",
|
|
@@ -569,7 +570,7 @@ import { AssemblyAI } from "assemblyai";
|
|
|
569
570
|
import { createHash as createHash2 } from "crypto";
|
|
570
571
|
import { readFile, mkdir as mkdir2, writeFile } from "fs/promises";
|
|
571
572
|
import { existsSync } from "fs";
|
|
572
|
-
import { dirname as
|
|
573
|
+
import { dirname as dirname2 } from "path";
|
|
573
574
|
async function fileHash(path) {
|
|
574
575
|
const buf = await readFile(path);
|
|
575
576
|
return createHash2("sha256").update(buf).digest("hex").slice(0, 24);
|
|
@@ -608,7 +609,7 @@ var AssemblyAIProvider = class {
|
|
|
608
609
|
}
|
|
609
610
|
const result = this.mapTranscript(transcript, hash);
|
|
610
611
|
if (cachePath) {
|
|
611
|
-
await mkdir2(
|
|
612
|
+
await mkdir2(dirname2(cachePath), { recursive: true });
|
|
612
613
|
await writeFile(cachePath, JSON.stringify(result, null, 2));
|
|
613
614
|
}
|
|
614
615
|
logger.info(
|
|
@@ -1672,7 +1673,7 @@ function formatJson(result) {
|
|
|
1672
1673
|
}
|
|
1673
1674
|
|
|
1674
1675
|
// src/core/pipeline.ts
|
|
1675
|
-
import { basename as basename3 } from "path";
|
|
1676
|
+
import { basename as basename3, resolve as resolve2 } from "path";
|
|
1676
1677
|
var JSON_OPTS = { encoding: "utf-8" };
|
|
1677
1678
|
function readJson(p) {
|
|
1678
1679
|
if (!existsSync2(p)) return null;
|
|
@@ -1716,6 +1717,7 @@ async function transcribe(opts) {
|
|
|
1716
1717
|
}
|
|
1717
1718
|
mkdirSync(options.intermediatesDir, { recursive: true });
|
|
1718
1719
|
mkdirSync(options.outputDir, { recursive: true });
|
|
1720
|
+
logger.info(`intermediates: ${resolve2(options.intermediatesDir)} (file://${resolve2(options.intermediatesDir)})`);
|
|
1719
1721
|
setLlmLogPath(options.llmLog ? `${options.intermediatesDir}/llm-calls.jsonl` : null);
|
|
1720
1722
|
const sourcePath = `${options.intermediatesDir}/source.json`;
|
|
1721
1723
|
const sig = inputSignature(options.input);
|
|
@@ -1759,7 +1761,8 @@ async function transcribe(opts) {
|
|
|
1759
1761
|
}
|
|
1760
1762
|
}
|
|
1761
1763
|
let probeInfo = null;
|
|
1762
|
-
const
|
|
1764
|
+
const AUDIO_OPTS = { format: "mp3", bitrate: "64k" };
|
|
1765
|
+
const audioPath = `${options.intermediatesDir}/audio.mp3`;
|
|
1763
1766
|
const probePath = `${options.intermediatesDir}/probe.json`;
|
|
1764
1767
|
if (has(passes, "preprocess")) {
|
|
1765
1768
|
logger.info("=== preprocess ===");
|
|
@@ -1769,8 +1772,8 @@ async function transcribe(opts) {
|
|
|
1769
1772
|
writeJson(probePath, probeInfo);
|
|
1770
1773
|
}
|
|
1771
1774
|
if (!existsSync2(audioPath) || forceAll) {
|
|
1772
|
-
logger.info("extracting audio (mono 16kHz
|
|
1773
|
-
await extractAudio(options.input, audioPath,
|
|
1775
|
+
logger.info("extracting audio (mono 16kHz mp3)...");
|
|
1776
|
+
await extractAudio(options.input, audioPath, AUDIO_OPTS);
|
|
1774
1777
|
}
|
|
1775
1778
|
if (probeInfo.hasVideo) {
|
|
1776
1779
|
const kfDir = `${options.intermediatesDir}/keyframes`;
|
|
@@ -1791,9 +1794,9 @@ async function transcribe(opts) {
|
|
|
1791
1794
|
if (!description) {
|
|
1792
1795
|
logger.info("=== describe ===");
|
|
1793
1796
|
const client = new GeminiClient(keys.gemini);
|
|
1794
|
-
const samplePath = `${options.intermediatesDir}/sample.
|
|
1797
|
+
const samplePath = `${options.intermediatesDir}/sample.mp3`;
|
|
1795
1798
|
if (!existsSync2(samplePath) || forceAll) {
|
|
1796
|
-
await extractChunk(audioPath, samplePath, 0, Math.min(300, duration),
|
|
1799
|
+
await extractChunk(audioPath, samplePath, 0, Math.min(300, duration), AUDIO_OPTS);
|
|
1797
1800
|
}
|
|
1798
1801
|
const files = [{ path: samplePath }];
|
|
1799
1802
|
const kfDir = `${options.intermediatesDir}/keyframes`;
|
|
@@ -1847,9 +1850,9 @@ async function transcribe(opts) {
|
|
|
1847
1850
|
logger.info(`chunk ${chunk.index}: cached (${cached.segments.length} segments)`);
|
|
1848
1851
|
return tagWith(cached, chunk);
|
|
1849
1852
|
}
|
|
1850
|
-
const chunkPath = `${llmDir}/chunk_${String(chunk.index).padStart(2, "0")}.
|
|
1853
|
+
const chunkPath = `${llmDir}/chunk_${String(chunk.index).padStart(2, "0")}.mp3`;
|
|
1851
1854
|
if (!existsSync2(chunkPath) || forceAll) {
|
|
1852
|
-
await extractChunk(audioPath, chunkPath, chunk.start, chunk.end,
|
|
1855
|
+
await extractChunk(audioPath, chunkPath, chunk.start, chunk.end, AUDIO_OPTS);
|
|
1853
1856
|
}
|
|
1854
1857
|
let previousTail;
|
|
1855
1858
|
if (chunk.index > 0) {
|
|
@@ -1912,12 +1915,11 @@ async function transcribe(opts) {
|
|
|
1912
1915
|
if (provider === "whisper-groq") {
|
|
1913
1916
|
logger.info("=== timestamped (Groq Whisper \u2014 no diarization) ===");
|
|
1914
1917
|
if (!keys.groq) throw new Error("GROQ_API_KEY is required for whisper-groq");
|
|
1915
|
-
|
|
1916
|
-
|
|
1917
|
-
await extractAudio(options.input, mp3Path, { format: "mp3", bitrate: "64k" });
|
|
1918
|
+
if (!existsSync2(audioPath) || forceAll) {
|
|
1919
|
+
await extractAudio(options.input, audioPath, AUDIO_OPTS);
|
|
1918
1920
|
}
|
|
1919
1921
|
const { readFile: readFile2 } = await import("fs/promises");
|
|
1920
|
-
const buf = await readFile2(
|
|
1922
|
+
const buf = await readFile2(audioPath);
|
|
1921
1923
|
const groq = new WhisperGroqClient(keys.groq);
|
|
1922
1924
|
asrResult = await groq.transcribe(buf);
|
|
1923
1925
|
writeJson(`${options.intermediatesDir}/timestamped.json`, asrResult);
|