feat(tts): add processing duration timing

This commit is contained in:
mitchell 2026-05-02 22:22:09 -04:00
parent f5c8bdfe99
commit 57acb09a18

22
tts.ts
View file

@ -3,6 +3,8 @@ import { parseArgs } from "node:util";
import { $, which } from "bun";
import chalk from "chalk";
const start = Date.now();
const { values: args } = parseArgs({
args: Bun.argv,
options: {
@ -43,9 +45,14 @@ const koko = Bun.spawn({
});
if (!wait) {
koko.exited.then(() => console.log(chalk.green("\nProcessing finished.")));
koko.exited.then(() => {
const stop = Date.now();
const duration = ((stop - start) / 1000).toFixed(2);
console.log(chalk.green(`\nProcessing finished: ${duration}s`));
});
}
let first = true;
const decoder = new TextDecoder();
for await (const line of koko.stdout) {
const decoded = decoder.decode(line).trim();
@ -58,9 +65,16 @@ for await (const line of koko.stdout) {
continue;
}
if (first) {
first = false;
const stop = Date.now();
const duration = ((stop - start) / 1000).toFixed(2);
console.log(chalk.blue(`\nTime-to-audio: ${duration}s`));
}
for (const info of infos) {
const file = `${home}/.ttsc/${info.file}.wav`;
console.log(`\n${chalk.blue(file)}:\n${info.text}`);
console.log(`\n${chalk.blue(file)}:\n${info.text}\n`);
if (!wait) {
await Bun.spawn({
@ -77,7 +91,9 @@ for await (const line of koko.stdout) {
await koko.exited;
if (!wait) process.exit();
console.log(chalk.green("\nProcessing finished."));
const stop = Date.now();
const duration = ((stop - start) / 1000).toFixed(2);
console.log(chalk.green(`\nProcessing finished: ${duration}s`));
console.log(chalk.yellow(`Combining audio with sox...`));
if (which("sox")) {