@remotion/install-whisper-cpp 4.0.131 → 4.0.132

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,3 +1,4 @@
1
+ export declare const getWhisperExecutablePath: (whisperPath: string) => string;
1
2
  export declare const installWhisperCpp: ({ version, to, printOutput, }: {
2
3
  version: string;
3
4
  to: string;
@@ -26,11 +26,12 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
26
26
  return (mod && mod.__esModule) ? mod : { "default": mod };
27
27
  };
28
28
  Object.defineProperty(exports, "__esModule", { value: true });
29
- exports.installWhisperCpp = void 0;
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
32
  const node_stream_1 = require("node:stream");
33
33
  const promises_1 = require("node:stream/promises");
34
+ const os_1 = __importDefault(require("os"));
34
35
  const path_1 = __importDefault(require("path"));
35
36
  const installForWindows = async ({ version, to, printOutput, }) => {
36
37
  const url = `https://github.com/ggerganov/whisper.cpp/releases/download/v${version}/whisper-bin-x64.zip`;
@@ -54,7 +55,7 @@ const installWhisperForUnix = ({ version, to, printOutput, }) => {
54
55
  });
55
56
  const isSemVer = /^[\d]{1}\.[\d]{1,2}\.+/;
56
57
  const ref = isSemVer.test(version) ? `v${version}` : version;
57
- (0, node_child_process_1.execSync)(`git checkout v${ref}`, {
58
+ (0, node_child_process_1.execSync)(`git checkout ${ref}`, {
58
59
  stdio,
59
60
  cwd: to,
60
61
  });
@@ -63,8 +64,20 @@ const installWhisperForUnix = ({ version, to, printOutput, }) => {
63
64
  stdio,
64
65
  });
65
66
  };
67
+ const getWhisperExecutablePath = (whisperPath) => {
68
+ return os_1.default.platform() === 'win32'
69
+ ? path_1.default.join(whisperPath, 'main.exe')
70
+ : path_1.default.join(whisperPath, './main');
71
+ };
72
+ exports.getWhisperExecutablePath = getWhisperExecutablePath;
66
73
  const installWhisperCpp = async ({ version, to, printOutput = true, }) => {
67
74
  if ((0, fs_1.existsSync)(to)) {
75
+ if (!(0, fs_1.existsSync)((0, exports.getWhisperExecutablePath)(to))) {
76
+ if (printOutput) {
77
+ console.log(`Whisper folder exists but the executable (${to}) is missing. Delete ${to} and try again.`);
78
+ }
79
+ return Promise.resolve({ alreadyExisted: false });
80
+ }
68
81
  if (printOutput) {
69
82
  console.log(`Whisper already exists at ${to}`);
70
83
  }
@@ -57,12 +57,13 @@ export type TranscriptionJson<WithTokenLevelTimestamp extends boolean> = {
57
57
  result: Result;
58
58
  transcription: true extends WithTokenLevelTimestamp ? TranscriptionItemWithTimestamp[] : TranscriptionItem[];
59
59
  };
60
- export declare const transcribe: <HasTokenLevelTimestamps extends boolean>({ inputPath, whisperPath, model, modelFolder, translateToEnglish, tokenLevelTimestamps, }: {
60
+ export declare const transcribe: <HasTokenLevelTimestamps extends boolean>({ inputPath, whisperPath, model, modelFolder, translateToEnglish, tokenLevelTimestamps, printOutput, }: {
61
61
  inputPath: string;
62
62
  whisperPath: string;
63
63
  model: WhisperModel;
64
64
  tokenLevelTimestamps: HasTokenLevelTimestamps;
65
65
  modelFolder?: string | undefined;
66
66
  translateToEnglish?: boolean | undefined;
67
+ printOutput?: boolean | undefined;
67
68
  }) => Promise<TranscriptionJson<HasTokenLevelTimestamps>>;
68
69
  export {};
@@ -29,9 +29,9 @@ Object.defineProperty(exports, "__esModule", { value: true });
29
29
  exports.transcribe = void 0;
30
30
  const node_child_process_1 = require("node:child_process");
31
31
  const node_fs_1 = __importStar(require("node:fs"));
32
- const node_os_1 = __importDefault(require("node:os"));
33
32
  const node_path_1 = __importDefault(require("node:path"));
34
33
  const download_whisper_model_1 = require("./download-whisper-model");
34
+ const install_whisper_cpp_1 = require("./install-whisper-cpp");
35
35
  const isWavFile = (inputPath) => {
36
36
  const splitted = inputPath.split('.');
37
37
  if (!splitted) {
@@ -43,14 +43,12 @@ const readJson = async (jsonPath) => {
43
43
  const data = await node_fs_1.default.promises.readFile(jsonPath, 'utf8');
44
44
  return JSON.parse(data);
45
45
  };
46
- const transcribeToTempJSON = async ({ fileToTranscribe, whisperPath, model, tmpJSONPath, modelFolder, translate, tokenLevelTimestamps, }) => {
46
+ const transcribeToTempJSON = async ({ fileToTranscribe, whisperPath, model, tmpJSONPath, modelFolder, translate, tokenLevelTimestamps, printOutput, }) => {
47
47
  const modelPath = (0, download_whisper_model_1.getModelPath)(modelFolder !== null && modelFolder !== void 0 ? modelFolder : whisperPath, model);
48
48
  if (!node_fs_1.default.existsSync(modelPath)) {
49
49
  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`);
50
50
  }
51
- const executable = node_os_1.default.platform() === 'win32'
52
- ? node_path_1.default.join(whisperPath, 'main.exe')
53
- : node_path_1.default.join(whisperPath, './main');
51
+ const executable = (0, install_whisper_cpp_1.getWhisperExecutablePath)(whisperPath);
54
52
  const args = [
55
53
  '-f',
56
54
  fileToTranscribe,
@@ -59,7 +57,7 @@ const transcribeToTempJSON = async ({ fileToTranscribe, whisperPath, model, tmpJ
59
57
  '--output-json',
60
58
  '--max-len',
61
59
  '1',
62
- '-ofj',
60
+ '-ojf',
63
61
  tokenLevelTimestamps ? ['--dtw', model] : null,
64
62
  model ? [`-m`, `${modelPath}`] : null,
65
63
  translate ? '-tr' : null,
@@ -67,7 +65,9 @@ const transcribeToTempJSON = async ({ fileToTranscribe, whisperPath, model, tmpJ
67
65
  .flat(1)
68
66
  .filter(Boolean);
69
67
  const outputPath = await new Promise((resolve, reject) => {
70
- const task = (0, node_child_process_1.spawn)(executable, args, { cwd: whisperPath });
68
+ const task = (0, node_child_process_1.spawn)(executable, args, {
69
+ cwd: whisperPath,
70
+ });
71
71
  const predictedPath = `${tmpJSONPath}.json`;
72
72
  let output = '';
73
73
  const onData = (data) => {
@@ -78,8 +78,20 @@ const transcribeToTempJSON = async ({ fileToTranscribe, whisperPath, model, tmpJ
78
78
  task.kill();
79
79
  }
80
80
  };
81
- task.stdout.on('data', onData);
82
- task.stderr.on('data', onData);
81
+ const onStderr = (data) => {
82
+ onData(data);
83
+ if (printOutput) {
84
+ console.error(data.toString('utf-8'));
85
+ }
86
+ };
87
+ const onStdout = (data) => {
88
+ onData(data);
89
+ if (printOutput) {
90
+ console.error(data.toString('utf-8'));
91
+ }
92
+ };
93
+ task.stdout.on('data', onStdout);
94
+ task.stderr.on('data', onStderr);
83
95
  task.on('exit', (code) => {
84
96
  // Whisper sometimes files also with error code 0
85
97
  // https://github.com/ggerganov/whisper.cpp/pull/1952/files
@@ -92,7 +104,7 @@ const transcribeToTempJSON = async ({ fileToTranscribe, whisperPath, model, tmpJ
92
104
  });
93
105
  return { outputPath };
94
106
  };
95
- const transcribe = async ({ inputPath, whisperPath, model, modelFolder, translateToEnglish = false, tokenLevelTimestamps, }) => {
107
+ const transcribe = async ({ inputPath, whisperPath, model, modelFolder, translateToEnglish = false, tokenLevelTimestamps, printOutput = true, }) => {
96
108
  if (!(0, node_fs_1.existsSync)(whisperPath)) {
97
109
  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.`);
98
110
  }
@@ -111,6 +123,7 @@ const transcribe = async ({ inputPath, whisperPath, model, modelFolder, translat
111
123
  modelFolder: modelFolder !== null && modelFolder !== void 0 ? modelFolder : null,
112
124
  translate: translateToEnglish,
113
125
  tokenLevelTimestamps,
126
+ printOutput,
114
127
  });
115
128
  const json = (await readJson(tmpJSONPath));
116
129
  node_fs_1.default.unlinkSync(tmpJSONPath);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@remotion/install-whisper-cpp",
3
- "version": "4.0.131",
3
+ "version": "4.0.132",
4
4
  "description": "Install helper for Whisper.cpp",
5
5
  "main": "dist/index.js",
6
6
  "sideEffects": false,