offmute-v2 0.0.3 → 0.0.5

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
@@ -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",
@@ -63,12 +64,14 @@ var MODELS = {
63
64
  gemini25Pro: "gemini-2.5-pro",
64
65
  gemini25Flash: "gemini-2.5-flash",
65
66
  gemini3Pro: "gemini-3-pro-preview",
67
+ gemini31Pro: "gemini-3.1-pro-preview",
68
+ geminiFlashLatest: "gemini-flash-latest",
66
69
  deepseek: "deepseek-chat",
67
70
  deepseekReasoner: "deepseek-reasoner",
68
71
  gpt4o: "gpt-4o",
69
72
  claudeSonnet: "claude-sonnet-4-5"
70
73
  };
71
- var DEFAULT_TRANSCRIBE_MODEL = MODELS.gemini25Flash;
74
+ var DEFAULT_TRANSCRIBE_MODEL = MODELS.gemini31Pro;
72
75
  var DEFAULT_REASONER_MODEL = MODELS.deepseek;
73
76
  function resolveKeys(injected) {
74
77
  const env = process.env;
@@ -85,7 +88,8 @@ function resolveKeys(injected) {
85
88
  function resolveOptions(opts) {
86
89
  return {
87
90
  input: opts.input,
88
- outputDir: opts.outputDir,
91
+ // Default: write next to the input file (e.g. meeting.md beside meeting.mp4) — no ./output folder.
92
+ outputDir: opts.outputDir ?? (0, import_node_path.dirname)((0, import_node_path.resolve)(opts.input)),
89
93
  intermediatesDir: opts.intermediatesDir ?? deriveIntermediatesDir(opts.input),
90
94
  instructions: opts.instructions,
91
95
  knownSpeakers: opts.knownSpeakers,
@@ -105,7 +109,7 @@ function resolveOptions(opts) {
105
109
  screenshotCount: opts.screenshotCount ?? 6,
106
110
  concurrency: opts.concurrency ?? 4,
107
111
  saveIntermediates: opts.saveIntermediates ?? true,
108
- formats: opts.formats ?? ["srt", "md", "json"],
112
+ formats: opts.formats ?? ["md"],
109
113
  diarizationLevel: opts.diarizationLevel ?? 2,
110
114
  apiKeys: opts.apiKeys,
111
115
  model: opts.model,
@@ -122,7 +126,7 @@ function deriveIntermediatesDir(input) {
122
126
  const abs = (0, import_node_path.resolve)(input);
123
127
  const hash = (0, import_node_crypto.createHash)("sha1").update(abs).digest("hex").slice(0, 8);
124
128
  const base = (0, import_node_path.basename)(input, extOf(input)) || "input";
125
- return `${(0, import_node_path.dirname)(abs)}/.offmute-v2-${base}-${hash}`;
129
+ return `${(0, import_node_os.tmpdir)()}/offmute-v2-${base}-${hash}`;
126
130
  }
127
131
  function extOf(p) {
128
132
  const i = p.lastIndexOf(".");
@@ -209,7 +213,7 @@ var import_node_child_process = require("child_process");
209
213
  var import_promises = require("fs/promises");
210
214
  var import_node_path2 = require("path");
211
215
  function run(cmd, args, _opts = {}) {
212
- return new Promise((resolve2, reject) => {
216
+ return new Promise((resolve3, reject) => {
213
217
  const child = (0, import_node_child_process.spawn)(cmd, args, { stdio: ["ignore", "pipe", "pipe"] });
214
218
  let stdout = "";
215
219
  let stderr = "";
@@ -217,7 +221,7 @@ function run(cmd, args, _opts = {}) {
217
221
  child.stderr.on("data", (d) => stderr += d.toString());
218
222
  child.on("error", reject);
219
223
  child.on("close", (code) => {
220
- if (code === 0) resolve2({ stdout, stderr });
224
+ if (code === 0) resolve3({ stdout, stderr });
221
225
  else {
222
226
  const tail = stderr.slice(-800);
223
227
  reject(new Error(`${cmd} exited ${code}: ${tail}`));
@@ -1748,10 +1752,9 @@ function has(passes, p) {
1748
1752
  }
1749
1753
  async function transcribe(opts) {
1750
1754
  if (!opts || typeof opts.input !== "string" || opts.input.length === 0) {
1751
- throw new Error("transcribe(options): 'input' (path to the audio/video file) is required");
1752
- }
1753
- if (typeof opts.outputDir !== "string" || opts.outputDir.length === 0) {
1754
- throw new Error("transcribe(options): 'outputDir' (directory for outputs) is required");
1755
+ throw new Error(
1756
+ "transcribe(options): 'input' (path to the audio/video file) is required"
1757
+ );
1755
1758
  }
1756
1759
  const options = resolveOptions(opts);
1757
1760
  const keys = resolveKeys(options.apiKeys);
@@ -1761,11 +1764,16 @@ async function transcribe(opts) {
1761
1764
  }
1762
1765
  (0, import_node_fs4.mkdirSync)(options.intermediatesDir, { recursive: true });
1763
1766
  (0, import_node_fs4.mkdirSync)(options.outputDir, { recursive: true });
1767
+ logger.info(
1768
+ `intermediates: ${(0, import_node_path5.resolve)(options.intermediatesDir)} (file://${(0, import_node_path5.resolve)(options.intermediatesDir)})`
1769
+ );
1764
1770
  setLlmLogPath(options.llmLog ? `${options.intermediatesDir}/llm-calls.jsonl` : null);
1765
1771
  const sourcePath = `${options.intermediatesDir}/source.json`;
1766
1772
  const sig = inputSignature(options.input);
1767
1773
  const cfgSig = configSignature(opts);
1768
- const prevSig = readJson(sourcePath);
1774
+ const prevSig = readJson(
1775
+ sourcePath
1776
+ );
1769
1777
  const inputChanged = !prevSig || prevSig.signature !== sig;
1770
1778
  const configChanged = !prevSig || prevSig.config !== cfgSig;
1771
1779
  if (inputChanged && prevSig) {
@@ -1804,7 +1812,8 @@ async function transcribe(opts) {
1804
1812
  }
1805
1813
  }
1806
1814
  let probeInfo = null;
1807
- const audioPath = `${options.intermediatesDir}/audio.flac`;
1815
+ const AUDIO_OPTS = { format: "mp3", bitrate: "64k" };
1816
+ const audioPath = `${options.intermediatesDir}/audio.mp3`;
1808
1817
  const probePath = `${options.intermediatesDir}/probe.json`;
1809
1818
  if (has(passes, "preprocess")) {
1810
1819
  logger.info("=== preprocess ===");
@@ -1814,8 +1823,8 @@ async function transcribe(opts) {
1814
1823
  writeJson(probePath, probeInfo);
1815
1824
  }
1816
1825
  if (!(0, import_node_fs4.existsSync)(audioPath) || forceAll) {
1817
- logger.info("extracting audio (mono 16kHz FLAC)...");
1818
- await extractAudio(options.input, audioPath, { format: "flac" });
1826
+ logger.info("extracting audio (mono 16kHz mp3)...");
1827
+ await extractAudio(options.input, audioPath, AUDIO_OPTS);
1819
1828
  }
1820
1829
  if (probeInfo.hasVideo) {
1821
1830
  const kfDir = `${options.intermediatesDir}/keyframes`;
@@ -1836,9 +1845,9 @@ async function transcribe(opts) {
1836
1845
  if (!description) {
1837
1846
  logger.info("=== describe ===");
1838
1847
  const client = new GeminiClient(keys.gemini);
1839
- const samplePath = `${options.intermediatesDir}/sample.flac`;
1848
+ const samplePath = `${options.intermediatesDir}/sample.mp3`;
1840
1849
  if (!(0, import_node_fs4.existsSync)(samplePath) || forceAll) {
1841
- await extractChunk(audioPath, samplePath, 0, Math.min(300, duration), { format: "flac" });
1850
+ await extractChunk(audioPath, samplePath, 0, Math.min(300, duration), AUDIO_OPTS);
1842
1851
  }
1843
1852
  const files = [{ path: samplePath }];
1844
1853
  const kfDir = `${options.intermediatesDir}/keyframes`;
@@ -1848,7 +1857,13 @@ async function transcribe(opts) {
1848
1857
  if ((0, import_node_fs4.existsSync)(p)) files.push({ path: p });
1849
1858
  }
1850
1859
  }
1851
- description = await describeMeeting(client, models.transcribe, files, (0, import_node_path5.basename)(options.input), options.instructions);
1860
+ description = await describeMeeting(
1861
+ client,
1862
+ models.transcribe,
1863
+ files,
1864
+ (0, import_node_path5.basename)(options.input),
1865
+ options.instructions
1866
+ );
1852
1867
  writeJson(descPath, description);
1853
1868
  logger.info(`description: ${description.description.slice(0, 120)}...`);
1854
1869
  }
@@ -1861,27 +1876,39 @@ async function transcribe(opts) {
1861
1876
  let silences = [];
1862
1877
  try {
1863
1878
  silences = await detectSilence(audioPath, { noiseDb: -15, minDuration: 0.3 });
1864
- if (silences.length < 3) silences = await detectSilence(audioPath, { noiseDb: -12, minDuration: 0.25 });
1879
+ if (silences.length < 3)
1880
+ silences = await detectSilence(audioPath, { noiseDb: -12, minDuration: 0.25 });
1865
1881
  } catch {
1866
1882
  }
1867
1883
  chunks = planChunks(duration, options.chunkDurationSec, options.chunkOverlapSec);
1868
1884
  if (silences.length > 3) {
1869
1885
  chunks = chunks.map((c) => {
1870
- const snapped = snapToSilence(c.start, silences, Math.min(10, options.chunkOverlapSec / 2));
1886
+ const snapped = snapToSilence(
1887
+ c.start,
1888
+ silences,
1889
+ Math.min(10, options.chunkOverlapSec / 2)
1890
+ );
1871
1891
  return { ...c, start: snapped, trustedStart: snapped + c.overlapWithPrevious };
1872
1892
  });
1873
1893
  }
1874
1894
  }
1875
1895
  const tagWith = (r, chunk) => ({
1876
1896
  ...r,
1877
- segments: r.segments.map((s) => ({ ...s, chunkIndex: chunk.index, trustedStart: chunk.trustedStart }))
1897
+ segments: r.segments.map((s) => ({
1898
+ ...s,
1899
+ chunkIndex: chunk.index,
1900
+ trustedStart: chunk.trustedStart
1901
+ }))
1878
1902
  });
1879
1903
  let llmChunkResults = [];
1880
1904
  if (has(passes, "llm-transcribe")) {
1881
1905
  logger.info("=== llm-transcribe ===");
1882
1906
  let runChunks = chunks;
1883
- if (options.onlyChunk !== void 0) runChunks = chunks.filter((c) => c.index === options.onlyChunk);
1884
- logger.info(`${runChunks.length} chunks (${options.chunkDurationSec}s, ${options.chunkOverlapSec}s overlap)`);
1907
+ if (options.onlyChunk !== void 0)
1908
+ runChunks = chunks.filter((c) => c.index === options.onlyChunk);
1909
+ logger.info(
1910
+ `${runChunks.length} chunks (${options.chunkDurationSec}s, ${options.chunkOverlapSec}s overlap)`
1911
+ );
1885
1912
  const client = new GeminiClient(keys.gemini);
1886
1913
  const llmDir = `${options.intermediatesDir}/llm`;
1887
1914
  (0, import_node_fs4.mkdirSync)(llmDir, { recursive: true });
@@ -1892,9 +1919,9 @@ async function transcribe(opts) {
1892
1919
  logger.info(`chunk ${chunk.index}: cached (${cached.segments.length} segments)`);
1893
1920
  return tagWith(cached, chunk);
1894
1921
  }
1895
- const chunkPath = `${llmDir}/chunk_${String(chunk.index).padStart(2, "0")}.flac`;
1922
+ const chunkPath = `${llmDir}/chunk_${String(chunk.index).padStart(2, "0")}.mp3`;
1896
1923
  if (!(0, import_node_fs4.existsSync)(chunkPath) || forceAll) {
1897
- await extractChunk(audioPath, chunkPath, chunk.start, chunk.end, { format: "flac" });
1924
+ await extractChunk(audioPath, chunkPath, chunk.start, chunk.end, AUDIO_OPTS);
1898
1925
  }
1899
1926
  let previousTail;
1900
1927
  if (chunk.index > 0) {
@@ -1905,7 +1932,9 @@ async function transcribe(opts) {
1905
1932
  previousTail = prev.segments.slice(-6).map((s) => `${s.speaker}: ${s.text}`).join("\n");
1906
1933
  }
1907
1934
  }
1908
- logger.info(`chunk ${chunk.index}: transcribing [${chunk.start.toFixed(0)}-${chunk.end.toFixed(0)}]s...`);
1935
+ logger.info(
1936
+ `chunk ${chunk.index}: transcribing [${chunk.start.toFixed(0)}-${chunk.end.toFixed(0)}]s...`
1937
+ );
1909
1938
  const result2 = await transcribeChunk(
1910
1939
  client,
1911
1940
  models.transcribe,
@@ -1922,7 +1951,10 @@ async function transcribe(opts) {
1922
1951
  { chunkDurationSec: chunk.end - chunk.start, validationRetries: 1 }
1923
1952
  );
1924
1953
  writeJson(parsedPath, result2);
1925
- (0, import_node_fs4.writeFileSync)(`${llmDir}/chunk_${String(chunk.index).padStart(2, "0")}_raw.json`, result2.raw);
1954
+ (0, import_node_fs4.writeFileSync)(
1955
+ `${llmDir}/chunk_${String(chunk.index).padStart(2, "0")}_raw.json`,
1956
+ result2.raw
1957
+ );
1926
1958
  return tagWith(result2, chunk);
1927
1959
  });
1928
1960
  const errored = llmChunkResults.filter((r) => r.error);
@@ -1957,19 +1989,24 @@ async function transcribe(opts) {
1957
1989
  if (provider === "whisper-groq") {
1958
1990
  logger.info("=== timestamped (Groq Whisper \u2014 no diarization) ===");
1959
1991
  if (!keys.groq) throw new Error("GROQ_API_KEY is required for whisper-groq");
1960
- const mp3Path = `${options.intermediatesDir}/audio.mp3`;
1961
- if (!(0, import_node_fs4.existsSync)(mp3Path) || options.force) {
1962
- await extractAudio(options.input, mp3Path, { format: "mp3", bitrate: "64k" });
1992
+ if (!(0, import_node_fs4.existsSync)(audioPath) || forceAll) {
1993
+ await extractAudio(options.input, audioPath, AUDIO_OPTS);
1963
1994
  }
1964
1995
  const { readFile: readFile2 } = await import("fs/promises");
1965
- const buf = await readFile2(mp3Path);
1996
+ const buf = await readFile2(audioPath);
1966
1997
  const groq = new WhisperGroqClient(keys.groq);
1967
1998
  asrResult = await groq.transcribe(buf);
1968
1999
  writeJson(`${options.intermediatesDir}/timestamped.json`, asrResult);
1969
2000
  } else {
1970
2001
  logger.info("=== timestamped (AssemblyAI) ===");
1971
- if (!keys.assemblyai) throw new Error("ASSEMBLYAI_API_KEY is required for the timestamped pass (or use --timestamped whisper-groq)");
1972
- const aai = new AssemblyAIProvider({ apiKey: keys.assemblyai, cacheDir: `${options.intermediatesDir}/assemblyai` });
2002
+ if (!keys.assemblyai)
2003
+ throw new Error(
2004
+ "ASSEMBLYAI_API_KEY is required for the timestamped pass (or use --timestamped whisper-groq)"
2005
+ );
2006
+ const aai = new AssemblyAIProvider({
2007
+ apiKey: keys.assemblyai,
2008
+ cacheDir: `${options.intermediatesDir}/assemblyai`
2009
+ });
1973
2010
  asrResult = await aai.transcribe(audioPath);
1974
2011
  writeJson(`${options.intermediatesDir}/timestamped.json`, asrResult);
1975
2012
  }
@@ -2013,7 +2050,11 @@ async function transcribe(opts) {
2013
2050
  }
2014
2051
  if (options.diarizationLevel >= 3 && has(passes, "identify") && keys.deepseek && description) {
2015
2052
  logger.info("=== identify (DeepSeek) ===");
2016
- const dsClient = OpenAICompatClient.fromProvider("deepseek", keys.deepseek, models.reasoner);
2053
+ const dsClient = OpenAICompatClient.fromProvider(
2054
+ "deepseek",
2055
+ keys.deepseek,
2056
+ models.reasoner
2057
+ );
2017
2058
  const id = await identifySpeakers(
2018
2059
  dsClient,
2019
2060
  models.reasoner,
@@ -2022,7 +2063,9 @@ async function transcribe(opts) {
2022
2063
  description.roster,
2023
2064
  options.knownSpeakers
2024
2065
  );
2025
- logger.info(`identified ${Object.keys(id.nameMap).length} speakers: ${JSON.stringify(id.nameMap)}`);
2066
+ logger.info(
2067
+ `identified ${Object.keys(id.nameMap).length} speakers: ${JSON.stringify(id.nameMap)}`
2068
+ );
2026
2069
  writeJson(`${options.intermediatesDir}/identified.json`, id);
2027
2070
  segments = segments.map(
2028
2071
  (s) => id.nameMap[s.speaker] ? { ...s, speakerName: id.nameMap[s.speaker] } : s
@@ -2053,9 +2096,18 @@ async function transcribe(opts) {
2053
2096
  const result = { segments: finalSegments, speakers, metadata };
2054
2097
  for (const fmt of options.formats) {
2055
2098
  const base = (0, import_node_path5.basename)(options.input, ext(options.input));
2056
- if (fmt === "srt") (0, import_node_fs4.writeFileSync)(`${options.outputDir}/${base}.srt`, formatSrt(result, { title: base }));
2057
- if (fmt === "md") (0, import_node_fs4.writeFileSync)(`${options.outputDir}/${base}.md`, formatMarkdown(result, { title: base }));
2058
- if (fmt === "json") (0, import_node_fs4.writeFileSync)(`${options.outputDir}/${base}.json`, formatJson(result));
2099
+ if (fmt === "srt")
2100
+ (0, import_node_fs4.writeFileSync)(
2101
+ `${options.outputDir}/${base}.srt`,
2102
+ formatSrt(result, { title: base })
2103
+ );
2104
+ if (fmt === "md")
2105
+ (0, import_node_fs4.writeFileSync)(
2106
+ `${options.outputDir}/${base}.md`,
2107
+ formatMarkdown(result, { title: base })
2108
+ );
2109
+ if (fmt === "json")
2110
+ (0, import_node_fs4.writeFileSync)(`${options.outputDir}/${base}.json`, formatJson(result));
2059
2111
  }
2060
2112
  logger.info(`outputs written to ${options.outputDir}`);
2061
2113
  return result;