🎥 Make videos programmatically with React
new signature
Jonny Burger48f73c219a59
diff --git a/packages/docs/docs/install-whisper-cpp/transcribe.mdx b/packages/docs/docs/install-whisper-cpp/transcribe.mdxindex e5c56775a6..18b9f082fa 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"----# transcribe()<AvailableFrom v="4.0.125 "/>+# transcribe()<AvailableFrom v="4.0.131 "/>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).@@ -50,6 +50,12 @@ npx remotion ffmpeg -i input.mp4 -ar 16000 output.wav -yThe path to your `whisper.cpp` folder.If you haven't installed Whisper.cpp, you can do so for example through [`installWhisperCpp()`](/docs/install-whisper-cpp/install-whisper-cpp) and use the same `folder`.+### `tokenLevelTimestamps`<AvailableFrom v="4.0.131"/>++Passes the `--dtw` flag to Whisper.cpp to generate more accurate timestamps, which are being returned under the `t_dtw` field.+Recommended to get actually accurate timings, but only available from Whisper.cpp versions later than 1.0.54 (commit [`741abb`](https://github.com/ggerganov/whisper.cpp/commit/741abb162ce8207eca2562e59c03efefb21c0122) or later).+Set to `false` if you use an older version of Whisper.cpp.+### `model?`_optional - default: `base.en`_diff --git a/packages/install-whisper-cpp/src/convert-to-captions.ts b/packages/install-whisper-cpp/src/convert-to-captions.tsindex a0326a108b..02146178fa 100644--- a/packages/install-whisper-cpp/src/convert-to-captions.ts+++ b/packages/install-whisper-cpp/src/convert-to-captions.ts@@ -1,6 +1,6 @@import type {TranscriptionJson} from './transcribe';-type Word = {+export type Caption = {text: string;startInSeconds: number;};@@ -11,8 +11,8 @@ export function convertToCaptions({}: {transcriptions: TranscriptionJson<true>['transcription'];combineCloseWords: number;-}): Word[] {- const merged: Word[] = [];+}): {captions: Caption[]} {+ const merged: Caption[] = [];let currentText = '';let currentFrom = 0;let currentTo = 0;@@ -39,9 +39,11 @@ export function convertToCaptions({if (currentText === '') {// It's the start of the document or after a sentence that started with a spacecurrentFrom = item.offsets.from;+ currentTokenLevelTimestamp = item.tokens[0].t_dtw;}currentText += text;+ currentText = currentText.trimStart();currentTo = item.offsets.to;}@@ -54,5 +56,5 @@ export function convertToCaptions({}});- return merged;+ return {captions: merged};}diff --git a/packages/install-whisper-cpp/src/index.ts b/packages/install-whisper-cpp/src/index.tsindex 1b77d65bf3..450539f926 100644--- a/packages/install-whisper-cpp/src/index.ts+++ b/packages/install-whisper-cpp/src/index.ts@@ -1,3 +1,4 @@+export {Caption, convertToCaptions} from './convert-to-captions';export {downloadWhisperModel,OnProgress,diff --git a/packages/install-whisper-cpp/src/test/convert-to-captions.test.ts b/packages/install-whisper-cpp/src/test/convert-to-captions.test.tsindex 8d05ea4e90..e4d9335e99 100644--- a/packages/install-whisper-cpp/src/test/convert-to-captions.test.ts+++ b/packages/install-whisper-cpp/src/test/convert-to-captions.test.ts@@ -3,13 +3,13 @@ import {convertToCaptions} from '../convert-to-captions';import {examplePayload} from './example-payload';test('Convert to captions - 200ms together', () => {- const transcript = convertToCaptions({+ const {captions: transcript} = convertToCaptions({transcriptions: examplePayload.transcription,combineCloseWords: 200,});expect(transcript).toEqual([- {text: ' William', startInSeconds: 0},+ {text: 'William', startInSeconds: 0.24},{text: 'just', startInSeconds: 0.48},{text: 'hit 100,000', startInSeconds: 0.7},{text: 'YouTube', startInSeconds: 2.22},@@ -122,7 +122,7 @@ test('Convert to captions - 200ms together', () => {});test('Convert to captions - 0ms together', () => {- const transcript = convertToCaptions({+ const {captions: transcript} = convertToCaptions({transcriptions: examplePayload.transcription,combineCloseWords: 0,});diff --git a/packages/install-whisper-cpp/src/transcribe.ts b/packages/install-whisper-cpp/src/transcribe.tsindex 9ce2f891fe..e3815136b8 100644--- a/packages/install-whisper-cpp/src/transcribe.ts+++ b/packages/install-whisper-cpp/src/transcribe.ts@@ -188,9 +188,9 @@ export const transcribe = async <HasTokenLevelTimestamps extends boolean>({inputPath: string;whisperPath: string;model: WhisperModel;+ tokenLevelTimestamps: HasTokenLevelTimestamps;modelFolder?: string;translateToEnglish?: boolean;- tokenLevelTimestamps: HasTokenLevelTimestamps;}): Promise<TranscriptionJson<HasTokenLevelTimestamps>> => {if (!existsSync(whisperPath)) {throw new Error(