refactor(tts): replace string interpolation with path.join()
This commit is contained in:
parent
7bf8951b62
commit
32f9dd5495
1 changed files with 9 additions and 6 deletions
15
tts.ts
15
tts.ts
|
|
@ -1,5 +1,6 @@
|
||||||
import fs from "node:fs/promises";
|
import fs from "node:fs/promises";
|
||||||
import os from "node:os";
|
import os from "node:os";
|
||||||
|
import path from "node:path";
|
||||||
import process from "node:process";
|
import process from "node:process";
|
||||||
import { createInterface } from "node:readline";
|
import { createInterface } from "node:readline";
|
||||||
import { parseArgs } from "node:util";
|
import { parseArgs } from "node:util";
|
||||||
|
|
@ -60,13 +61,13 @@ async function main() {
|
||||||
}
|
}
|
||||||
|
|
||||||
const home = os.homedir();
|
const home = os.homedir();
|
||||||
const cwd = `${home}/.ttsc/`;
|
const cwd = path.join(home, ".ttsc");
|
||||||
|
|
||||||
const wavs = await Array.fromAsync(fs.glob(`${cwd}*.wav`));
|
const wavs = await Array.fromAsync(fs.glob(path.join(cwd, "*.wav")));
|
||||||
await execa({ cwd, shell: true, reject: false })`rm ${wavs}`;
|
await execa({ cwd, shell: true, reject: false })`rm ${wavs}`;
|
||||||
|
|
||||||
if (edit) {
|
if (edit) {
|
||||||
const file = `${cwd}input.txt`;
|
const file = path.join(cwd, "input.txt");
|
||||||
await fs.writeFile(file, input);
|
await fs.writeFile(file, input);
|
||||||
const editor = process.env.EDITOR || "nano";
|
const editor = process.env.EDITOR || "nano";
|
||||||
await execa({
|
await execa({
|
||||||
|
|
@ -124,7 +125,7 @@ async function main() {
|
||||||
|
|
||||||
const [columns] = process.stdout.getWindowSize();
|
const [columns] = process.stdout.getWindowSize();
|
||||||
const text = wrapAnsi(info.text, columns);
|
const text = wrapAnsi(info.text, columns);
|
||||||
const file = `${home}/.ttsc/${info.file}.wav`;
|
const file = path.join(cwd, `${info.file}.wav`);
|
||||||
|
|
||||||
if (wait) {
|
if (wait) {
|
||||||
process.stdout.write(".");
|
process.stdout.write(".");
|
||||||
|
|
@ -148,7 +149,7 @@ async function main() {
|
||||||
|
|
||||||
console.log(chalk.yellow(`Combining audio with sox...\n`));
|
console.log(chalk.yellow(`Combining audio with sox...\n`));
|
||||||
try {
|
try {
|
||||||
const wavs = await Array.fromAsync(fs.glob(`${cwd}*.wav`));
|
const wavs = await Array.fromAsync(fs.glob(path.join(cwd, "*.wav")));
|
||||||
await execa({ cwd, shell: true })`sox ${wavs} output.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") {
|
||||||
|
|
@ -163,7 +164,9 @@ async function main() {
|
||||||
const [columns] = process.stdout.getWindowSize();
|
const [columns] = process.stdout.getWindowSize();
|
||||||
console.log(wrapAnsi(input, columns));
|
console.log(wrapAnsi(input, columns));
|
||||||
|
|
||||||
console.log(chalk.green(`Playing audio from ${cwd}output.wav`));
|
console.log(
|
||||||
|
chalk.green(`Playing audio from ${path.join(cwd, "output.wav")}`),
|
||||||
|
);
|
||||||
await execa({
|
await execa({
|
||||||
cwd,
|
cwd,
|
||||||
stdin: "ignore",
|
stdin: "ignore",
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue