Skip to content

Commit

Permalink
catch 16khz
Browse files Browse the repository at this point in the history
  • Loading branch information
JonnyBurger committed Jan 31, 2025
1 parent 7a09ccf commit 927c021
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions packages/install-whisper-cpp/src/transcribe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
};

Expand Down Expand Up @@ -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}`,
Expand Down Expand Up @@ -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"',
);
}

Expand Down

0 comments on commit 927c021

Please sign in to comment.