Skip to main content

openAiWhisperApiToCaptions()v4.0.217

Turns the output from openai.audio.transcriptions.create from the openai package into an array of Caption objects.

This package performs processing on the captions in order to retain the punctuation in the words, which is not by default included in the OpenAI response.

This function can be used in any JavaScript environment, but you should not use the OpenAI API in the browser because your API key will be exposed to the browser.

Example usage
tsx
import fs from 'fs';
import {OpenAI} from 'openai';
import {openAiWhisperApiToCaptions} from '@remotion/openai-whisper';
 
const openai = new OpenAI();
 
const transcription = await openai.audio.transcriptions.create({
file: fs.createReadStream('audio.mp3'),
model: 'whisper-1',
response_format: 'verbose_json',
prompt: 'Hello, welcome to my lecture.',
timestamp_granularities: ['word'],
});
 
const {captions} = openAiWhisperApiToCaptions({transcription});
Example usage
tsx
import fs from 'fs';
import {OpenAI} from 'openai';
import {openAiWhisperApiToCaptions} from '@remotion/openai-whisper';
 
const openai = new OpenAI();
 
const transcription = await openai.audio.transcriptions.create({
file: fs.createReadStream('audio.mp3'),
model: 'whisper-1',
response_format: 'verbose_json',
prompt: 'Hello, welcome to my lecture.',
timestamp_granularities: ['word'],
});
 
const {captions} = openAiWhisperApiToCaptions({transcription});

See also