typescriptintermediate
Whisper Audio Transcription
Transcribe audio files to text using OpenAI Whisper API with language detection and timestamps.
typescriptPress ⌘/Ctrl + Shift + C to copy
import OpenAI from 'openai';
import * as fs from 'fs';
const openai = new OpenAI();
export async function transcribe(filePath: string) {
const file = fs.createReadStream(filePath);
const transcription = await openai.audio.transcriptions.create({
file,
model: 'whisper-1',
response_format: 'verbose_json',
timestamp_granularities: ['segment'],
});
return {
text: transcription.text,
language: transcription.language,
duration: transcription.duration,
segments: transcription.segments?.map((s) => ({
start: s.start,
end: s.end,
text: s.text,
})),
};
}
// Usage:
// const result = await transcribe('./podcast-episode.mp3');
// console.log(result.text);
// result.segments?.forEach(s => console.log(`[${s.start}s] ${s.text}`));Use Cases
- Podcast transcription
- Meeting notes
- Voice command processing
Tags
Related Snippets
Similar patterns you can reuse in the same workflow.
pythonbeginner
Whisper Audio Transcription Pipeline
Transcribe audio files to text using OpenAI Whisper API with language detection and timestamps.
Best for: meeting transcription
#whisper#transcription
pythonadvanced
Speaker Diarization with Whisper + pyannote
Transcribe audio and identify speakers by combining OpenAI Whisper with pyannote.audio diarization.
Best for: meeting transcription
#whisper#diarization
typescriptbeginner
OpenAI Text-to-Speech
Generate natural speech audio from text using OpenAI TTS API with multiple voice options and formats.
Best for: Audiobook generation
#tts#speech
pythonbeginner
OpenAI Text-to-Speech Synthesis
Convert text to natural-sounding speech using the OpenAI TTS API with voice selection and streaming.
Best for: text-to-speech
#openai#tts