@storyteller-platform/ghost-story 0.1.5 → 0.1.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/cli/bin.cjs CHANGED
@@ -24,6 +24,7 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
24
24
  ));
25
25
  var import_zli = require("@robingenz/zli");
26
26
  var import_cli_progress = require("cli-progress");
27
+ var import_fs_extra = require("fs-extra");
27
28
  var import_zod = require("zod");
28
29
  var import_config = require("./config.cjs");
29
30
  var import_install = require("./install.cjs");
@@ -194,7 +195,16 @@ const transcribeCommand = (0, import_zli.defineCommand)({
194
195
  import_cli_progress.Presets.shades_classic
195
196
  );
196
197
  try {
197
- const [inputPath] = args;
198
+ let [inputPath] = args;
199
+ const path = await import("node:path");
200
+ inputPath = path.resolve(process.cwd(), inputPath);
201
+ let outputPath = options.output ? path.resolve(process.cwd(), options.output) : void 0;
202
+ if (outputPath && !path.extname(outputPath)) {
203
+ outputPath = `${outputPath}.json`;
204
+ }
205
+ if (outputPath) {
206
+ (0, import_fs_extra.ensureDirSync)(path.dirname(outputPath));
207
+ }
198
208
  const result = await recognize(inputPath, {
199
209
  engine: options.engine,
200
210
  language: options.language,
@@ -219,14 +229,14 @@ const transcribeCommand = (0, import_zli.defineCommand)({
219
229
  }
220
230
  }
221
231
  });
222
- if (!options.output) {
232
+ if (!outputPath) {
223
233
  console.log(JSON.stringify(result, null, 2));
224
234
  return;
225
235
  }
226
236
  const { writeFile } = await import("node:fs/promises");
227
- await writeFile(options.output, JSON.stringify(result, null, 2));
237
+ await writeFile(outputPath, JSON.stringify(result, null, 2));
228
238
  console.log(`
229
- Transcription written to ${options.output}`);
239
+ Transcription written to ${outputPath}`);
230
240
  } finally {
231
241
  if (!options.noProgress) {
232
242
  progressBar.stop();
package/dist/cli/bin.js CHANGED
@@ -6,6 +6,7 @@ import {
6
6
  processConfig
7
7
  } from "@robingenz/zli";
8
8
  import { Presets, SingleBar } from "cli-progress";
9
+ import { ensureDirSync } from "fs-extra";
9
10
  import { z } from "zod";
10
11
  import {
11
12
  BUILD_VARIANTS,
@@ -193,7 +194,16 @@ const transcribeCommand = defineCommand({
193
194
  Presets.shades_classic
194
195
  );
195
196
  try {
196
- const [inputPath] = args;
197
+ let [inputPath] = args;
198
+ const path = await import("node:path");
199
+ inputPath = path.resolve(process.cwd(), inputPath);
200
+ let outputPath = options.output ? path.resolve(process.cwd(), options.output) : void 0;
201
+ if (outputPath && !path.extname(outputPath)) {
202
+ outputPath = `${outputPath}.json`;
203
+ }
204
+ if (outputPath) {
205
+ ensureDirSync(path.dirname(outputPath));
206
+ }
197
207
  const result = await recognize(inputPath, {
198
208
  engine: options.engine,
199
209
  language: options.language,
@@ -218,14 +228,14 @@ const transcribeCommand = defineCommand({
218
228
  }
219
229
  }
220
230
  });
221
- if (!options.output) {
231
+ if (!outputPath) {
222
232
  console.log(JSON.stringify(result, null, 2));
223
233
  return;
224
234
  }
225
235
  const { writeFile } = await import("node:fs/promises");
226
- await writeFile(options.output, JSON.stringify(result, null, 2));
236
+ await writeFile(outputPath, JSON.stringify(result, null, 2));
227
237
  console.log(`
228
- Transcription written to ${options.output}`);
238
+ Transcription written to ${outputPath}`);
229
239
  } finally {
230
240
  if (!options.noProgress) {
231
241
  progressBar.stop();
@@ -43,6 +43,8 @@ var import_node_os = __toESM(require("node:os"), 1);
43
43
  var import_node_path = __toESM(require("node:path"), 1);
44
44
  var import_promises2 = require("node:stream/promises");
45
45
  var import_node_zlib = require("node:zlib");
46
+ var import_chalk = __toESM(require("chalk"), 1);
47
+ var import_cli_progress = require("cli-progress");
46
48
  var import_tar = require("tar");
47
49
  var import_config = require("./config.cjs");
48
50
  async function downloadFile(options) {
@@ -68,9 +70,27 @@ async function downloadFile(options) {
68
70
  }
69
71
  await (0, import_promises.mkdir)(import_node_path.default.dirname(destPath), { recursive: true });
70
72
  const fileStream = (0, import_node_fs.createWriteStream)(destPath);
73
+ const progressBar = new import_cli_progress.SingleBar(
74
+ {
75
+ etaBuffer: 2,
76
+ hideCursor: null,
77
+ noTTYOutput: !process.stderr.isTTY,
78
+ autopadding: true,
79
+ format: `${import_chalk.default.yellow("{bar}")} | {percentage}% | {current}/{sum} MB | ({speed} MB/s)`
80
+ },
81
+ import_cli_progress.Presets.shades_classic
82
+ );
71
83
  const reader = response.body.getReader();
72
84
  let downloaded = 0;
73
- let lastPrinted = 0;
85
+ let lastTime = Date.now();
86
+ let lastDownloaded = 0;
87
+ if (printOutput) {
88
+ progressBar.start(totalSize, 0, {
89
+ current: "0 MB",
90
+ sum: `${(totalSize / 1024 / 1024).toFixed(2)} MB`,
91
+ speed: 0
92
+ });
93
+ }
74
94
  try {
75
95
  while (true) {
76
96
  const { done, value } = await reader.read();
@@ -81,18 +101,25 @@ async function downloadFile(options) {
81
101
  fileStream.write(value);
82
102
  onProgress == null ? void 0 : onProgress(downloaded, totalSize);
83
103
  if (printOutput && totalSize > 0) {
84
- const shouldPrint = downloaded - lastPrinted > 10 * 1024 * 1024 || downloaded === totalSize;
104
+ const deltaTime = Date.now() - lastTime;
105
+ const shouldPrint = deltaTime > 1e3 || downloaded === totalSize;
85
106
  if (shouldPrint) {
86
- const percent = (downloaded / totalSize * 100).toFixed(1);
87
- console.log(
88
- ` ${(downloaded / 1024 / 1024).toFixed(1)} MB / ${(totalSize / 1024 / 1024).toFixed(1)} MB (${percent}%)`
89
- );
90
- lastPrinted = downloaded;
107
+ const speed = (downloaded - lastDownloaded) / 1024 / 1024 / (deltaTime / 1e3);
108
+ lastTime = Date.now();
109
+ lastDownloaded = downloaded;
110
+ progressBar.update(downloaded, {
111
+ current: (downloaded / 1024 / 1024).toFixed(2),
112
+ sum: (totalSize / 1024 / 1024).toFixed(2),
113
+ speed: speed.toFixed(2)
114
+ });
91
115
  }
92
116
  }
93
117
  }
94
118
  } finally {
95
119
  fileStream.end();
120
+ if (printOutput) {
121
+ progressBar.stop();
122
+ }
96
123
  }
97
124
  await new Promise((resolve, reject) => {
98
125
  fileStream.on("finish", resolve);
@@ -9,6 +9,8 @@ import os from "node:os";
9
9
  import path from "node:path";
10
10
  import { pipeline } from "node:stream/promises";
11
11
  import { createGunzip } from "node:zlib";
12
+ import chalk from "chalk";
13
+ import { Presets, SingleBar } from "cli-progress";
12
14
  import { extract } from "tar";
13
15
  import {
14
16
  MODEL_SIZES,
@@ -52,9 +54,27 @@ async function downloadFile(options) {
52
54
  }
53
55
  await mkdir(path.dirname(destPath), { recursive: true });
54
56
  const fileStream = createWriteStream(destPath);
57
+ const progressBar = new SingleBar(
58
+ {
59
+ etaBuffer: 2,
60
+ hideCursor: null,
61
+ noTTYOutput: !process.stderr.isTTY,
62
+ autopadding: true,
63
+ format: `${chalk.yellow("{bar}")} | {percentage}% | {current}/{sum} MB | ({speed} MB/s)`
64
+ },
65
+ Presets.shades_classic
66
+ );
55
67
  const reader = response.body.getReader();
56
68
  let downloaded = 0;
57
- let lastPrinted = 0;
69
+ let lastTime = Date.now();
70
+ let lastDownloaded = 0;
71
+ if (printOutput) {
72
+ progressBar.start(totalSize, 0, {
73
+ current: "0 MB",
74
+ sum: `${(totalSize / 1024 / 1024).toFixed(2)} MB`,
75
+ speed: 0
76
+ });
77
+ }
58
78
  try {
59
79
  while (true) {
60
80
  const { done, value } = await reader.read();
@@ -65,18 +85,25 @@ async function downloadFile(options) {
65
85
  fileStream.write(value);
66
86
  onProgress == null ? void 0 : onProgress(downloaded, totalSize);
67
87
  if (printOutput && totalSize > 0) {
68
- const shouldPrint = downloaded - lastPrinted > 10 * 1024 * 1024 || downloaded === totalSize;
88
+ const deltaTime = Date.now() - lastTime;
89
+ const shouldPrint = deltaTime > 1e3 || downloaded === totalSize;
69
90
  if (shouldPrint) {
70
- const percent = (downloaded / totalSize * 100).toFixed(1);
71
- console.log(
72
- ` ${(downloaded / 1024 / 1024).toFixed(1)} MB / ${(totalSize / 1024 / 1024).toFixed(1)} MB (${percent}%)`
73
- );
74
- lastPrinted = downloaded;
91
+ const speed = (downloaded - lastDownloaded) / 1024 / 1024 / (deltaTime / 1e3);
92
+ lastTime = Date.now();
93
+ lastDownloaded = downloaded;
94
+ progressBar.update(downloaded, {
95
+ current: (downloaded / 1024 / 1024).toFixed(2),
96
+ sum: (totalSize / 1024 / 1024).toFixed(2),
97
+ speed: speed.toFixed(2)
98
+ });
75
99
  }
76
100
  }
77
101
  }
78
102
  } finally {
79
103
  fileStream.end();
104
+ if (printOutput) {
105
+ progressBar.stop();
106
+ }
80
107
  }
81
108
  await new Promise((resolve, reject) => {
82
109
  fileStream.on("finish", resolve);
@@ -319,7 +319,7 @@ function buildTranscribeArgs(options) {
319
319
  "--print-progress",
320
320
  options.language ? ["--language", options.language.toLowerCase()] : null,
321
321
  options.flashAttention ? ["--flash-attn"] : null,
322
- options.suppressNonSpeechTokens ? ["--suppress-nst", "--no-prints"] : null,
322
+ options.suppressNonSpeechTokens ? ["--suppress-nst"] : null,
323
323
  ["--processors", String(options.processors)],
324
324
  ["--threads", String(options.threads)]
325
325
  ];
@@ -298,7 +298,7 @@ function buildTranscribeArgs(options) {
298
298
  "--print-progress",
299
299
  options.language ? ["--language", options.language.toLowerCase()] : null,
300
300
  options.flashAttention ? ["--flash-attn"] : null,
301
- options.suppressNonSpeechTokens ? ["--suppress-nst", "--no-prints"] : null,
301
+ options.suppressNonSpeechTokens ? ["--suppress-nst"] : null,
302
302
  ["--processors", String(options.processors)],
303
303
  ["--threads", String(options.threads)]
304
304
  ];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@storyteller-platform/ghost-story",
3
- "version": "0.1.5",
3
+ "version": "0.1.6",
4
4
  "description": "An easy-to-use speech toolset. Fork of the original echogarden project.",
5
5
  "author": "Thomas F. K. Jorna",
6
6
  "license": "GPL-3.0",