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