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.cjs CHANGED
@@ -135,11 +135,11 @@ function resolveOptions(opts) {
135
135
  zeroStorage: opts.zeroStorage ?? true
136
136
  };
137
137
  }
138
- function deriveIntermediatesDir(input) {
138
+ function deriveIntermediatesDir(input, parent = (0, import_node_os.tmpdir)()) {
139
139
  const abs = (0, import_node_path.resolve)(input);
140
140
  const hash = (0, import_node_crypto.createHash)("sha1").update(abs).digest("hex").slice(0, 8);
141
141
  const base = (0, import_node_path.basename)(input, extOf(input)) || "input";
142
- return `${(0, import_node_os.tmpdir)()}/offmute-v2-${base}-${hash}`;
142
+ return (0, import_node_path.join)(parent, `offmute-v2-${base}-${hash}`);
143
143
  }
144
144
  function extOf(p) {
145
145
  const i = p.lastIndexOf(".");
@@ -3644,6 +3644,37 @@ function stageTag(name) {
3644
3644
  throw e;
3645
3645
  };
3646
3646
  }
3647
+ async function preflight(opts) {
3648
+ const options = resolveOptions(opts);
3649
+ const keys = resolveKeys(options.apiKeys);
3650
+ if (!await checkFfmpeg()) throw new Error("ffmpeg/ffprobe not found in PATH");
3651
+ if (!keys.gemini) throw new Error("GEMINI_API_KEY (or GOOGLE_API_KEY) is required");
3652
+ if (!has(options.passes, "timestamped") && !has(options.passes, "align")) return;
3653
+ const tsProvider = options.timestampedProvider ?? "assemblyai";
3654
+ if (tsProvider === "assemblyai" && !keys.assemblyai) {
3655
+ throw new Error(
3656
+ "ASSEMBLYAI_API_KEY is required for the timestamped pass (or use --timestamped elevenlabs / whisper-groq)"
3657
+ );
3658
+ }
3659
+ if (tsProvider === "whisper-groq" && !keys.groq) {
3660
+ throw new Error("GROQ_API_KEY is required for --timestamped whisper-groq");
3661
+ }
3662
+ if (tsProvider === "elevenlabs" && !keys.elevenlabs) {
3663
+ throw new Error("ELEVENLABS_API_KEY is required for --timestamped elevenlabs");
3664
+ }
3665
+ }
3666
+ function estimateRun(opts, durationSec) {
3667
+ const options = resolveOptions(opts);
3668
+ return estimateRunCost({
3669
+ durationSec,
3670
+ model: options.model ?? DEFAULT_TRANSCRIBE_MODEL,
3671
+ reasoner: options.reasoner ?? DEFAULT_REASONER_MODEL,
3672
+ tsProvider: options.timestampedProvider ?? "assemblyai",
3673
+ chunkSec: options.chunkDurationSec,
3674
+ overlapSec: options.chunkOverlapSec,
3675
+ identify: options.diarizationLevel >= 3 && has(options.passes, "identify")
3676
+ });
3677
+ }
3647
3678
  async function transcribe(opts) {
3648
3679
  if (!opts || typeof opts.input !== "string" || opts.input.length === 0) {
3649
3680
  throw new Error(
@@ -3698,23 +3729,9 @@ async function transcribe(opts) {
3698
3729
  };
3699
3730
  const emit = (event) => emitTo(options.onProgress, event);
3700
3731
  const geminiOpts = { zeroStorage: options.zeroStorage };
3701
- if (!await checkFfmpeg()) throw new Error("ffmpeg/ffprobe not found in PATH");
3702
- if (!keys.gemini) throw new Error("GEMINI_API_KEY (or GOOGLE_API_KEY) is required");
3732
+ await preflight(opts);
3703
3733
  const tsProvider = options.timestampedProvider ?? "assemblyai";
3704
3734
  const willTimestamp = has(passes, "timestamped") || has(passes, "align");
3705
- if (willTimestamp) {
3706
- if (tsProvider === "assemblyai" && !keys.assemblyai) {
3707
- throw new Error(
3708
- "ASSEMBLYAI_API_KEY is required for the timestamped pass (or use --timestamped elevenlabs / whisper-groq)"
3709
- );
3710
- }
3711
- if (tsProvider === "whisper-groq" && !keys.groq) {
3712
- throw new Error("GROQ_API_KEY is required for --timestamped whisper-groq");
3713
- }
3714
- if (tsProvider === "elevenlabs" && !keys.elevenlabs) {
3715
- throw new Error("ELEVENLABS_API_KEY is required for --timestamped elevenlabs");
3716
- }
3717
- }
3718
3735
  let probeInfo = null;
3719
3736
  const AUDIO_OPTS = { format: "mp3", bitrate: "64k" };
3720
3737
  const audioPath = `${options.intermediatesDir}/audio.mp3`;
@@ -3752,15 +3769,7 @@ async function transcribe(opts) {
3752
3769
  }
3753
3770
  if (!probeInfo) throw new Error("probe info missing (run preprocess)");
3754
3771
  const duration = probeInfo.duration;
3755
- const estimate = estimateRunCost({
3756
- durationSec: duration,
3757
- model: models.transcribe,
3758
- reasoner: models.reasoner,
3759
- tsProvider,
3760
- chunkSec: options.chunkDurationSec,
3761
- overlapSec: options.chunkOverlapSec,
3762
- identify: options.diarizationLevel >= 3 && has(passes, "identify")
3763
- });
3772
+ const estimate = estimateRun(opts, duration);
3764
3773
  logger.info(
3765
3774
  `estimated cost ~$${estimate.totalUsd.toFixed(2)}${estimate.incomplete ? " (+unpriced parts)" : ""} [${estimate.lines.join(" \xB7 ")}]`
3766
3775
  );