Skip to main content

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

Available models: 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

  • audio: Path to audio file, or audio waveform as NumPy array or PyTorch tensor
  • verbose: Display transcription progress (True, False, or None for silent)
  • language: Specify the spoken language (e.g., "en", "ja", "es")
  • task: Either "transcribe" or "translate" (default: "transcribe")

Return Value

Returns a dictionary containing:
Each segment contains:

Usage Examples

Specify Language

Get Segment Details

Use Initial Prompt for Custom Vocabulary

The initial_prompt parameter is useful for improving accuracy with domain-specific vocabulary, proper nouns, or technical terms.

Extract Word-Level Timestamps

Process Specific Time Ranges

Disable Context Conditioning

Lower-Level Access

For more control, use detect_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

By default, models are cached in ~/.cache/whisper/.

Device Selection

Batch Processing

Audio Preprocessing

Whisper includes utility functions for audio processing:
Audio must be resampled to 16kHz mono. The whisper.load_audio() function handles this automatically using FFmpeg.