@remotion/install-whisper-cpp 4.0.150 → 4.0.152

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.
@@ -1,6 +1,6 @@
1
+ import { type OnProgress } from './download';
1
2
  declare const models: readonly ["tiny", "tiny.en", "base", "base.en", "small", "small.en", "medium", "medium.en", "large-v1", "large-v2", "large-v3"];
2
3
  export type WhisperModel = (typeof models)[number];
3
- export type OnProgress = (downloadedBytes: number, totalBytes: number) => void;
4
4
  export declare const getModelPath: (folder: string, model: WhisperModel) => string;
5
5
  export declare const downloadWhisperModel: ({ model, folder, printOutput, onProgress, }: {
6
6
  model: WhisperModel;
@@ -29,6 +29,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
29
29
  exports.downloadWhisperModel = exports.getModelPath = void 0;
30
30
  const fs_1 = __importStar(require("fs"));
31
31
  const path_1 = __importDefault(require("path"));
32
+ const download_1 = require("./download");
32
33
  const models = [
33
34
  'tiny',
34
35
  'tiny.en',
@@ -62,49 +63,11 @@ const downloadWhisperModel = async ({ model, folder, printOutput = true, onProgr
62
63
  console.log(`Downloading whisper model ${model} from ${baseModelUrl}`);
63
64
  }
64
65
  const fileStream = fs_1.default.createWriteStream(filePath);
65
- const { body, headers } = await fetch(baseModelUrl);
66
- const contentLength = headers.get('content-length');
67
- if (body === null) {
68
- throw new Error('Failed to download whisper model');
69
- }
70
- if (contentLength === null) {
71
- throw new Error('Content-Length header not found');
72
- }
73
- const totalFileSize = parseInt(contentLength, 10);
74
- let downloaded = 0;
75
- let lastPrinted = 0;
76
- const reader = body.getReader();
77
- // eslint-disable-next-line no-async-promise-executor
78
- await new Promise(async (resolve, reject) => {
79
- try {
80
- // eslint-disable-next-line no-constant-condition
81
- while (true) {
82
- const { done, value } = await reader.read();
83
- if (value) {
84
- downloaded += value.length;
85
- if (printOutput &&
86
- (downloaded - lastPrinted > 1024 * 1024 * 10 ||
87
- downloaded === totalFileSize)) {
88
- console.log(`Downloaded ${downloaded} of ${contentLength} bytes (${((downloaded / Number(contentLength)) *
89
- 100).toFixed(2)}%)`);
90
- lastPrinted = downloaded;
91
- }
92
- fileStream.write(value, () => {
93
- onProgress === null || onProgress === void 0 ? void 0 : onProgress(downloaded, totalFileSize);
94
- if (downloaded === totalFileSize) {
95
- fileStream.end();
96
- resolve();
97
- }
98
- });
99
- }
100
- if (done) {
101
- break;
102
- }
103
- }
104
- }
105
- catch (e) {
106
- reject(e);
107
- }
66
+ await (0, download_1.downloadFile)({
67
+ fileStream,
68
+ url: baseModelUrl,
69
+ printOutput,
70
+ onProgress,
108
71
  });
109
72
  return { alreadyExisted: false };
110
73
  };
@@ -0,0 +1,14 @@
1
+ /// <reference types="node" />
2
+ /// <reference types="bun-types" />
3
+ /// <reference types="node" />
4
+ /// <reference types="node" />
5
+ /// <reference types="node" />
6
+ /// <reference types="bun-types" />
7
+ /// <reference types="bun-types" />
8
+ export type OnProgress = (downloadedBytes: number, totalBytes: number) => void;
9
+ export declare const downloadFile: ({ fileStream, url, printOutput, onProgress, }: {
10
+ fileStream: NodeJS.WritableStream;
11
+ url: string;
12
+ printOutput: boolean;
13
+ onProgress: OnProgress | undefined;
14
+ }) => Promise<void>;
@@ -0,0 +1,50 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.downloadFile = void 0;
4
+ const downloadFile = async ({ fileStream, url, printOutput, onProgress, }) => {
5
+ const { body, headers } = await fetch(url);
6
+ const contentLength = headers.get('content-length');
7
+ if (body === null) {
8
+ throw new Error('Failed to download whisper model');
9
+ }
10
+ if (contentLength === null) {
11
+ throw new Error('Content-Length header not found');
12
+ }
13
+ let downloaded = 0;
14
+ let lastPrinted = 0;
15
+ const totalFileSize = parseInt(contentLength, 10);
16
+ const reader = body.getReader();
17
+ // eslint-disable-next-line no-async-promise-executor
18
+ await new Promise(async (resolve, reject) => {
19
+ try {
20
+ // eslint-disable-next-line no-constant-condition
21
+ while (true) {
22
+ const { done, value } = await reader.read();
23
+ if (value) {
24
+ downloaded += value.length;
25
+ if (printOutput &&
26
+ (downloaded - lastPrinted > 1024 * 1024 * 10 ||
27
+ downloaded === totalFileSize)) {
28
+ console.log(`Downloaded ${downloaded} of ${contentLength} bytes (${((downloaded / Number(contentLength)) *
29
+ 100).toFixed(2)}%)`);
30
+ lastPrinted = downloaded;
31
+ }
32
+ fileStream.write(value, () => {
33
+ onProgress === null || onProgress === void 0 ? void 0 : onProgress(downloaded, totalFileSize);
34
+ if (downloaded === totalFileSize) {
35
+ fileStream.end();
36
+ resolve();
37
+ }
38
+ });
39
+ }
40
+ if (done) {
41
+ break;
42
+ }
43
+ }
44
+ }
45
+ catch (e) {
46
+ reject(e);
47
+ }
48
+ });
49
+ };
50
+ exports.downloadFile = downloadFile;
package/dist/index.d.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  export { Caption, convertToCaptions } from './convert-to-captions';
2
- export { OnProgress, WhisperModel, downloadWhisperModel, } from './download-whisper-model';
2
+ export type { OnProgress } from './download';
3
+ export { WhisperModel, downloadWhisperModel } from './download-whisper-model';
3
4
  export { installWhisperCpp } from './install-whisper-cpp';
4
5
  export type { Language } from './languages';
5
6
  export { TranscriptionJson, transcribe } from './transcribe';
@@ -29,10 +29,9 @@ Object.defineProperty(exports, "__esModule", { value: true });
29
29
  exports.installWhisperCpp = exports.getWhisperExecutablePath = void 0;
30
30
  const fs_1 = __importStar(require("fs"));
31
31
  const node_child_process_1 = require("node:child_process");
32
- const node_stream_1 = require("node:stream");
33
- const promises_1 = require("node:stream/promises");
34
32
  const os_1 = __importDefault(require("os"));
35
33
  const path_1 = __importDefault(require("path"));
34
+ const download_1 = require("./download");
36
35
  const getIsSemVer = (str) => {
37
36
  return /^[\d]{1}\.[\d]{1,2}\.+/.test(str);
38
37
  };
@@ -46,11 +45,12 @@ const installForWindows = async ({ version, to, printOutput, }) => {
46
45
  : `https://github.com/ggerganov/whisper.cpp/releases/download/v${version}/whisper-bin-x64.zip`;
47
46
  const filePath = path_1.default.join(process.cwd(), 'whisper-bin-x64.zip');
48
47
  const fileStream = fs_1.default.createWriteStream(filePath);
49
- const { body } = await fetch(url);
50
- if (body === null) {
51
- throw new Error('Failed to download whisper binary');
52
- }
53
- await (0, promises_1.finished)(node_stream_1.Readable.fromWeb(body).pipe(fileStream));
48
+ await (0, download_1.downloadFile)({
49
+ fileStream,
50
+ printOutput,
51
+ url,
52
+ onProgress: undefined,
53
+ });
54
54
  (0, node_child_process_1.execSync)(`Expand-Archive -Force ${filePath} ${to}`, {
55
55
  shell: 'powershell',
56
56
  stdio: printOutput ? 'inherit' : 'ignore',
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@remotion/install-whisper-cpp",
3
- "version": "4.0.150",
3
+ "version": "4.0.152",
4
4
  "description": "Install helper for Whisper.cpp",
5
5
  "main": "dist/index.js",
6
6
  "sideEffects": false,