Overview
Whisper provides a clean Python API for integrating speech recognition and translation into your applications. This guide covers the main functions and common usage patterns.Basic Transcription
1
Import and load model
tiny, base, small, medium, large, turbo, or English-only variants (tiny.en, base.en, small.en, medium.en).2
Transcribe audio
The transcribe() Function
The transcribe() method is the primary interface for audio transcription.
Function Signature
Parameters
- Basic
- Quality Control
- Timestamps
- Context
audio: Path to audio file, or audio waveform as NumPy array or PyTorch tensorverbose: Display transcription progress (True,False, orNonefor silent)language: Specify the spoken language (e.g.,"en","ja","es")task: Either"transcribe"or"translate"(default:"transcribe")
Return Value
Returns a dictionary containing:Usage Examples
Specify Language
Get Segment Details
Use Initial Prompt for Custom Vocabulary
Extract Word-Level Timestamps
Process Specific Time Ranges
Disable Context Conditioning
Lower-Level Access
For more control, usedetect_language() and decode() functions:
Language Detection
Manual Decoding
The
transcribe() function internally handles sliding windows and processes the entire audio file. The decode() function only processes a single 30-second segment.Model Loading Options
Load from Specific Directory
~/.cache/whisper/.