refactor(tts): make cjs compatible and add sea config

This commit is contained in:
mitchell 2026-06-08 15:17:07 -04:00
parent 3235a08633
commit 39cb573619
2 changed files with 135 additions and 122 deletions

6
sea-config-tts.json Normal file
View file

@ -0,0 +1,6 @@
{
"main": "dist/tts.js",
"output": "dist/ttsc",
"useCodeCache": true,
"disableExperimentalSEAWarning": true
}

13
tts.ts
View file

@ -8,10 +8,11 @@ import { execa } from "execa";
import { Window } from "happy-dom"; import { Window } from "happy-dom";
import wrapAnsi from "wrap-ansi"; import wrapAnsi from "wrap-ansi";
async function main() {
const start = Date.now(); const start = Date.now();
const { values: args } = parseArgs({ const { values: args } = parseArgs({
args: process.argv, args: process.argv.slice(2),
options: { options: {
wait: { type: "boolean" }, wait: { type: "boolean" },
w: { type: "boolean" }, w: { type: "boolean" },
@ -19,7 +20,7 @@ const { values: args } = parseArgs({
u: { type: "string" }, u: { type: "string" },
}, },
strict: true, strict: true,
allowPositionals: true, allowPositionals: false,
}); });
const wait = args.wait ?? args.w; const wait = args.wait ?? args.w;
@ -67,7 +68,7 @@ console.log(
const koko = execa({ const koko = execa({
cwd, cwd,
input: Buffer.from(input), // execa v6+ uses 'input'. Use 'stdin' for v5 input,
stdout: "pipe", stdout: "pipe",
stderr: "inherit", stderr: "inherit",
})`uv run -- python -u main.py`; })`uv run -- python -u main.py`;
@ -145,3 +146,9 @@ await execa({
stdout: "inherit", stdout: "inherit",
stderr: "inherit", stderr: "inherit",
})`mpv --pause output.wav`; })`mpv --pause output.wav`;
}
main().catch((err) => {
console.error(err);
process.exit(1);
});