Skip to content

🎥 Make videos programmatically with React

catch 16khz

Jonny Burger927c02137d61
diff --git a/packages/install-whisper-cpp/src/transcribe.ts b/packages/install-whisper-cpp/src/transcribe.ts
index 6fe1e473c1..ad7c5a7fb8 100644
--- a/packages/install-whisper-cpp/src/transcribe.ts
+++ b/packages/install-whisper-cpp/src/transcribe.ts
@@ -199,10 +199,14 @@ const transcribeToTemporaryFile = async ({
}
};
+ let stderr = '';
+
const onStderr = (data: Buffer) => {
onData(data);
+ const utf8 = data.toString('utf-8');
+ stderr += utf8;
if (printOutput) {
- process.stderr.write(data.toString('utf-8'));
+ process.stderr.write(utf8);
}
};
@@ -233,6 +237,14 @@ const transcribeToTemporaryFile = async ({
return;
}
+ if (stderr.includes('must be 16 kHz')) {
+ reject(
+ new Error(
+ 'wav file must be 16 kHz - use this command to make it so: "ffmpeg -i input.wav -ar 16000 output.wav -y"',
+ ),
+ );
+ }
+
reject(
new Error(
`No transcription was created (process exited with code ${code}): ${output}`,
@@ -283,7 +295,7 @@ export const transcribe = async <HasTokenLevelTimestamps extends boolean>({
if (!isWavFile(inputPath)) {
throw new Error(
- 'Invalid inputFile type. The provided file is not a wav file!',
+ 'Invalid inputFile type. The provided file is not a wav file! Convert the file to a 16KHz wav file first: "ffmpeg -i input.mp4 -ar 16000 output.wav -y"',
);
}