Skip to main content

DecodingOptions

A frozen dataclass that contains all configuration options for decoding 30-second audio segments. Used by the decode() function to control decoding behavior.

Fields

Task and Language

str
default:"transcribe"
Whether to perform transcription ("transcribe") or translation to English ("translate")
Optional[str]
default:"None"
Language code of the audio (e.g., "en", "fr", "ja"). If None, language is detected automatically.

Sampling Strategy

float
default:"0.0"
Sampling temperature. Use 0.0 for greedy decoding (deterministic), or values like 0.2-1.0 for stochastic sampling.
Optional[int]
default:"None"
Maximum number of tokens to sample. Defaults to n_text_ctx // 2 if not specified.
Optional[int]
default:"None"
Number of independent samples to generate when using stochastic sampling (temperature > 0). The best one is selected based on log probability.
Optional[int]
default:"None"
Number of beams for beam search when using greedy decoding (temperature = 0). Cannot be used with best_of.
Optional[float]
default:"None"
Beam search patience factor as described in arxiv:2204.05424. Requires beam_size to be set.
Optional[float]
default:"None"
“Alpha” parameter for length penalty in Google NMT. Use None for simple length normalization. Should be between 0 and 1.

Prompting and Context

Optional[Union[str, List[int]]]
default:"None"
Text or token IDs to provide as context from previous audio. Helps with consistency across segments. See discussion for details.
Optional[Union[str, List[int]]]
default:"None"
Text or token IDs to prefix the current segment with. Forces the transcription to start with specific text.

Token Suppression

Optional[Union[str, Iterable[int]]]
default:"-1"
List of token IDs to suppress, or comma-separated string. Use "-1" to suppress non-speech tokens as defined in tokenizer.non_speech_tokens().
bool
default:"True"
Suppress blank outputs at the beginning of sampling

Timestamp Options

bool
default:"False"
Use <|notimestamps|> token to sample text tokens only, without any timestamp tokens
Optional[float]
default:"1.0"
Maximum allowed timestamp (in seconds) for the first token. Prevents the model from starting too late in the audio.

Implementation Details

bool
default:"True"
Use 16-bit floating point precision for most calculations. Set to False if running on CPU or if encountering numerical issues.

Usage Examples

Basic Transcription

Translation to English

Beam Search Decoding

Stochastic Sampling

Using Prompts for Context

Text-Only Output (No Timestamps)

Custom Token Suppression

Using Kwargs Shortcut

Notes

When to Use Each Option

  • Greedy decoding (temperature=0.0): Fastest and most deterministic, good for most use cases
  • Beam search (beam_size=5): Better quality for challenging audio, slower than greedy
  • Stochastic sampling (temperature>0, best_of>1): Useful for creative applications or when you want variation

Constraints

  • Cannot use beam_size and best_of together
  • patience requires beam_size to be set
  • length_penalty should be between 0 and 1 if specified
  • best_of is incompatible with greedy sampling (temperature=0)

Performance Tips

  • Set fp16=False when running on CPU for better compatibility
  • Lower beam_size for faster decoding at the cost of quality
  • Use without_timestamps=True if you don’t need timestamp information
  • The dataclass is frozen (immutable) - create a new instance to change options

Language Codes

Common language codes include: "en" (English), "zh" (Chinese), "es" (Spanish), "fr" (French), "de" (German), "ja" (Japanese), "ko" (Korean), "ru" (Russian), "ar" (Arabic), "hi" (Hindi)