offmute-v2 0.2.0 → 0.3.0

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/index.js CHANGED
@@ -9,7 +9,7 @@ var DEFAULT_REASONER_MODEL = "deepseek-chat";
9
9
 
10
10
  // src/core/config.ts
11
11
  import { createHash } from "crypto";
12
- import { basename, dirname, resolve } from "path";
12
+ import { basename, dirname, join, resolve } from "path";
13
13
  import { statSync } from "fs";
14
14
  import { tmpdir } from "os";
15
15
  var DEFAULT_PASSES = [
@@ -83,11 +83,11 @@ function resolveOptions(opts) {
83
83
  zeroStorage: opts.zeroStorage ?? true
84
84
  };
85
85
  }
86
- function deriveIntermediatesDir(input) {
86
+ function deriveIntermediatesDir(input, parent = tmpdir()) {
87
87
  const abs = resolve(input);
88
88
  const hash = createHash("sha1").update(abs).digest("hex").slice(0, 8);
89
89
  const base = basename(input, extOf(input)) || "input";
90
- return `${tmpdir()}/offmute-v2-${base}-${hash}`;
90
+ return join(parent, `offmute-v2-${base}-${hash}`);
91
91
  }
92
92
  function extOf(p) {
93
93
  const i = p.lastIndexOf(".");
@@ -1203,9 +1203,9 @@ import {
1203
1203
  writeFileSync
1204
1204
  } from "fs";
1205
1205
  import { homedir } from "os";
1206
- import { join } from "path";
1206
+ import { join as join2 } from "path";
1207
1207
  function statsDir() {
1208
- return process.env.OFFMUTE_HOME || join(homedir(), ".offmute");
1208
+ return process.env.OFFMUTE_HOME || join2(homedir(), ".offmute");
1209
1209
  }
1210
1210
  function statsEnabled() {
1211
1211
  return !process.env.OFFMUTE_NO_STATS;
@@ -1223,7 +1223,7 @@ var EMPTY = {
1223
1223
  };
1224
1224
  function readStats() {
1225
1225
  try {
1226
- const p = join(statsDir(), "stats.json");
1226
+ const p = join2(statsDir(), "stats.json");
1227
1227
  if (!existsSync2(p)) return { ...EMPTY };
1228
1228
  return { ...EMPTY, ...JSON.parse(readFileSync(p, "utf-8")) };
1229
1229
  } catch {
@@ -1231,7 +1231,7 @@ function readStats() {
1231
1231
  }
1232
1232
  }
1233
1233
  function withStatsLock(dir, fn) {
1234
- const lock = join(dir, ".stats.lock");
1234
+ const lock = join2(dir, ".stats.lock");
1235
1235
  const deadline = Date.now() + 2e3;
1236
1236
  for (; ; ) {
1237
1237
  try {
@@ -1258,7 +1258,7 @@ function recordRun(rec, perModelCost) {
1258
1258
  try {
1259
1259
  const dir = statsDir();
1260
1260
  mkdirSync(dir, { recursive: true });
1261
- appendFileSync2(join(dir, "history.jsonl"), JSON.stringify(rec) + "\n");
1261
+ appendFileSync2(join2(dir, "history.jsonl"), JSON.stringify(rec) + "\n");
1262
1262
  withStatsLock(dir, () => {
1263
1263
  foldIntoAggregates(rec, perModelCost, dir);
1264
1264
  });
@@ -1281,7 +1281,7 @@ function foldIntoAggregates(rec, perModelCost, dir) {
1281
1281
  if (tModel) s.runsByModel[tModel] = (s.runsByModel[tModel] ?? 0) + 1;
1282
1282
  s.firstRun ??= rec.ts;
1283
1283
  s.lastRun = rec.ts;
1284
- writeFileSync(join(dir, "stats.json"), JSON.stringify(s, null, 2));
1284
+ writeFileSync(join2(dir, "stats.json"), JSON.stringify(s, null, 2));
1285
1285
  }
1286
1286
 
1287
1287
  // src/transcribe/describe.ts
@@ -3603,6 +3603,37 @@ function stageTag(name) {
3603
3603
  throw e;
3604
3604
  };
3605
3605
  }
3606
+ async function preflight(opts) {
3607
+ const options = resolveOptions(opts);
3608
+ const keys = resolveKeys(options.apiKeys);
3609
+ if (!await checkFfmpeg()) throw new Error("ffmpeg/ffprobe not found in PATH");
3610
+ if (!keys.gemini) throw new Error("GEMINI_API_KEY (or GOOGLE_API_KEY) is required");
3611
+ if (!has(options.passes, "timestamped") && !has(options.passes, "align")) return;
3612
+ const tsProvider = options.timestampedProvider ?? "assemblyai";
3613
+ if (tsProvider === "assemblyai" && !keys.assemblyai) {
3614
+ throw new Error(
3615
+ "ASSEMBLYAI_API_KEY is required for the timestamped pass (or use --timestamped elevenlabs / whisper-groq)"
3616
+ );
3617
+ }
3618
+ if (tsProvider === "whisper-groq" && !keys.groq) {
3619
+ throw new Error("GROQ_API_KEY is required for --timestamped whisper-groq");
3620
+ }
3621
+ if (tsProvider === "elevenlabs" && !keys.elevenlabs) {
3622
+ throw new Error("ELEVENLABS_API_KEY is required for --timestamped elevenlabs");
3623
+ }
3624
+ }
3625
+ function estimateRun(opts, durationSec) {
3626
+ const options = resolveOptions(opts);
3627
+ return estimateRunCost({
3628
+ durationSec,
3629
+ model: options.model ?? DEFAULT_TRANSCRIBE_MODEL,
3630
+ reasoner: options.reasoner ?? DEFAULT_REASONER_MODEL,
3631
+ tsProvider: options.timestampedProvider ?? "assemblyai",
3632
+ chunkSec: options.chunkDurationSec,
3633
+ overlapSec: options.chunkOverlapSec,
3634
+ identify: options.diarizationLevel >= 3 && has(options.passes, "identify")
3635
+ });
3636
+ }
3606
3637
  async function transcribe(opts) {
3607
3638
  if (!opts || typeof opts.input !== "string" || opts.input.length === 0) {
3608
3639
  throw new Error(
@@ -3657,23 +3688,9 @@ async function transcribe(opts) {
3657
3688
  };
3658
3689
  const emit = (event) => emitTo(options.onProgress, event);
3659
3690
  const geminiOpts = { zeroStorage: options.zeroStorage };
3660
- if (!await checkFfmpeg()) throw new Error("ffmpeg/ffprobe not found in PATH");
3661
- if (!keys.gemini) throw new Error("GEMINI_API_KEY (or GOOGLE_API_KEY) is required");
3691
+ await preflight(opts);
3662
3692
  const tsProvider = options.timestampedProvider ?? "assemblyai";
3663
3693
  const willTimestamp = has(passes, "timestamped") || has(passes, "align");
3664
- if (willTimestamp) {
3665
- if (tsProvider === "assemblyai" && !keys.assemblyai) {
3666
- throw new Error(
3667
- "ASSEMBLYAI_API_KEY is required for the timestamped pass (or use --timestamped elevenlabs / whisper-groq)"
3668
- );
3669
- }
3670
- if (tsProvider === "whisper-groq" && !keys.groq) {
3671
- throw new Error("GROQ_API_KEY is required for --timestamped whisper-groq");
3672
- }
3673
- if (tsProvider === "elevenlabs" && !keys.elevenlabs) {
3674
- throw new Error("ELEVENLABS_API_KEY is required for --timestamped elevenlabs");
3675
- }
3676
- }
3677
3694
  let probeInfo = null;
3678
3695
  const AUDIO_OPTS = { format: "mp3", bitrate: "64k" };
3679
3696
  const audioPath = `${options.intermediatesDir}/audio.mp3`;
@@ -3711,15 +3728,7 @@ async function transcribe(opts) {
3711
3728
  }
3712
3729
  if (!probeInfo) throw new Error("probe info missing (run preprocess)");
3713
3730
  const duration = probeInfo.duration;
3714
- const estimate = estimateRunCost({
3715
- durationSec: duration,
3716
- model: models.transcribe,
3717
- reasoner: models.reasoner,
3718
- tsProvider,
3719
- chunkSec: options.chunkDurationSec,
3720
- overlapSec: options.chunkOverlapSec,
3721
- identify: options.diarizationLevel >= 3 && has(passes, "identify")
3722
- });
3731
+ const estimate = estimateRun(opts, duration);
3723
3732
  logger.info(
3724
3733
  `estimated cost ~$${estimate.totalUsd.toFixed(2)}${estimate.incomplete ? " (+unpriced parts)" : ""} [${estimate.lines.join(" \xB7 ")}]`
3725
3734
  );