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/dist/cli.js CHANGED
@@ -4,15 +4,16 @@
4
4
  import { Command } from "commander";
5
5
  import { readFileSync as readFileSync2 } from "fs";
6
6
  import { fileURLToPath } from "url";
7
- import { dirname as dirname4, join } from "path";
7
+ import { dirname as dirname3, join } from "path";
8
8
 
9
9
  // src/core/pipeline.ts
10
10
  import { existsSync as existsSync2, mkdirSync, readFileSync, writeFileSync } from "fs";
11
11
 
12
12
  // src/core/config.ts
13
13
  import { createHash } from "crypto";
14
- import { basename, dirname, resolve } from "path";
14
+ import { basename, resolve } from "path";
15
15
  import { statSync } from "fs";
16
+ import { tmpdir } from "os";
16
17
  var DEFAULT_PASSES = [
17
18
  "preprocess",
18
19
  "describe",
@@ -85,7 +86,7 @@ function deriveIntermediatesDir(input2) {
85
86
  const abs = resolve(input2);
86
87
  const hash = createHash("sha1").update(abs).digest("hex").slice(0, 8);
87
88
  const base = basename(input2, extOf(input2)) || "input";
88
- return `${dirname(abs)}/.offmute-v2-${base}-${hash}`;
89
+ return `${tmpdir()}/offmute-v2-${base}-${hash}`;
89
90
  }
90
91
  function extOf(p) {
91
92
  const i = p.lastIndexOf(".");
@@ -170,9 +171,9 @@ var logger = {
170
171
  // src/audio/ffmpeg.ts
171
172
  import { spawn } from "child_process";
172
173
  import { mkdir } from "fs/promises";
173
- import { dirname as dirname2 } from "path";
174
+ import { dirname } from "path";
174
175
  function run(cmd, args, _opts = {}) {
175
- return new Promise((resolve2, reject) => {
176
+ return new Promise((resolve3, reject) => {
176
177
  const child = spawn(cmd, args, { stdio: ["ignore", "pipe", "pipe"] });
177
178
  let stdout = "";
178
179
  let stderr = "";
@@ -180,7 +181,7 @@ function run(cmd, args, _opts = {}) {
180
181
  child.stderr.on("data", (d) => stderr += d.toString());
181
182
  child.on("error", reject);
182
183
  child.on("close", (code) => {
183
- if (code === 0) resolve2({ stdout, stderr });
184
+ if (code === 0) resolve3({ stdout, stderr });
184
185
  else {
185
186
  const tail = stderr.slice(-800);
186
187
  reject(new Error(`${cmd} exited ${code}: ${tail}`));
@@ -241,12 +242,12 @@ function audioArgs(opts2) {
241
242
  }
242
243
  }
243
244
  async function extractAudio(input2, output, opts2 = {}) {
244
- await mkdir(dirname2(output), { recursive: true });
245
+ await mkdir(dirname(output), { recursive: true });
245
246
  const args = ["-y", "-i", input2, ...audioArgs(opts2), output];
246
247
  await run("ffmpeg", args);
247
248
  }
248
249
  async function extractChunk(input2, output, startSec, endSec, opts2 = {}) {
249
- await mkdir(dirname2(output), { recursive: true });
250
+ await mkdir(dirname(output), { recursive: true });
250
251
  const duration = Math.max(0, endSec - startSec);
251
252
  const args = [
252
253
  "-y",
@@ -577,7 +578,7 @@ import { AssemblyAI } from "assemblyai";
577
578
  import { createHash as createHash2 } from "crypto";
578
579
  import { readFile, mkdir as mkdir2, writeFile } from "fs/promises";
579
580
  import { existsSync } from "fs";
580
- import { dirname as dirname3 } from "path";
581
+ import { dirname as dirname2 } from "path";
581
582
  async function fileHash(path) {
582
583
  const buf = await readFile(path);
583
584
  return createHash2("sha256").update(buf).digest("hex").slice(0, 24);
@@ -616,7 +617,7 @@ var AssemblyAIProvider = class {
616
617
  }
617
618
  const result = this.mapTranscript(transcript, hash);
618
619
  if (cachePath) {
619
- await mkdir2(dirname3(cachePath), { recursive: true });
620
+ await mkdir2(dirname2(cachePath), { recursive: true });
620
621
  await writeFile(cachePath, JSON.stringify(result, null, 2));
621
622
  }
622
623
  logger.info(
@@ -1665,7 +1666,7 @@ function formatJson(result) {
1665
1666
  }
1666
1667
 
1667
1668
  // src/core/pipeline.ts
1668
- import { basename as basename3 } from "path";
1669
+ import { basename as basename3, resolve as resolve2 } from "path";
1669
1670
  var JSON_OPTS = { encoding: "utf-8" };
1670
1671
  function readJson(p) {
1671
1672
  if (!existsSync2(p)) return null;
@@ -1709,6 +1710,7 @@ async function transcribe(opts2) {
1709
1710
  }
1710
1711
  mkdirSync(options.intermediatesDir, { recursive: true });
1711
1712
  mkdirSync(options.outputDir, { recursive: true });
1713
+ logger.info(`intermediates: ${resolve2(options.intermediatesDir)} (file://${resolve2(options.intermediatesDir)})`);
1712
1714
  setLlmLogPath(options.llmLog ? `${options.intermediatesDir}/llm-calls.jsonl` : null);
1713
1715
  const sourcePath = `${options.intermediatesDir}/source.json`;
1714
1716
  const sig = inputSignature(options.input);
@@ -1752,7 +1754,8 @@ async function transcribe(opts2) {
1752
1754
  }
1753
1755
  }
1754
1756
  let probeInfo = null;
1755
- const audioPath = `${options.intermediatesDir}/audio.flac`;
1757
+ const AUDIO_OPTS = { format: "mp3", bitrate: "64k" };
1758
+ const audioPath = `${options.intermediatesDir}/audio.mp3`;
1756
1759
  const probePath = `${options.intermediatesDir}/probe.json`;
1757
1760
  if (has(passes2, "preprocess")) {
1758
1761
  logger.info("=== preprocess ===");
@@ -1762,8 +1765,8 @@ async function transcribe(opts2) {
1762
1765
  writeJson(probePath, probeInfo);
1763
1766
  }
1764
1767
  if (!existsSync2(audioPath) || forceAll) {
1765
- logger.info("extracting audio (mono 16kHz FLAC)...");
1766
- await extractAudio(options.input, audioPath, { format: "flac" });
1768
+ logger.info("extracting audio (mono 16kHz mp3)...");
1769
+ await extractAudio(options.input, audioPath, AUDIO_OPTS);
1767
1770
  }
1768
1771
  if (probeInfo.hasVideo) {
1769
1772
  const kfDir = `${options.intermediatesDir}/keyframes`;
@@ -1784,9 +1787,9 @@ async function transcribe(opts2) {
1784
1787
  if (!description) {
1785
1788
  logger.info("=== describe ===");
1786
1789
  const client = new GeminiClient(keys.gemini);
1787
- const samplePath = `${options.intermediatesDir}/sample.flac`;
1790
+ const samplePath = `${options.intermediatesDir}/sample.mp3`;
1788
1791
  if (!existsSync2(samplePath) || forceAll) {
1789
- await extractChunk(audioPath, samplePath, 0, Math.min(300, duration), { format: "flac" });
1792
+ await extractChunk(audioPath, samplePath, 0, Math.min(300, duration), AUDIO_OPTS);
1790
1793
  }
1791
1794
  const files = [{ path: samplePath }];
1792
1795
  const kfDir = `${options.intermediatesDir}/keyframes`;
@@ -1840,9 +1843,9 @@ async function transcribe(opts2) {
1840
1843
  logger.info(`chunk ${chunk.index}: cached (${cached.segments.length} segments)`);
1841
1844
  return tagWith(cached, chunk);
1842
1845
  }
1843
- const chunkPath = `${llmDir}/chunk_${String(chunk.index).padStart(2, "0")}.flac`;
1846
+ const chunkPath = `${llmDir}/chunk_${String(chunk.index).padStart(2, "0")}.mp3`;
1844
1847
  if (!existsSync2(chunkPath) || forceAll) {
1845
- await extractChunk(audioPath, chunkPath, chunk.start, chunk.end, { format: "flac" });
1848
+ await extractChunk(audioPath, chunkPath, chunk.start, chunk.end, AUDIO_OPTS);
1846
1849
  }
1847
1850
  let previousTail;
1848
1851
  if (chunk.index > 0) {
@@ -1905,12 +1908,11 @@ async function transcribe(opts2) {
1905
1908
  if (provider === "whisper-groq") {
1906
1909
  logger.info("=== timestamped (Groq Whisper \u2014 no diarization) ===");
1907
1910
  if (!keys.groq) throw new Error("GROQ_API_KEY is required for whisper-groq");
1908
- const mp3Path = `${options.intermediatesDir}/audio.mp3`;
1909
- if (!existsSync2(mp3Path) || options.force) {
1910
- await extractAudio(options.input, mp3Path, { format: "mp3", bitrate: "64k" });
1911
+ if (!existsSync2(audioPath) || forceAll) {
1912
+ await extractAudio(options.input, audioPath, AUDIO_OPTS);
1911
1913
  }
1912
1914
  const { readFile: readFile2 } = await import("fs/promises");
1913
- const buf = await readFile2(mp3Path);
1915
+ const buf = await readFile2(audioPath);
1914
1916
  const groq = new WhisperGroqClient(keys.groq);
1915
1917
  asrResult = await groq.transcribe(buf);
1916
1918
  writeJson(`${options.intermediatesDir}/timestamped.json`, asrResult);
@@ -2016,7 +2018,7 @@ function ext(p) {
2016
2018
  // src/cli.ts
2017
2019
  var packageVersion = "0.0.0";
2018
2020
  try {
2019
- const here = dirname4(fileURLToPath(import.meta.url));
2021
+ const here = dirname3(fileURLToPath(import.meta.url));
2020
2022
  const pkg = JSON.parse(readFileSync2(join(here, "..", "package.json"), "utf-8"));
2021
2023
  packageVersion = pkg.version;
2022
2024
  } catch {