From 7bf8951b620e0e47e6571c34b5196ab07eeb02cd Mon Sep 17 00:00:00 2001 From: mitchell Date: Tue, 9 Jun 2026 20:18:10 -0400 Subject: [PATCH] fix(tts): --edit file handling and file globbing --- tts.ts | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/tts.ts b/tts.ts index 976da80..8af1144 100644 --- a/tts.ts +++ b/tts.ts @@ -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.");