Skip to content

πŸŽ₯ Make videos programmatically with React

`@remotion/openai-whisper`: Fix cases as described in issue #5069

Jonny Burgera7dc762a92a0
diff --git a/packages/openai-whisper/src/openai-whisper-api-to-captions.ts b/packages/openai-whisper/src/openai-whisper-api-to-captions.ts
index b1f5e01f8f..7d18b4bd55 100644
--- a/packages/openai-whisper/src/openai-whisper-api-to-captions.ts
+++ b/packages/openai-whisper/src/openai-whisper-api-to-captions.ts
@@ -38,7 +38,7 @@ export const openAiWhisperApiToCaptions = ({
const punctuation = `\\?,\\.\\%\\–\\!\\;\\:\\'\\"\\-\\_\\(\\)\\[\\]\\{\\}\\@\\#\\$\\^\\&\\*\\+\\=\\/\\|\\<\\>\\~\``;
const match = new RegExp(
- `^([\\s${punctuation}]{0,4})${word.word.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')}([${punctuation}]{0,3})?`,
+ `^([\\s?${punctuation}]{0,4})${word.word.replace(new RegExp(`^[${punctuation}]+`), '').replace(/[.*+?^${}()|[\]\\]/g, '\\$&')}([${punctuation}]{0,3})?`,
).exec(remainingText);
if (!match) {
throw new Error(
diff --git a/packages/openai-whisper/src/test/get-and-convert.test.ts b/packages/openai-whisper/src/test/get-and-convert.test.ts
index ac45d86ef0..264549aae4 100644
--- a/packages/openai-whisper/src/test/get-and-convert.test.ts
+++ b/packages/openai-whisper/src/test/get-and-convert.test.ts
@@ -104,7 +104,7 @@ if (!process.env.CI) {
timestamp_granularities: ['word'],
});
const {captions} = openAiWhisperApiToCaptions({transcription});
- expect(captions.length).toBeGreaterThan(400);
+ expect(captions.length).toBeGreaterThan(60);
},
{timeout: 60000},
);
diff --git a/packages/openai-whisper/src/test/issue-50069.test.ts b/packages/openai-whisper/src/test/issue-50069.test.ts
new file mode 100644
index 0000000000..77edd530c5
--- /dev/null
+++ b/packages/openai-whisper/src/test/issue-50069.test.ts
@@ -0,0 +1,70 @@
+import {expect, test} from 'bun:test';
+import type {OpenAiVerboseTranscription} from '../openai-format';
+import {openAiWhisperApiToCaptions} from '../openai-whisper-api-to-captions';
+
+test('issue 5069 case 1', () => {
+ const res: OpenAiVerboseTranscription = {
+ text: 'Like-minded.',
+ task: 'transcribe',
+ language: '',
+ duration: 1.325,
+ words: [
+ {word: ' Like', start: 0, end: 0.5600000023841858},
+ {word: '-minded.', start: 0.5600000023841858, end: 1.0800000429153442},
+ ],
+ };
+
+ const results = openAiWhisperApiToCaptions({transcription: res});
+
+ expect(results).toEqual({
+ captions: [
+ {
+ confidence: null,
+ endMs: 560.0000023841858,
+ startMs: 0,
+ text: 'Like-',
+ timestampMs: 280.0000011920929,
+ },
+ {
+ confidence: null,
+ endMs: 1080.0000429153442,
+ startMs: 560.0000023841858,
+ text: 'minded.',
+ timestampMs: 820.000022649765,
+ },
+ ],
+ });
+});
+
+test('issue 5069 case 2', () => {
+ const res: OpenAiVerboseTranscription = {
+ text: '50,000.',
+ task: 'transcribe',
+ language: '',
+ duration: 1.45,
+ words: [
+ {word: ' 50', start: 0, end: 0.5600000023841858},
+ {word: ',000.', start: 0.5600000023841858, end: 1.1399999856948853},
+ ],
+ };
+
+ const results = openAiWhisperApiToCaptions({transcription: res});
+ expect(results).toEqual({
+ captions: [
+ {
+ confidence: null,
+ endMs: 560.0000023841858,
+ startMs: 0,
+ text: '50,',
+ timestampMs: 280.0000011920929,
+ },
+ {
+ confidence: null,
+ endMs: 1139.9999856948853,
+ startMs: 560.0000023841858,
+ text: '000.',
+ timestampMs: 849.9999940395355,
+ },
+ ],
+ });
+});
diff --git a/packages/renderer/src/options/video-bitrate.tsx b/packages/renderer/src/options/video-bitrate.tsx
index f0d4c4f268..37557c7591 100644
--- a/packages/renderer/src/options/video-bitrate.tsx
+++ b/packages/renderer/src/options/video-bitrate.tsx
@@ -17,7 +17,7 @@ export const videoBitrateOption = {
</>
),
ssrName: 'videoBitrate',
- docLink: 'https://www.remotion.dev/docs/renderer/render-media#videobitrate-',
+ docLink: 'https://www.remotion.dev/docs/renderer/render-media#videobitrate',
type: '' as string | null,
getValue: ({commandLine}) => {
if (commandLine[cliFlag] !== undefined) {