fix(tts): --edit file handling and file globbing

This commit is contained in:
mitchell 2026-06-09 20:18:10 -04:00
parent 574ebdc8a1
commit 7bf8951b62

18
tts.ts
View file

@ -62,18 +62,19 @@ async function main() {
const home = os.homedir();
const cwd = `${home}/.ttsc/`;
await execa({ cwd, shell: true, reject: false })`rm *.wav`;
const wavs = await Array.fromAsync(fs.glob(`${cwd}*.wav`));
await execa({ cwd, shell: true, reject: false })`rm ${wavs}`;
if (edit) {
const file = await fs.open(`${cwd}input.txt`, "w+");
await file.writeFile(input);
const file = `${cwd}input.txt`;
await fs.writeFile(file, input);
const editor = process.env.EDITOR || "nano";
await execa({
cwd,
stdin: "inherit",
stdout: "inherit",
})`${editor} ${cwd}input.txt`;
input = await file.readFile("utf8");
await file.close();
})`${editor} input.txt`;
input = await fs.readFile(file, "utf8");
}
console.log(chalk.blue("Welcome to TTSC!"));
@ -100,7 +101,7 @@ async function main() {
}
let first = true;
const rl = createInterface({ input: koko.stdout, crlfDelay: Infinity });
const rl = createInterface({ input: koko.stdout });
for await (const line of rl) {
const trimmed = line.trim();
@ -147,7 +148,8 @@ async function main() {
console.log(chalk.yellow(`Combining audio with sox...\n`));
try {
await execa({ cwd, shell: true })`sox *.wav output.wav`;
const wavs = await Array.fromAsync(fs.glob(`${cwd}*.wav`));
await execa({ cwd, shell: true })`sox ${wavs} output.wav`;
} catch (err) {
if (err instanceof Object && "code" in err && err.code === "ENOENT") {
console.error("Sox not found. Unable to combine outputs.");