mirror of
https://github.com/heygen-com/hyperframes.git
synced 2026-11-23 11:29:54 +00:00
fix(media-use): duck, cut, transcribe, dither and audio scripts print control characters as escapes (#8235)
* fix(media-use): duck, cut, transcribe and dither lines show control characters as escapes audio-duck, transcript-cut, transcribe and dither now print file paths, error messages and text read from project files through terminalText, so control characters show as visible escapes. Multi-line errors keep their line breaks. --json output is unchanged. * fix(media-use): audio engine, wait-bgm and heygen-tts lines show control characters as escapes audio.mjs, wait-bgm.mjs and heygen-tts.mjs now print voice ids, line text, bgm paths, status messages and voice names through terminalText. audio-duck also escapes the --target value it prints. Files written to disk keep their values as they are. * fix(media-use): audio engine error lines show control characters as escapes die() in audio.mjs, wait-bgm.mjs and heygen-tts.mjs escapes each line of its message, so a broken request or meta file and HeyGen's refusal text print control characters as escapes. wait-bgm reports a broken audio_meta.json through die(). The bgm launch line, the audio_meta.json path and the heygen-tts output paths are escaped as well.
This commit is contained in:
@@ -18,7 +18,7 @@
|
||||
"files": 13
|
||||
},
|
||||
"media-use": {
|
||||
"hash": "a69a0e15504970d5",
|
||||
"hash": "476ec9020960f6f0",
|
||||
"files": 131
|
||||
},
|
||||
"remotion-to-hyperframes": {
|
||||
|
||||
@@ -58,6 +58,7 @@ import { mapWithConcurrency } from "./lib/concurrency.mjs";
|
||||
import { openAudioMeta } from "./lib/audio-meta.mjs";
|
||||
import { recordInManifest, voicePaths, writtenAssets } from "./lib/media-record.mjs";
|
||||
import { engineBgmLog, projectPath } from "./lib/project-path.mjs";
|
||||
import { terminalText } from "../../scripts/lib/terminal-text.mjs";
|
||||
|
||||
const HERE = dirname(fileURLToPath(import.meta.url));
|
||||
const argv = process.argv.slice(2);
|
||||
@@ -67,7 +68,7 @@ const flag = (name, def) => {
|
||||
};
|
||||
const has = (name) => argv.includes(`--${name}`);
|
||||
const die = (m) => {
|
||||
console.error(`✗ audio engine: ${m}`);
|
||||
console.error(`✗ audio engine: ${m}`.split("\n").map(terminalText).join("\n"));
|
||||
process.exit(1);
|
||||
};
|
||||
const r3 = (x) => Number(x.toFixed(3));
|
||||
@@ -162,7 +163,7 @@ if (only.has("tts") && lines.length) {
|
||||
ttsProvider = "recording"; // every line is the person's own recording: no TTS provider to pick
|
||||
voiceId = null;
|
||||
}
|
||||
console.error(`· tts: ${ttsProvider} · voice ${voiceId} · ${lines.length} line(s)`);
|
||||
console.error(terminalText(`· tts: ${ttsProvider} · voice ${voiceId} · ${lines.length} line(s)`));
|
||||
// A line with `audio` is the person's own recording (path inside the project), with optional
|
||||
// `words`; `speed` applies to it like to a generated voice. Returns synthesizeOne's shape.
|
||||
const useRecording = (line, abs) => {
|
||||
@@ -221,7 +222,9 @@ if (only.has("tts") && lines.length) {
|
||||
const results = await mapWithConcurrency(lines, ttsConcurrency, synthLine);
|
||||
voices = results.filter(Boolean);
|
||||
for (const v of voices)
|
||||
console.error(` voice ${v.id}: ${v.path} (${v.duration_s}s, ${v.words.length} words)`);
|
||||
console.error(
|
||||
terminalText(` voice ${v.id}: ${v.path} (${v.duration_s}s, ${v.words.length} words)`),
|
||||
);
|
||||
}
|
||||
const hasVoice = voices.length > 0;
|
||||
const totalDuration = r3(voices.reduce((a, v) => a + (v.duration_s || 0), 0));
|
||||
@@ -271,7 +274,7 @@ if (only.has("bgm")) {
|
||||
if (bgm) {
|
||||
bgmFields.bgm_provider = "heygen";
|
||||
bgmFields.bgm_mode = "retrieve";
|
||||
console.error(` bgm: ${bgm.path} (retrieve "${bgm.query}")`);
|
||||
console.error(terminalText(` bgm: ${bgm.path} (retrieve "${bgm.query}")`));
|
||||
} else {
|
||||
anomalies.push(`bgm: no music match for "${request.bgm?.query ?? ""}" — skipped`);
|
||||
}
|
||||
@@ -307,7 +310,9 @@ if (only.has("bgm")) {
|
||||
bgmFields.bgm_target_duration_s = gen.target_duration_s ?? null;
|
||||
bgmFields.bgm_seed_duration_s = gen.seed_duration_s ?? null;
|
||||
bgmFields.bgm_loop_count = gen.loop_count ?? null;
|
||||
console.error(` bgm: launched ${gen.provider} (detached, pid ${gen.pid}) → ${gen.path}`);
|
||||
console.error(
|
||||
terminalText(` bgm: launched ${gen.provider} (detached, pid ${gen.pid}) → ${gen.path}`),
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -345,7 +350,7 @@ audioMeta.write(meta);
|
||||
const written = writtenAssets({ only, lines, voices, ttsProvider, bgm, bgmFields, sfx });
|
||||
anomalies.push(...recordInManifest(hyperframesDir, written));
|
||||
|
||||
console.log(`✓ audio engine → ${outPath}`);
|
||||
console.log(terminalText(`✓ audio engine → ${outPath}`));
|
||||
console.log(` heygen: ${heygenOK ? "yes" : "no"} · ran: ${[...only].join(",")}`);
|
||||
console.log(
|
||||
` voices: ${voices.length} · bgm: ${bgm ? `${bgmFields.bgm_provider}${bgmFields.bgm_pending ? " (pending)" : ""}` : "none"} · sfx: ${sfx.length}`,
|
||||
@@ -353,5 +358,5 @@ console.log(
|
||||
console.log(` total voice duration: ${totalDuration}s`);
|
||||
if (anomalies.length) {
|
||||
console.log(`\nanomalies (non-fatal):`);
|
||||
for (const a of anomalies) console.log(` - ${a}`);
|
||||
for (const a of anomalies) console.log(terminalText(` - ${a}`));
|
||||
}
|
||||
|
||||
@@ -232,3 +232,41 @@ test("an audio_meta.json in the project that links outside it is refused and lef
|
||||
rmSync(base, { recursive: true, force: true });
|
||||
}
|
||||
});
|
||||
|
||||
test("line ids and the voice from audio_request.json print with control characters as escapes", () => {
|
||||
const dir = mkdtempSync(join(tmpdir(), "audio-escape-"));
|
||||
try {
|
||||
const id = "v\x1b[2J\x07";
|
||||
writeFileSync(
|
||||
join(dir, "audio_request.json"),
|
||||
JSON.stringify({ voice: `am_${id}`, lines: [{ id, text: "" }] }),
|
||||
);
|
||||
const run = spawnSync(
|
||||
process.execPath,
|
||||
[join(HERE, "audio.mjs"), "--hyperframes", dir, "--only", "tts"],
|
||||
{ encoding: "utf8", env: { ...process.env, HOME: dir } },
|
||||
);
|
||||
assert.equal(run.status, 0, run.stderr);
|
||||
const shown = run.stdout + run.stderr;
|
||||
assert.match(shown, /line v\\x1b\[2J\\x07: empty text/);
|
||||
for (const raw of ["\x1b", "\x07"]) assert.ok(!shown.includes(raw), JSON.stringify(shown));
|
||||
} finally {
|
||||
rmSync(dir, { recursive: true, force: true });
|
||||
}
|
||||
});
|
||||
|
||||
test("a broken audio_request.json prints its bytes with control characters as escapes", () => {
|
||||
const dir = mkdtempSync(join(tmpdir(), "audio-broken-request-"));
|
||||
try {
|
||||
writeFileSync(join(dir, "audio_request.json"), '{"lines": [ \x1b]0;x \x07 ]}');
|
||||
const run = spawnSync(process.execPath, [join(HERE, "audio.mjs"), "--hyperframes", dir], {
|
||||
encoding: "utf8",
|
||||
env: { ...process.env, HOME: dir },
|
||||
});
|
||||
assert.equal(run.status, 1, run.stdout);
|
||||
assert.match(run.stderr, /audio_request\.json parse: .*\\x1b/);
|
||||
for (const raw of ["\x1b", "\x07"]) assert.ok(!run.stderr.includes(raw), run.stderr);
|
||||
} finally {
|
||||
rmSync(dir, { recursive: true, force: true });
|
||||
}
|
||||
});
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
import { existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
|
||||
import { dirname, resolve } from "node:path";
|
||||
import { heygenAuthHeaders, heygenJSON, loadEnvFromDir } from "./lib/heygen.mjs";
|
||||
import { terminalText } from "../../scripts/lib/terminal-text.mjs";
|
||||
import { ffprobeDuration, resolveVoiceId, synthesizeOne, withWordIds } from "./lib/tts.mjs";
|
||||
|
||||
const argv = process.argv.slice(2);
|
||||
@@ -29,7 +30,7 @@ function flag(name, def) {
|
||||
return v.startsWith("--") ? true : v;
|
||||
}
|
||||
const die = (m) => {
|
||||
console.error(`✗ heygen-tts: ${m}`);
|
||||
console.error(`✗ heygen-tts: ${m}`.split("\n").map(terminalText).join("\n"));
|
||||
process.exit(1);
|
||||
};
|
||||
|
||||
@@ -77,7 +78,7 @@ if (listOnly) {
|
||||
headers: authHeaders,
|
||||
});
|
||||
for (const v of payload.data ?? payload.voices ?? []) {
|
||||
console.log(`${v.voice_id}\t${v.name}\t${v.language ?? ""}`);
|
||||
console.log(terminalText(`${v.voice_id}\t${v.name}\t${v.language ?? ""}`));
|
||||
}
|
||||
process.exit(0);
|
||||
}
|
||||
@@ -91,7 +92,7 @@ const text =
|
||||
if (!text) die("input text is empty");
|
||||
|
||||
const voiceId = await resolveVoiceId({ provider: "heygen", userVoice, lang });
|
||||
if (!userVoice) console.error(`· using voice ${voiceId}`);
|
||||
if (!userVoice) console.error(terminalText(`· using voice ${voiceId}`));
|
||||
|
||||
// ---------- synthesize (shared engine code) ----------
|
||||
const { ok, words, error } = await synthesizeOne({
|
||||
@@ -119,4 +120,6 @@ if (wordsPath) {
|
||||
|
||||
const dur = ffprobeDuration(output);
|
||||
const durStr = isFinite(dur) ? ` (${dur.toFixed(2)}s)` : "";
|
||||
console.log(`✓ ${output}${durStr}${wordCount ? ` · ${wordsPath} (${wordCount} words)` : ""}`);
|
||||
console.log(
|
||||
terminalText(`✓ ${output}${durStr}${wordCount ? ` · ${wordsPath} (${wordCount} words)` : ""}`),
|
||||
);
|
||||
|
||||
@@ -18,6 +18,7 @@ import { join, resolve } from "node:path";
|
||||
import { replaceFile } from "../../scripts/lib/manifest.mjs";
|
||||
import { recordInManifest } from "./lib/media-record.mjs";
|
||||
import { engineBgmLog, projectPath } from "./lib/project-path.mjs";
|
||||
import { terminalText } from "../../scripts/lib/terminal-text.mjs";
|
||||
|
||||
const argv = process.argv.slice(2);
|
||||
const flag = (name, def) => {
|
||||
@@ -26,7 +27,7 @@ const flag = (name, def) => {
|
||||
};
|
||||
|
||||
function die(msg) {
|
||||
console.error(`✗ wait-bgm.mjs: ${msg}`);
|
||||
console.error(`✗ wait-bgm.mjs: ${msg}`.split("\n").map(terminalText).join("\n"));
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
@@ -89,7 +90,12 @@ function writeStatus(status) {
|
||||
|
||||
if (!existsSync(audioMetaPath)) die(`audio_meta.json missing at ${audioMetaPath}`);
|
||||
|
||||
const audioMeta = JSON.parse(readFileSync(audioMetaPath, "utf8"));
|
||||
let audioMeta;
|
||||
try {
|
||||
audioMeta = JSON.parse(readFileSync(audioMetaPath, "utf8"));
|
||||
} catch (e) {
|
||||
die(`audio_meta.json parse: ${e.message}`);
|
||||
}
|
||||
// A track path that leads outside the project counts as no track.
|
||||
const bgmAbsPath = (audioMeta.bgm?.path && projectPath(hyperframesDir, audioMeta.bgm.path)) || "";
|
||||
const bgmPath = bgmAbsPath ? audioMeta.bgm.path : "";
|
||||
@@ -118,7 +124,7 @@ if (!base.enabled) {
|
||||
waited_ms: 0,
|
||||
message: "BGM not requested or disabled in audio_meta.json.",
|
||||
});
|
||||
console.log(`✓ bgm: ${status.status} (${status.message})`);
|
||||
console.log(terminalText(`✓ bgm: ${status.status} (${status.message})`));
|
||||
process.exit(0);
|
||||
}
|
||||
|
||||
@@ -137,10 +143,10 @@ while (Date.now() - started <= timeoutMs) {
|
||||
size_bytes: size,
|
||||
message: `BGM ready at ${bgmPath}.`,
|
||||
});
|
||||
console.log(`✓ bgm: ready (${bgmPath}, ${size}B)`);
|
||||
console.log(terminalText(`✓ bgm: ready (${bgmPath}, ${size}B)`));
|
||||
const generated = { path: bgmPath, type: "bgm", source: "generated", provider: base.provider };
|
||||
for (const anomaly of recordInManifest(hyperframesDir, [generated]))
|
||||
console.error(` ${anomaly}`);
|
||||
console.error(terminalText(` ${anomaly}`));
|
||||
process.exit(0);
|
||||
}
|
||||
|
||||
@@ -160,7 +166,7 @@ while (Date.now() - started <= timeoutMs) {
|
||||
message,
|
||||
error_tail: (lastFailure || lastTail).slice(-2000),
|
||||
});
|
||||
console.log(`! bgm: failed (${status.message})`);
|
||||
console.log(terminalText(`! bgm: failed (${status.message})`));
|
||||
process.exit(0);
|
||||
}
|
||||
|
||||
@@ -177,4 +183,4 @@ const status = writeStatus({
|
||||
message: `Timed out waiting for ${bgmPath}; assemble-index will skip BGM if still absent.`,
|
||||
log_tail: lastTail.slice(-2000),
|
||||
});
|
||||
console.log(`! bgm: timeout after ${status.waited_ms}ms (${bgmPath})`);
|
||||
console.log(terminalText(`! bgm: timeout after ${status.waited_ms}ms (${bgmPath})`));
|
||||
|
||||
@@ -253,3 +253,45 @@ test("a pid whose log is not the engine's own is dropped with the log", () => {
|
||||
rmSync(dir, { recursive: true, force: true });
|
||||
}
|
||||
});
|
||||
|
||||
test("a ready track's path from audio_meta.json prints with control characters as escapes", () => {
|
||||
const dir = mkdtempSync(join(tmpdir(), "mu-wait-bgm-escape-"));
|
||||
try {
|
||||
const track = "assets/bgm/x\x1b[2J\x07.wav";
|
||||
mkdirSync(join(dir, "assets/bgm"), { recursive: true });
|
||||
writeFileSync(join(dir, track), "RIFF");
|
||||
writeFileSync(
|
||||
join(dir, "audio_meta.json"),
|
||||
JSON.stringify({ bgm: { path: track }, bgm_pending: true }),
|
||||
);
|
||||
const script = new URL("./wait-bgm.mjs", import.meta.url).pathname;
|
||||
const args = ["--audio-meta", join(dir, "audio_meta.json"), "--hyperframes", dir];
|
||||
const run = spawnSync(process.execPath, [script, ...args, "--timeout-ms", "0"], {
|
||||
encoding: "utf8",
|
||||
});
|
||||
assert.equal(run.status, 0, run.stderr);
|
||||
assert.match(run.stdout, /ready \(assets\/bgm\/x\\x1b\[2J\\x07\.wav/);
|
||||
for (const raw of ["\x1b", "\x07"]) assert.ok(!run.stdout.includes(raw), run.stdout);
|
||||
const status = JSON.parse(readFileSync(join(dir, "bgm_status.json"), "utf8"));
|
||||
assert.equal(status.path, track);
|
||||
} finally {
|
||||
rmSync(dir, { recursive: true, force: true });
|
||||
}
|
||||
});
|
||||
|
||||
test("a broken audio_meta.json prints its bytes with control characters as escapes", () => {
|
||||
const dir = mkdtempSync(join(tmpdir(), "mu-wait-bgm-broken-"));
|
||||
try {
|
||||
writeFileSync(join(dir, "audio_meta.json"), '{"bgm": [ \x1b]0;x \x07 ]}');
|
||||
const script = new URL("./wait-bgm.mjs", import.meta.url).pathname;
|
||||
const args = ["--audio-meta", join(dir, "audio_meta.json"), "--hyperframes", dir];
|
||||
const run = spawnSync(process.execPath, [script, ...args, "--timeout-ms", "0"], {
|
||||
encoding: "utf8",
|
||||
});
|
||||
assert.equal(run.status, 1, run.stdout);
|
||||
assert.match(run.stderr, /audio_meta\.json parse: .*\\x1b/);
|
||||
for (const raw of ["\x1b", "\x07"]) assert.ok(!run.stderr.includes(raw), run.stderr);
|
||||
} finally {
|
||||
rmSync(dir, { recursive: true, force: true });
|
||||
}
|
||||
});
|
||||
|
||||
@@ -5,6 +5,7 @@ import { resolve } from "node:path";
|
||||
import { parseArgs } from "node:util";
|
||||
import { duckKeyframes, duckLane, speechSpans } from "./lib/duck.mjs";
|
||||
import { track } from "./lib/telemetry.mjs";
|
||||
import { terminalText } from "./lib/terminal-text.mjs";
|
||||
|
||||
const { values: args } = parseArgs({
|
||||
options: {
|
||||
@@ -51,7 +52,7 @@ try {
|
||||
await track("media_use_duck", { sequential: !!args.sequential });
|
||||
} catch (err) {
|
||||
if (args.json) console.log(JSON.stringify({ ok: false, error: err.message }));
|
||||
else console.error(`error: ${err.message}`);
|
||||
else console.error(`error: ${err.message}`.split("\n").map(terminalText).join("\n"));
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
@@ -88,7 +89,9 @@ function run() {
|
||||
return;
|
||||
}
|
||||
|
||||
console.log(`<!-- auto-duck: ${target} under narration; add to its <audio> element -->`);
|
||||
console.log(
|
||||
terminalText(`<!-- auto-duck: ${target} under narration; add to its <audio> element -->`),
|
||||
);
|
||||
console.log(`data-automation='${JSON.stringify(lane)}'`);
|
||||
}
|
||||
|
||||
|
||||
@@ -12,6 +12,7 @@ import {
|
||||
applyErrorDiffusionRgba,
|
||||
errorDiffusionBufferLength,
|
||||
} from "./lib/error-diffusion.mjs";
|
||||
import { terminalText } from "./lib/terminal-text.mjs";
|
||||
|
||||
const IMAGE_EXTENSIONS = new Set([".png", ".jpg", ".jpeg", ".webp", ".bmp", ".tif", ".tiff"]);
|
||||
const OUTPUT_IMAGE_EXTENSIONS = new Set([".png", ".jpg", ".jpeg", ".webp"]);
|
||||
@@ -59,13 +60,13 @@ try {
|
||||
const result = await run();
|
||||
if (args.json) console.log(JSON.stringify({ ok: true, ...result }));
|
||||
else {
|
||||
console.log(`dithered ${result.input} -> ${result.out} (${result.algorithm})`);
|
||||
console.log(`next: resolve --from ${result.out} --type ${result.type}`);
|
||||
console.log(terminalText(`dithered ${result.input} -> ${result.out} (${result.algorithm})`));
|
||||
console.log(terminalText(`next: resolve --from ${result.out} --type ${result.type}`));
|
||||
}
|
||||
} catch (error) {
|
||||
const message = error instanceof Error ? error.message : String(error);
|
||||
if (args.json) console.log(JSON.stringify({ ok: false, error: message }));
|
||||
else console.error(`error: ${message}`);
|
||||
else console.error(`error: ${message}`.split("\n").map(terminalText).join("\n"));
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { strict as assert } from "node:assert";
|
||||
import { execFileSync } from "node:child_process";
|
||||
import { execFileSync, spawnSync } from "node:child_process";
|
||||
import { mkdirSync, mkdtempSync, rmSync, writeFileSync } from "node:fs";
|
||||
import { tmpdir } from "node:os";
|
||||
import { join } from "node:path";
|
||||
@@ -8,6 +8,9 @@ import { test } from "node:test";
|
||||
const scriptsDir = new URL(".", import.meta.url).pathname;
|
||||
const HOSTILE = "x\x1b]52;c;aGk=\x07\x1b[2J";
|
||||
const SHOWN = "x\\x1b]52;c;aGk=\\x07\\x1b[2J";
|
||||
const HAS_FFMPEG =
|
||||
spawnSync("ffmpeg", ["-version"], { stdio: "ignore" }).status === 0 &&
|
||||
spawnSync("ffprobe", ["-version"], { stdio: "ignore" }).status === 0;
|
||||
|
||||
function run(script, args, home) {
|
||||
return execFileSync(process.execPath, [join(scriptsDir, script), ...args], {
|
||||
@@ -106,3 +109,87 @@ test("a failing recipe command prints its error with control characters as visib
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
function failingStderr(script, args) {
|
||||
const result = spawnSync(process.execPath, [join(scriptsDir, script), ...args], {
|
||||
encoding: "utf8",
|
||||
});
|
||||
assert.equal(result.status === 0, false, result.stdout);
|
||||
return result.stderr;
|
||||
}
|
||||
|
||||
function withTempDir(fn) {
|
||||
const dir = mkdtempSync(join(tmpdir(), "media-use-script-output-"));
|
||||
try {
|
||||
fn(dir);
|
||||
} finally {
|
||||
rmSync(dir, { recursive: true, force: true });
|
||||
}
|
||||
}
|
||||
|
||||
test("audio-duck prints a voice id from audio_meta.json with control characters as escapes", () => {
|
||||
withTempDir((dir) => {
|
||||
const meta = join(dir, "audio_meta.json");
|
||||
const words = [{ text: "hi", start: 0, end: 0.5 }];
|
||||
writeFileSync(meta, JSON.stringify({ voices: [{ id: HOSTILE, words }] }));
|
||||
const args = ["--meta", meta, "--target", "#bgm", "--offsets", "other=0"];
|
||||
assertEscaped(failingStderr("audio-duck.mjs", args));
|
||||
const json = JSON.parse(
|
||||
spawnSync(process.execPath, [join(scriptsDir, "audio-duck.mjs"), ...args, "--json"], {
|
||||
encoding: "utf8",
|
||||
}).stdout,
|
||||
);
|
||||
assert.equal(json.error, `--offsets is missing voice "${HOSTILE}"`);
|
||||
});
|
||||
});
|
||||
|
||||
test("audio-duck and transcript-cut print a broken JSON file's bytes as escapes", () => {
|
||||
withTempDir((dir) => {
|
||||
const broken = join(dir, "broken.json");
|
||||
writeFileSync(broken, `{"words": ${HOSTILE}}`);
|
||||
for (const shown of [
|
||||
failingStderr("audio-duck.mjs", ["--meta", broken, "--target", "#bgm"]),
|
||||
failingStderr("transcript-cut.mjs", ["--transcript", broken, "--plan"]),
|
||||
]) {
|
||||
assert.match(shown, /x\\x1b\]52/);
|
||||
for (const raw of ["\x1b", "\x07"]) assert.ok(!shown.includes(raw), JSON.stringify(shown));
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
test("transcribe and dither print a missing input path with control characters as escapes", () => {
|
||||
withTempDir((dir) => {
|
||||
const missing = join(dir, `${HOSTILE}.wav`);
|
||||
assertEscaped(failingStderr("transcribe.mjs", ["--input", missing]));
|
||||
assertEscaped(failingStderr("dither.mjs", ["--input", missing, "--out", join(dir, "o.png")]));
|
||||
});
|
||||
});
|
||||
|
||||
test(
|
||||
"transcript-cut and dither print output paths with control characters as escapes",
|
||||
{ skip: !HAS_FFMPEG },
|
||||
() => {
|
||||
withTempDir((dir) => {
|
||||
const tone = join(dir, "tone.wav");
|
||||
const image = join(dir, "frame.png");
|
||||
const lavfi = ["-y", "-loglevel", "error", "-f", "lavfi", "-i"];
|
||||
execFileSync("ffmpeg", [...lavfi, "sine=frequency=440:duration=2", tone]);
|
||||
execFileSync("ffmpeg", [...lavfi, "color=size=8x8", "-frames:v", "1", image]);
|
||||
const transcript = join(dir, "words.json");
|
||||
writeFileSync(transcript, JSON.stringify([{ text: "hi", start: 0, end: 1 }]));
|
||||
const cut = ["--input", tone, "--transcript", transcript, "--remove", "1-2"];
|
||||
assertEscaped(run("transcript-cut.mjs", [...cut, "--out", join(dir, `${HOSTILE}.wav`)], dir));
|
||||
assertEscaped(
|
||||
run("dither.mjs", ["--input", image, "--out", join(dir, `${HOSTILE}.png`)], dir),
|
||||
);
|
||||
});
|
||||
},
|
||||
);
|
||||
|
||||
test("audio-duck prints the --target value with control characters as escapes", () => {
|
||||
withTempDir((dir) => {
|
||||
const meta = join(dir, "audio_meta.json");
|
||||
writeFileSync(meta, JSON.stringify({ words: [{ text: "hi", start: 0, end: 0.5 }] }));
|
||||
assertEscaped(run("audio-duck.mjs", ["--meta", meta, "--target", HOSTILE], dir));
|
||||
});
|
||||
});
|
||||
|
||||
@@ -17,6 +17,7 @@ import { parseArgs, stripVTControlCharacters } from "node:util";
|
||||
import { mergeTokensToWords } from "./lib/parakeet-words.mjs";
|
||||
import { track } from "./lib/telemetry.mjs";
|
||||
import { resolveNpxInvocation } from "./lib/npx-sync.mjs";
|
||||
import { terminalText } from "./lib/terminal-text.mjs";
|
||||
|
||||
// The DEFAULT local transcription path. Prefers NVIDIA Parakeet-TDT via
|
||||
// parakeet-mlx, which beats whisper.cpp on the Open ASR Leaderboard (~6.05% vs
|
||||
@@ -61,7 +62,7 @@ if (!args.input) {
|
||||
}
|
||||
const inputPath = resolve(args.input);
|
||||
if (!existsSync(inputPath)) {
|
||||
console.error(`error: input not found: ${inputPath}`);
|
||||
console.error(terminalText(`error: input not found: ${inputPath}`));
|
||||
process.exit(2);
|
||||
}
|
||||
const outPath = resolve(
|
||||
@@ -104,7 +105,9 @@ function report(engine, wordCount) {
|
||||
if (args.json) console.log(JSON.stringify({ ok: true, out: outPath, engine, words: wordCount }));
|
||||
else
|
||||
console.log(
|
||||
`transcribed ${basename(inputPath)} -> ${outPath}${wordCount != null ? ` (${wordCount} words,` : " ("}${engine})`,
|
||||
terminalText(
|
||||
`transcribed ${basename(inputPath)} -> ${outPath}${wordCount != null ? ` (${wordCount} words,` : " ("}${engine})`,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -206,6 +209,9 @@ try {
|
||||
await track("media_use_transcribe", { engine });
|
||||
} catch (err) {
|
||||
if (args.json) console.log(JSON.stringify({ ok: false, error: err.message }));
|
||||
else console.error(`error: transcription failed: ${err.message}`);
|
||||
else
|
||||
console.error(
|
||||
`error: transcription failed: ${err.message}`.split("\n").map(terminalText).join("\n"),
|
||||
);
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
@@ -9,6 +9,7 @@ import { parseArgs } from "node:util";
|
||||
import { compileCutList } from "./lib/cutlist.mjs";
|
||||
import { fadeFilterFor } from "./lib/transcriptCutFade.mjs";
|
||||
import { track } from "./lib/telemetry.mjs";
|
||||
import { terminalText } from "./lib/terminal-text.mjs";
|
||||
|
||||
const { values: args } = parseArgs({
|
||||
options: {
|
||||
@@ -61,7 +62,7 @@ try {
|
||||
});
|
||||
} catch (err) {
|
||||
if (args.json) console.log(JSON.stringify({ ok: false, error: err.message }));
|
||||
else console.error(`error: ${err.message}`);
|
||||
else console.error(`error: ${err.message}`.split("\n").map(terminalText).join("\n"));
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
@@ -175,11 +176,13 @@ function run() {
|
||||
}
|
||||
|
||||
console.log(
|
||||
`cut ${inputPath} -> ${outPath} (${segments.length} segments, ${fmt(keptSeconds)}s kept of ${fmt(
|
||||
totalSeconds,
|
||||
)}s)`,
|
||||
terminalText(
|
||||
`cut ${inputPath} -> ${outPath} (${segments.length} segments, ${fmt(keptSeconds)}s kept of ${fmt(
|
||||
totalSeconds,
|
||||
)}s)`,
|
||||
),
|
||||
);
|
||||
console.log(`next: resolve --from ${outPath} --type <type>`);
|
||||
console.log(terminalText(`next: resolve --from ${outPath} --type <type>`));
|
||||
}
|
||||
|
||||
function cutSegment(inputPath, segment, outPath, copy, fade) {
|
||||
|
||||
Reference in New Issue
Block a user