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/README.md +55 -49
- package/dist/cli.cjs +94 -40
- package/dist/cli.cjs.map +1 -1
- package/dist/cli.js +95 -41
- package/dist/cli.js.map +1 -1
- package/dist/index.cjs +89 -37
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +90 -38
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.cts
CHANGED
|
@@ -119,8 +119,8 @@ interface ApiKeys {
|
|
|
119
119
|
interface PipelineOptions {
|
|
120
120
|
/** Input file path. */
|
|
121
121
|
input: string;
|
|
122
|
-
/** Output directory. */
|
|
123
|
-
outputDir
|
|
122
|
+
/** Output directory. Defaults to the input file's own directory. */
|
|
123
|
+
outputDir?: string;
|
|
124
124
|
/** Directory for intermediates (resumable). If omitted, derived per-input so
|
|
125
125
|
* different files never share a cache (see deriveIntermediatesDir). */
|
|
126
126
|
intermediatesDir?: string;
|
package/dist/index.d.ts
CHANGED
|
@@ -119,8 +119,8 @@ interface ApiKeys {
|
|
|
119
119
|
interface PipelineOptions {
|
|
120
120
|
/** Input file path. */
|
|
121
121
|
input: string;
|
|
122
|
-
/** Output directory. */
|
|
123
|
-
outputDir
|
|
122
|
+
/** Output directory. Defaults to the input file's own directory. */
|
|
123
|
+
outputDir?: string;
|
|
124
124
|
/** Directory for intermediates (resumable). If omitted, derived per-input so
|
|
125
125
|
* different files never share a cache (see deriveIntermediatesDir). */
|
|
126
126
|
intermediatesDir?: string;
|
package/dist/index.js
CHANGED
|
@@ -5,6 +5,7 @@ import { existsSync as existsSync2, mkdirSync, readFileSync, writeFileSync } fro
|
|
|
5
5
|
import { createHash } from "crypto";
|
|
6
6
|
import { basename, dirname, 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",
|
|
@@ -18,12 +19,14 @@ var MODELS = {
|
|
|
18
19
|
gemini25Pro: "gemini-2.5-pro",
|
|
19
20
|
gemini25Flash: "gemini-2.5-flash",
|
|
20
21
|
gemini3Pro: "gemini-3-pro-preview",
|
|
22
|
+
gemini31Pro: "gemini-3.1-pro-preview",
|
|
23
|
+
geminiFlashLatest: "gemini-flash-latest",
|
|
21
24
|
deepseek: "deepseek-chat",
|
|
22
25
|
deepseekReasoner: "deepseek-reasoner",
|
|
23
26
|
gpt4o: "gpt-4o",
|
|
24
27
|
claudeSonnet: "claude-sonnet-4-5"
|
|
25
28
|
};
|
|
26
|
-
var DEFAULT_TRANSCRIBE_MODEL = MODELS.
|
|
29
|
+
var DEFAULT_TRANSCRIBE_MODEL = MODELS.gemini31Pro;
|
|
27
30
|
var DEFAULT_REASONER_MODEL = MODELS.deepseek;
|
|
28
31
|
function resolveKeys(injected) {
|
|
29
32
|
const env = process.env;
|
|
@@ -40,7 +43,8 @@ function resolveKeys(injected) {
|
|
|
40
43
|
function resolveOptions(opts) {
|
|
41
44
|
return {
|
|
42
45
|
input: opts.input,
|
|
43
|
-
|
|
46
|
+
// Default: write next to the input file (e.g. meeting.md beside meeting.mp4) — no ./output folder.
|
|
47
|
+
outputDir: opts.outputDir ?? dirname(resolve(opts.input)),
|
|
44
48
|
intermediatesDir: opts.intermediatesDir ?? deriveIntermediatesDir(opts.input),
|
|
45
49
|
instructions: opts.instructions,
|
|
46
50
|
knownSpeakers: opts.knownSpeakers,
|
|
@@ -60,7 +64,7 @@ function resolveOptions(opts) {
|
|
|
60
64
|
screenshotCount: opts.screenshotCount ?? 6,
|
|
61
65
|
concurrency: opts.concurrency ?? 4,
|
|
62
66
|
saveIntermediates: opts.saveIntermediates ?? true,
|
|
63
|
-
formats: opts.formats ?? ["
|
|
67
|
+
formats: opts.formats ?? ["md"],
|
|
64
68
|
diarizationLevel: opts.diarizationLevel ?? 2,
|
|
65
69
|
apiKeys: opts.apiKeys,
|
|
66
70
|
model: opts.model,
|
|
@@ -77,7 +81,7 @@ function deriveIntermediatesDir(input) {
|
|
|
77
81
|
const abs = resolve(input);
|
|
78
82
|
const hash = createHash("sha1").update(abs).digest("hex").slice(0, 8);
|
|
79
83
|
const base = basename(input, extOf(input)) || "input";
|
|
80
|
-
return `${
|
|
84
|
+
return `${tmpdir()}/offmute-v2-${base}-${hash}`;
|
|
81
85
|
}
|
|
82
86
|
function extOf(p) {
|
|
83
87
|
const i = p.lastIndexOf(".");
|
|
@@ -164,7 +168,7 @@ import { spawn } from "child_process";
|
|
|
164
168
|
import { mkdir } from "fs/promises";
|
|
165
169
|
import { dirname as dirname2 } from "path";
|
|
166
170
|
function run(cmd, args, _opts = {}) {
|
|
167
|
-
return new Promise((
|
|
171
|
+
return new Promise((resolve3, reject) => {
|
|
168
172
|
const child = spawn(cmd, args, { stdio: ["ignore", "pipe", "pipe"] });
|
|
169
173
|
let stdout = "";
|
|
170
174
|
let stderr = "";
|
|
@@ -172,7 +176,7 @@ function run(cmd, args, _opts = {}) {
|
|
|
172
176
|
child.stderr.on("data", (d) => stderr += d.toString());
|
|
173
177
|
child.on("error", reject);
|
|
174
178
|
child.on("close", (code) => {
|
|
175
|
-
if (code === 0)
|
|
179
|
+
if (code === 0) resolve3({ stdout, stderr });
|
|
176
180
|
else {
|
|
177
181
|
const tail = stderr.slice(-800);
|
|
178
182
|
reject(new Error(`${cmd} exited ${code}: ${tail}`));
|
|
@@ -1672,7 +1676,7 @@ function formatJson(result) {
|
|
|
1672
1676
|
}
|
|
1673
1677
|
|
|
1674
1678
|
// src/core/pipeline.ts
|
|
1675
|
-
import { basename as basename3 } from "path";
|
|
1679
|
+
import { basename as basename3, resolve as resolve2 } from "path";
|
|
1676
1680
|
var JSON_OPTS = { encoding: "utf-8" };
|
|
1677
1681
|
function readJson(p) {
|
|
1678
1682
|
if (!existsSync2(p)) return null;
|
|
@@ -1703,10 +1707,9 @@ function has(passes, p) {
|
|
|
1703
1707
|
}
|
|
1704
1708
|
async function transcribe(opts) {
|
|
1705
1709
|
if (!opts || typeof opts.input !== "string" || opts.input.length === 0) {
|
|
1706
|
-
throw new Error(
|
|
1707
|
-
|
|
1708
|
-
|
|
1709
|
-
throw new Error("transcribe(options): 'outputDir' (directory for outputs) is required");
|
|
1710
|
+
throw new Error(
|
|
1711
|
+
"transcribe(options): 'input' (path to the audio/video file) is required"
|
|
1712
|
+
);
|
|
1710
1713
|
}
|
|
1711
1714
|
const options = resolveOptions(opts);
|
|
1712
1715
|
const keys = resolveKeys(options.apiKeys);
|
|
@@ -1716,11 +1719,16 @@ async function transcribe(opts) {
|
|
|
1716
1719
|
}
|
|
1717
1720
|
mkdirSync(options.intermediatesDir, { recursive: true });
|
|
1718
1721
|
mkdirSync(options.outputDir, { recursive: true });
|
|
1722
|
+
logger.info(
|
|
1723
|
+
`intermediates: ${resolve2(options.intermediatesDir)} (file://${resolve2(options.intermediatesDir)})`
|
|
1724
|
+
);
|
|
1719
1725
|
setLlmLogPath(options.llmLog ? `${options.intermediatesDir}/llm-calls.jsonl` : null);
|
|
1720
1726
|
const sourcePath = `${options.intermediatesDir}/source.json`;
|
|
1721
1727
|
const sig = inputSignature(options.input);
|
|
1722
1728
|
const cfgSig = configSignature(opts);
|
|
1723
|
-
const prevSig = readJson(
|
|
1729
|
+
const prevSig = readJson(
|
|
1730
|
+
sourcePath
|
|
1731
|
+
);
|
|
1724
1732
|
const inputChanged = !prevSig || prevSig.signature !== sig;
|
|
1725
1733
|
const configChanged = !prevSig || prevSig.config !== cfgSig;
|
|
1726
1734
|
if (inputChanged && prevSig) {
|
|
@@ -1759,7 +1767,8 @@ async function transcribe(opts) {
|
|
|
1759
1767
|
}
|
|
1760
1768
|
}
|
|
1761
1769
|
let probeInfo = null;
|
|
1762
|
-
const
|
|
1770
|
+
const AUDIO_OPTS = { format: "mp3", bitrate: "64k" };
|
|
1771
|
+
const audioPath = `${options.intermediatesDir}/audio.mp3`;
|
|
1763
1772
|
const probePath = `${options.intermediatesDir}/probe.json`;
|
|
1764
1773
|
if (has(passes, "preprocess")) {
|
|
1765
1774
|
logger.info("=== preprocess ===");
|
|
@@ -1769,8 +1778,8 @@ async function transcribe(opts) {
|
|
|
1769
1778
|
writeJson(probePath, probeInfo);
|
|
1770
1779
|
}
|
|
1771
1780
|
if (!existsSync2(audioPath) || forceAll) {
|
|
1772
|
-
logger.info("extracting audio (mono 16kHz
|
|
1773
|
-
await extractAudio(options.input, audioPath,
|
|
1781
|
+
logger.info("extracting audio (mono 16kHz mp3)...");
|
|
1782
|
+
await extractAudio(options.input, audioPath, AUDIO_OPTS);
|
|
1774
1783
|
}
|
|
1775
1784
|
if (probeInfo.hasVideo) {
|
|
1776
1785
|
const kfDir = `${options.intermediatesDir}/keyframes`;
|
|
@@ -1791,9 +1800,9 @@ async function transcribe(opts) {
|
|
|
1791
1800
|
if (!description) {
|
|
1792
1801
|
logger.info("=== describe ===");
|
|
1793
1802
|
const client = new GeminiClient(keys.gemini);
|
|
1794
|
-
const samplePath = `${options.intermediatesDir}/sample.
|
|
1803
|
+
const samplePath = `${options.intermediatesDir}/sample.mp3`;
|
|
1795
1804
|
if (!existsSync2(samplePath) || forceAll) {
|
|
1796
|
-
await extractChunk(audioPath, samplePath, 0, Math.min(300, duration),
|
|
1805
|
+
await extractChunk(audioPath, samplePath, 0, Math.min(300, duration), AUDIO_OPTS);
|
|
1797
1806
|
}
|
|
1798
1807
|
const files = [{ path: samplePath }];
|
|
1799
1808
|
const kfDir = `${options.intermediatesDir}/keyframes`;
|
|
@@ -1803,7 +1812,13 @@ async function transcribe(opts) {
|
|
|
1803
1812
|
if (existsSync2(p)) files.push({ path: p });
|
|
1804
1813
|
}
|
|
1805
1814
|
}
|
|
1806
|
-
description = await describeMeeting(
|
|
1815
|
+
description = await describeMeeting(
|
|
1816
|
+
client,
|
|
1817
|
+
models.transcribe,
|
|
1818
|
+
files,
|
|
1819
|
+
basename3(options.input),
|
|
1820
|
+
options.instructions
|
|
1821
|
+
);
|
|
1807
1822
|
writeJson(descPath, description);
|
|
1808
1823
|
logger.info(`description: ${description.description.slice(0, 120)}...`);
|
|
1809
1824
|
}
|
|
@@ -1816,27 +1831,39 @@ async function transcribe(opts) {
|
|
|
1816
1831
|
let silences = [];
|
|
1817
1832
|
try {
|
|
1818
1833
|
silences = await detectSilence(audioPath, { noiseDb: -15, minDuration: 0.3 });
|
|
1819
|
-
if (silences.length < 3)
|
|
1834
|
+
if (silences.length < 3)
|
|
1835
|
+
silences = await detectSilence(audioPath, { noiseDb: -12, minDuration: 0.25 });
|
|
1820
1836
|
} catch {
|
|
1821
1837
|
}
|
|
1822
1838
|
chunks = planChunks(duration, options.chunkDurationSec, options.chunkOverlapSec);
|
|
1823
1839
|
if (silences.length > 3) {
|
|
1824
1840
|
chunks = chunks.map((c) => {
|
|
1825
|
-
const snapped = snapToSilence(
|
|
1841
|
+
const snapped = snapToSilence(
|
|
1842
|
+
c.start,
|
|
1843
|
+
silences,
|
|
1844
|
+
Math.min(10, options.chunkOverlapSec / 2)
|
|
1845
|
+
);
|
|
1826
1846
|
return { ...c, start: snapped, trustedStart: snapped + c.overlapWithPrevious };
|
|
1827
1847
|
});
|
|
1828
1848
|
}
|
|
1829
1849
|
}
|
|
1830
1850
|
const tagWith = (r, chunk) => ({
|
|
1831
1851
|
...r,
|
|
1832
|
-
segments: r.segments.map((s) => ({
|
|
1852
|
+
segments: r.segments.map((s) => ({
|
|
1853
|
+
...s,
|
|
1854
|
+
chunkIndex: chunk.index,
|
|
1855
|
+
trustedStart: chunk.trustedStart
|
|
1856
|
+
}))
|
|
1833
1857
|
});
|
|
1834
1858
|
let llmChunkResults = [];
|
|
1835
1859
|
if (has(passes, "llm-transcribe")) {
|
|
1836
1860
|
logger.info("=== llm-transcribe ===");
|
|
1837
1861
|
let runChunks = chunks;
|
|
1838
|
-
if (options.onlyChunk !== void 0)
|
|
1839
|
-
|
|
1862
|
+
if (options.onlyChunk !== void 0)
|
|
1863
|
+
runChunks = chunks.filter((c) => c.index === options.onlyChunk);
|
|
1864
|
+
logger.info(
|
|
1865
|
+
`${runChunks.length} chunks (${options.chunkDurationSec}s, ${options.chunkOverlapSec}s overlap)`
|
|
1866
|
+
);
|
|
1840
1867
|
const client = new GeminiClient(keys.gemini);
|
|
1841
1868
|
const llmDir = `${options.intermediatesDir}/llm`;
|
|
1842
1869
|
mkdirSync(llmDir, { recursive: true });
|
|
@@ -1847,9 +1874,9 @@ async function transcribe(opts) {
|
|
|
1847
1874
|
logger.info(`chunk ${chunk.index}: cached (${cached.segments.length} segments)`);
|
|
1848
1875
|
return tagWith(cached, chunk);
|
|
1849
1876
|
}
|
|
1850
|
-
const chunkPath = `${llmDir}/chunk_${String(chunk.index).padStart(2, "0")}.
|
|
1877
|
+
const chunkPath = `${llmDir}/chunk_${String(chunk.index).padStart(2, "0")}.mp3`;
|
|
1851
1878
|
if (!existsSync2(chunkPath) || forceAll) {
|
|
1852
|
-
await extractChunk(audioPath, chunkPath, chunk.start, chunk.end,
|
|
1879
|
+
await extractChunk(audioPath, chunkPath, chunk.start, chunk.end, AUDIO_OPTS);
|
|
1853
1880
|
}
|
|
1854
1881
|
let previousTail;
|
|
1855
1882
|
if (chunk.index > 0) {
|
|
@@ -1860,7 +1887,9 @@ async function transcribe(opts) {
|
|
|
1860
1887
|
previousTail = prev.segments.slice(-6).map((s) => `${s.speaker}: ${s.text}`).join("\n");
|
|
1861
1888
|
}
|
|
1862
1889
|
}
|
|
1863
|
-
logger.info(
|
|
1890
|
+
logger.info(
|
|
1891
|
+
`chunk ${chunk.index}: transcribing [${chunk.start.toFixed(0)}-${chunk.end.toFixed(0)}]s...`
|
|
1892
|
+
);
|
|
1864
1893
|
const result2 = await transcribeChunk(
|
|
1865
1894
|
client,
|
|
1866
1895
|
models.transcribe,
|
|
@@ -1877,7 +1906,10 @@ async function transcribe(opts) {
|
|
|
1877
1906
|
{ chunkDurationSec: chunk.end - chunk.start, validationRetries: 1 }
|
|
1878
1907
|
);
|
|
1879
1908
|
writeJson(parsedPath, result2);
|
|
1880
|
-
writeFileSync(
|
|
1909
|
+
writeFileSync(
|
|
1910
|
+
`${llmDir}/chunk_${String(chunk.index).padStart(2, "0")}_raw.json`,
|
|
1911
|
+
result2.raw
|
|
1912
|
+
);
|
|
1881
1913
|
return tagWith(result2, chunk);
|
|
1882
1914
|
});
|
|
1883
1915
|
const errored = llmChunkResults.filter((r) => r.error);
|
|
@@ -1912,19 +1944,24 @@ async function transcribe(opts) {
|
|
|
1912
1944
|
if (provider === "whisper-groq") {
|
|
1913
1945
|
logger.info("=== timestamped (Groq Whisper \u2014 no diarization) ===");
|
|
1914
1946
|
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" });
|
|
1947
|
+
if (!existsSync2(audioPath) || forceAll) {
|
|
1948
|
+
await extractAudio(options.input, audioPath, AUDIO_OPTS);
|
|
1918
1949
|
}
|
|
1919
1950
|
const { readFile: readFile2 } = await import("fs/promises");
|
|
1920
|
-
const buf = await readFile2(
|
|
1951
|
+
const buf = await readFile2(audioPath);
|
|
1921
1952
|
const groq = new WhisperGroqClient(keys.groq);
|
|
1922
1953
|
asrResult = await groq.transcribe(buf);
|
|
1923
1954
|
writeJson(`${options.intermediatesDir}/timestamped.json`, asrResult);
|
|
1924
1955
|
} else {
|
|
1925
1956
|
logger.info("=== timestamped (AssemblyAI) ===");
|
|
1926
|
-
if (!keys.assemblyai)
|
|
1927
|
-
|
|
1957
|
+
if (!keys.assemblyai)
|
|
1958
|
+
throw new Error(
|
|
1959
|
+
"ASSEMBLYAI_API_KEY is required for the timestamped pass (or use --timestamped whisper-groq)"
|
|
1960
|
+
);
|
|
1961
|
+
const aai = new AssemblyAIProvider({
|
|
1962
|
+
apiKey: keys.assemblyai,
|
|
1963
|
+
cacheDir: `${options.intermediatesDir}/assemblyai`
|
|
1964
|
+
});
|
|
1928
1965
|
asrResult = await aai.transcribe(audioPath);
|
|
1929
1966
|
writeJson(`${options.intermediatesDir}/timestamped.json`, asrResult);
|
|
1930
1967
|
}
|
|
@@ -1968,7 +2005,11 @@ async function transcribe(opts) {
|
|
|
1968
2005
|
}
|
|
1969
2006
|
if (options.diarizationLevel >= 3 && has(passes, "identify") && keys.deepseek && description) {
|
|
1970
2007
|
logger.info("=== identify (DeepSeek) ===");
|
|
1971
|
-
const dsClient = OpenAICompatClient.fromProvider(
|
|
2008
|
+
const dsClient = OpenAICompatClient.fromProvider(
|
|
2009
|
+
"deepseek",
|
|
2010
|
+
keys.deepseek,
|
|
2011
|
+
models.reasoner
|
|
2012
|
+
);
|
|
1972
2013
|
const id = await identifySpeakers(
|
|
1973
2014
|
dsClient,
|
|
1974
2015
|
models.reasoner,
|
|
@@ -1977,7 +2018,9 @@ async function transcribe(opts) {
|
|
|
1977
2018
|
description.roster,
|
|
1978
2019
|
options.knownSpeakers
|
|
1979
2020
|
);
|
|
1980
|
-
logger.info(
|
|
2021
|
+
logger.info(
|
|
2022
|
+
`identified ${Object.keys(id.nameMap).length} speakers: ${JSON.stringify(id.nameMap)}`
|
|
2023
|
+
);
|
|
1981
2024
|
writeJson(`${options.intermediatesDir}/identified.json`, id);
|
|
1982
2025
|
segments = segments.map(
|
|
1983
2026
|
(s) => id.nameMap[s.speaker] ? { ...s, speakerName: id.nameMap[s.speaker] } : s
|
|
@@ -2008,9 +2051,18 @@ async function transcribe(opts) {
|
|
|
2008
2051
|
const result = { segments: finalSegments, speakers, metadata };
|
|
2009
2052
|
for (const fmt of options.formats) {
|
|
2010
2053
|
const base = basename3(options.input, ext(options.input));
|
|
2011
|
-
if (fmt === "srt")
|
|
2012
|
-
|
|
2013
|
-
|
|
2054
|
+
if (fmt === "srt")
|
|
2055
|
+
writeFileSync(
|
|
2056
|
+
`${options.outputDir}/${base}.srt`,
|
|
2057
|
+
formatSrt(result, { title: base })
|
|
2058
|
+
);
|
|
2059
|
+
if (fmt === "md")
|
|
2060
|
+
writeFileSync(
|
|
2061
|
+
`${options.outputDir}/${base}.md`,
|
|
2062
|
+
formatMarkdown(result, { title: base })
|
|
2063
|
+
);
|
|
2064
|
+
if (fmt === "json")
|
|
2065
|
+
writeFileSync(`${options.outputDir}/${base}.json`, formatJson(result));
|
|
2014
2066
|
}
|
|
2015
2067
|
logger.info(`outputs written to ${options.outputDir}`);
|
|
2016
2068
|
return result;
|