Skip to content

🎥 Make videos programmatically with React

translation added

Patric Salvisbergace5666c3597
diff --git a/packages/docs/docs/install-whisper-cpp/transcribe.mdx b/packages/docs/docs/install-whisper-cpp/transcribe.mdx
index 41c3caa928..4b76481bd3 100644
--- a/packages/docs/docs/install-whisper-cpp/transcribe.mdx
+++ b/packages/docs/docs/install-whisper-cpp/transcribe.mdx
@@ -4,7 +4,7 @@ title: transcribe()
crumb: "@remotion/install-whisper-cpp"
---
-# downloadWhisperModel()<AvailableFrom v="?"/>
+# downloadWhisperModel()<AvailableFrom v="4.0.125 "/>
Transcribes a media file by utilizing Whisper.cpp.
You should first install Whisper.cpp, for example through [`installWhisperCpp()`](/docs/install-whisper-cpp/install-whisper-cpp).
@@ -47,9 +47,9 @@ The path to your Whisper.cpp folder. If you haven't installed Whisper.cpp, you c
### `model?`
-Specify a specific Whisper model for the transcription.
+_optional - default: `base.en`_
-Default: `base.en`
+Specify a specific Whisper model for the transcription.
Possible values: `tiny`, `tiny.en`, `base`, `base.en`, `small`, `small.en`, `medium`, `medium.en`, `large-v1`, `large-v2`, `large-v3`.
@@ -57,10 +57,23 @@ Make sure the model you want to use exists in your `whisper.cpp/models` folder.
### `modelFolder?`
+_optional - default: whisperPath/models_
+
If you saved Whisper models to a specific folder, pass its path here.
Uses the `whisper.cpp/models` folder at the location defined through `whisperPath` as default.
+### `translateToEnglish?`
+
+_optional - default: false_
+
+Set this boolean flag if you want to get a translated transcription of the provided file in English.
+Make sure to not use a \*.en model, as they will not be able to translate a foreign language to english.
+
+:::info
+We recommend using at least the `medium` model to get satisfactory results.
+:::
+
## Return value
### `TranscriptionJson`
diff --git a/packages/install-whisper-cpp/src/transcribe.ts b/packages/install-whisper-cpp/src/transcribe.ts
index 2530297a6b..9626b745a5 100644
--- a/packages/install-whisper-cpp/src/transcribe.ts
+++ b/packages/install-whisper-cpp/src/transcribe.ts
@@ -80,6 +80,7 @@ const transcribeToTempJSON = async (
model: WhisperModel,
tmpJSONPath: string,
modelFolder: string | null,
+ translate: boolean,
) => {
const promisifiedExec = util.promisify(exec);
@@ -107,8 +108,11 @@ const transcribeToTempJSON = async (
? path.join(whisperPath, 'main.exe')
: path.join(whisperPath, './main');
+ const modelOption = model ? `-m ${modelPath}` : '';
+ const translateOption = translate ? `-tr ` : '';
+
await promisifiedExec(
- `${executable} -f ${fileToTranscribe} --output-file ${tmpJSONPath} --output-json --max-len 1 -m ${modelPath}`,
+ `${executable} -f ${fileToTranscribe} --output-file ${tmpJSONPath} --output-json --max-len 1 ${modelOption} ${translateOption}`,
{cwd: whisperPath},
).then(({stderr}) => {
if (stderr.includes('error')) {
@@ -122,11 +126,13 @@ export const transcribe = async ({
whisperPath,
model = 'base.en',
modelFolder,
+ translateToEnglish = false,
}: {
filePath: string;
whisperPath: string;
model?: WhisperModel;
modelFolder?: string;
+ translateToEnglish?: boolean;
}): Promise<{transcription: TranscriptionJson}> => {
if (!existsSync(whisperPath)) {
throw new Error(
@@ -152,13 +158,17 @@ export const transcribe = async ({
model,
tmpJSONPath,
modelFolder ?? null,
+ translateToEnglish,
);
const json = await readJson(tmpJSONPath + '.json');
fs.unlink(tmpJSONPath + '.json', (err) => {
if (err) {
- console.error('Error while deleting a file: ', err);
+ console.error(
+ 'An error occured while deleting the temporary json file: ',
+ err,
+ );
}
});