@remotion/install-whisper-cpp 4.0.269 → 4.0.271

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,4 +1,4 @@
1
- export declare const getWhisperExecutablePath: (whisperPath: string) => string;
1
+ export declare const getWhisperExecutablePath: (whisperPath: string, whisperCppVersion: string) => string;
2
2
  export declare const installWhisperCpp: ({ version, to, printOutput, signal, }: {
3
3
  version: string;
4
4
  to: string;
@@ -33,6 +33,7 @@ const fs_1 = __importStar(require("fs"));
33
33
  const os_1 = __importDefault(require("os"));
34
34
  const path_1 = __importDefault(require("path"));
35
35
  const download_1 = require("./download");
36
+ const utils_1 = require("./utils");
36
37
  const getIsSemVer = (str) => {
37
38
  return /^[\d]{1}\.[\d]{1,2}\.+/.test(str);
38
39
  };
@@ -108,17 +109,24 @@ const installWhisperForUnix = async ({ version, to, printOutput, signal, }) => {
108
109
  shell: null,
109
110
  });
110
111
  };
111
- const getWhisperExecutablePath = (whisperPath) => {
112
+ const getWhisperExecutablePath = (whisperPath, whisperCppVersion) => {
113
+ // INFO: 'main.exe' is deprecated.
114
+ let cppBin = ['main'];
115
+ let cppFolder = [];
116
+ if ((0, utils_1.compareVersions)(whisperCppVersion, '1.7.4') >= 0) {
117
+ cppBin = ['whisper-cli'];
118
+ cppFolder = ['build', 'bin'];
119
+ }
112
120
  return os_1.default.platform() === 'win32'
113
- ? path_1.default.join(path_1.default.resolve(process.cwd(), whisperPath), 'main.exe')
114
- : path_1.default.join(path_1.default.resolve(process.cwd(), whisperPath), './main');
121
+ ? path_1.default.join(path_1.default.resolve(process.cwd(), whisperPath), ...cppFolder, `${cppBin}.exe`)
122
+ : path_1.default.join(path_1.default.resolve(process.cwd(), whisperPath), ...cppFolder, `./${cppBin}`);
115
123
  };
116
124
  exports.getWhisperExecutablePath = getWhisperExecutablePath;
117
125
  const installWhisperCpp = async ({ version, to, printOutput = true, signal, }) => {
118
126
  if ((0, fs_1.existsSync)(to)) {
119
- if (!(0, fs_1.existsSync)((0, exports.getWhisperExecutablePath)(to))) {
127
+ if (!(0, fs_1.existsSync)((0, exports.getWhisperExecutablePath)(to, version))) {
120
128
  if (printOutput) {
121
- throw new Error(`Whisper folder ${to} exists but the executable (${(0, exports.getWhisperExecutablePath)(to)}) is missing. Delete ${to} and try again.`);
129
+ throw new Error(`Whisper folder ${to} exists but the executable (${(0, exports.getWhisperExecutablePath)(to, version)}) is missing. Delete ${to} and try again.`);
122
130
  }
123
131
  return Promise.resolve({ alreadyExisted: false });
124
132
  }
@@ -137,7 +145,12 @@ const installWhisperCpp = async ({ version, to, printOutput = true, signal, }) =
137
145
  return Promise.resolve({ alreadyExisted: false });
138
146
  }
139
147
  if (process.platform === 'win32') {
140
- await installForWindows({ version, to, printOutput, signal: signal !== null && signal !== void 0 ? signal : null });
148
+ await installForWindows({
149
+ version,
150
+ to,
151
+ printOutput,
152
+ signal: signal !== null && signal !== void 0 ? signal : null,
153
+ });
141
154
  return Promise.resolve({ alreadyExisted: false });
142
155
  }
143
156
  throw new Error(`Unsupported platform: ${process.platform}`);
@@ -60,9 +60,10 @@ export type TranscriptionJson<WithTokenLevelTimestamp extends boolean> = {
60
60
  };
61
61
  export type TranscribeOnProgress = (progress: number) => void;
62
62
  export declare const modelToDtw: (model: WhisperModel) => string;
63
- export declare const transcribe: <HasTokenLevelTimestamps extends boolean>({ inputPath, whisperPath, model, modelFolder, translateToEnglish, tokenLevelTimestamps, printOutput, tokensPerItem, language, splitOnWord, signal, onProgress, }: {
63
+ export declare const transcribe: <HasTokenLevelTimestamps extends boolean>({ inputPath, whisperPath, whisperCppVersion, model, modelFolder, translateToEnglish, tokenLevelTimestamps, printOutput, tokensPerItem, language, splitOnWord, signal, onProgress, }: {
64
64
  inputPath: string;
65
65
  whisperPath: string;
66
+ whisperCppVersion: string;
66
67
  model: WhisperModel;
67
68
  tokenLevelTimestamps: HasTokenLevelTimestamps;
68
69
  modelFolder?: string;
@@ -61,12 +61,12 @@ const modelToDtw = (model) => {
61
61
  return model;
62
62
  };
63
63
  exports.modelToDtw = modelToDtw;
64
- const transcribeToTemporaryFile = async ({ fileToTranscribe, whisperPath, model, tmpJSONPath, modelFolder, translate, tokenLevelTimestamps, printOutput, tokensPerItem, language, splitOnWord, signal, onProgress, }) => {
64
+ const transcribeToTemporaryFile = async ({ fileToTranscribe, whisperPath, whisperCppVersion, model, tmpJSONPath, modelFolder, translate, tokenLevelTimestamps, printOutput, tokensPerItem, language, splitOnWord, signal, onProgress, }) => {
65
65
  const modelPath = (0, download_whisper_model_1.getModelPath)(modelFolder !== null && modelFolder !== void 0 ? modelFolder : whisperPath, model);
66
66
  if (!node_fs_1.default.existsSync(modelPath)) {
67
67
  throw new Error(`Error: Model ${model} does not exist at ${modelFolder ? modelFolder : modelPath}. Check out the downloadWhisperModel() API at https://www.remotion.dev/docs/install-whisper-cpp/download-whisper-model to see how to install whisper models`);
68
68
  }
69
- const executable = (0, install_whisper_cpp_1.getWhisperExecutablePath)(whisperPath);
69
+ const executable = (0, install_whisper_cpp_1.getWhisperExecutablePath)(whisperPath, whisperCppVersion);
70
70
  const args = [
71
71
  '-f',
72
72
  fileToTranscribe,
@@ -141,7 +141,7 @@ const transcribeToTemporaryFile = async ({ fileToTranscribe, whisperPath, model,
141
141
  });
142
142
  return { outputPath };
143
143
  };
144
- const transcribe = async ({ inputPath, whisperPath, model, modelFolder, translateToEnglish = false, tokenLevelTimestamps, printOutput = true, tokensPerItem, language, splitOnWord, signal, onProgress, }) => {
144
+ const transcribe = async ({ inputPath, whisperPath, whisperCppVersion, model, modelFolder, translateToEnglish = false, tokenLevelTimestamps, printOutput = true, tokensPerItem, language, splitOnWord, signal, onProgress, }) => {
145
145
  if (!(0, node_fs_1.existsSync)(whisperPath)) {
146
146
  throw new Error(`Whisper does not exist at ${whisperPath}. Double-check the passed whisperPath. If you havent installed whisper, check out the installWhisperCpp() API at https://www.remotion.dev/docs/install-whisper-cpp/install-whisper-cpp to see how to install whisper programatically.`);
147
147
  }
@@ -155,6 +155,7 @@ const transcribe = async ({ inputPath, whisperPath, model, modelFolder, translat
155
155
  const { outputPath: tmpJSONPath } = await transcribeToTemporaryFile({
156
156
  fileToTranscribe: inputPath,
157
157
  whisperPath,
158
+ whisperCppVersion,
158
159
  model,
159
160
  tmpJSONPath: tmpJSONDir,
160
161
  modelFolder: modelFolder !== null && modelFolder !== void 0 ? modelFolder : null,
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Compares two version strings.
3
+ *
4
+ * @param version1 - The first version string.
5
+ * @param version2 - The second version string.
6
+ * @returns 1 if version1 > version2, -1 if version1 < version2, 0 if they are equal.
7
+ * @throws {Error} If either version is not a valid string or has an invalid format.
8
+ */
9
+ export declare function compareVersions(version1: string, version2: string): number;
package/dist/utils.js ADDED
@@ -0,0 +1,38 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.compareVersions = compareVersions;
4
+ /**
5
+ * Compares two version strings.
6
+ *
7
+ * @param version1 - The first version string.
8
+ * @param version2 - The second version string.
9
+ * @returns 1 if version1 > version2, -1 if version1 < version2, 0 if they are equal.
10
+ * @throws {Error} If either version is not a valid string or has an invalid format.
11
+ */
12
+ function compareVersions(version1, version2) {
13
+ const parseVersion = (version) => {
14
+ const parts = version.split('.').map((part) => Number(part));
15
+ if (parts.some(isNaN)) {
16
+ throw new Error('Invalid version format. Expected x.x.x');
17
+ }
18
+ return parts;
19
+ };
20
+ if (typeof version1 !== 'string' || typeof version2 !== 'string') {
21
+ throw new Error('Both inputs should be strings. Expected x.x.x');
22
+ }
23
+ const v1Parts = parseVersion(version1);
24
+ const v2Parts = parseVersion(version2);
25
+ // Ensure both versions have the same number of parts
26
+ const maxLength = Math.max(v1Parts.length, v2Parts.length);
27
+ while (v1Parts.length < maxLength)
28
+ v1Parts.push(0);
29
+ while (v2Parts.length < maxLength)
30
+ v2Parts.push(0);
31
+ for (let i = 0; i < maxLength; i++) {
32
+ if (v1Parts[i] > v2Parts[i])
33
+ return 1; // Version1 is greater
34
+ if (v1Parts[i] < v2Parts[i])
35
+ return -1; // Version2 is greater
36
+ }
37
+ return 0; // Versions are equal
38
+ }
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "url": "https://github.com/remotion-dev/remotion/tree/main/packages/install-whisper-cpp"
4
4
  },
5
5
  "name": "@remotion/install-whisper-cpp",
6
- "version": "4.0.269",
6
+ "version": "4.0.271",
7
7
  "description": "Helpers for installing and using Whisper.cpp",
8
8
  "main": "dist/index.js",
9
9
  "sideEffects": false,
@@ -16,12 +16,12 @@
16
16
  "author": "Jonny Burger <jonny@remotion.dev>",
17
17
  "license": "SEE LICENSE IN LICENSE.md",
18
18
  "dependencies": {
19
- "@remotion/captions": "4.0.269"
19
+ "@remotion/captions": "4.0.271"
20
20
  },
21
21
  "peerDependencies": {},
22
22
  "devDependencies": {
23
23
  "eslint": "9.19.0",
24
- "@remotion/eslint-config-internal": "4.0.269"
24
+ "@remotion/eslint-config-internal": "4.0.271"
25
25
  },
26
26
  "keywords": [
27
27
  "remotion",