feat(tts): add processing duration timing
This commit is contained in:
parent
f5c8bdfe99
commit
57acb09a18
1 changed files with 19 additions and 3 deletions
22
tts.ts
22
tts.ts
|
|
@ -3,6 +3,8 @@ import { parseArgs } from "node:util";
|
||||||
import { $, which } from "bun";
|
import { $, which } from "bun";
|
||||||
import chalk from "chalk";
|
import chalk from "chalk";
|
||||||
|
|
||||||
|
const start = Date.now();
|
||||||
|
|
||||||
const { values: args } = parseArgs({
|
const { values: args } = parseArgs({
|
||||||
args: Bun.argv,
|
args: Bun.argv,
|
||||||
options: {
|
options: {
|
||||||
|
|
@ -43,9 +45,14 @@ const koko = Bun.spawn({
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!wait) {
|
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();
|
const decoder = new TextDecoder();
|
||||||
for await (const line of koko.stdout) {
|
for await (const line of koko.stdout) {
|
||||||
const decoded = decoder.decode(line).trim();
|
const decoded = decoder.decode(line).trim();
|
||||||
|
|
@ -58,9 +65,16 @@ for await (const line of koko.stdout) {
|
||||||
continue;
|
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) {
|
for (const info of infos) {
|
||||||
const file = `${home}/.ttsc/${info.file}.wav`;
|
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) {
|
if (!wait) {
|
||||||
await Bun.spawn({
|
await Bun.spawn({
|
||||||
|
|
@ -77,7 +91,9 @@ for await (const line of koko.stdout) {
|
||||||
await koko.exited;
|
await koko.exited;
|
||||||
if (!wait) process.exit();
|
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...`));
|
console.log(chalk.yellow(`Combining audio with sox...`));
|
||||||
if (which("sox")) {
|
if (which("sox")) {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue