Whisper
Constants
Constructors
Initializes a whisper context from a pre-loaded model buffer in memory.
buffer should contain the raw model data (same content as a model file).
Set use_gpu to true to enable Metal acceleration on macOS.
Raises Whisper::Error if the model fails to load.
Loads a whisper model from disk and initializes the inference context.
model_path should point to a GGML-format model file (e.g. ggml-base.en.bin).
Set use_gpu to true to enable Metal acceleration on macOS.
Raises Whisper::Error if the file doesn't exist or the model fails to load.
Class methods
Runs a GGML matrix multiply benchmark and returns the result code.
Runs a GGML matrix multiply benchmark and returns a human-readable result string.
Runs a memory copy benchmark and returns the result code.
Runs a memory copy benchmark and returns a human-readable result string.
Returns the language ID for the given language string, or -1 if not found.
Returns the full language name for the given ID (e.g. "german").
Instance methods
Frees the underlying whisper context. Safe to call multiple times.
Called automatically by #finalize, but explicit cleanup is preferred.
Creates an independent inference state for parallel transcription.
Each State can run inference concurrently on the same model context.
The caller is responsible for closing the returned state.
Raises Whisper::Error if the context is closed or state creation fails.
Runs the decoder on the given token context in the default state.
Call encode first. Returns 0 on success.
Returns the detected language code from the most recent transcription.
The language ID is retrieved from the default context state and converted
to a BCP-47 string (e.g. "en", "de").
Runs the encoder on the mel spectrogram in the default state.
Call pcm_to_mel or set_mel first. Returns 0 on success.
Runs language auto-detection on the mel spectrogram and returns the detected language code along with a hash of all language probabilities.
Requires pcm_to_mel or equivalent to have been called first.
Returns a Slice of logits from the last decode call on the default state.
The slice contains n_tokens * n_vocab floats (row-major, last row = last token).
Returns true if the loaded model supports multiple languages.
English-only models (e.g. ggml-base.en.bin) return false.
Converts raw PCM audio to mel spectrogram in the default state.
Returns 0 on success.
Sets a custom mel spectrogram in the default state.
n_mel must be 80. Returns 0 on success.
Returns a string describing the CPU features available for inference (e.g. AVX, NEON, Metal support).
Tokenizes the given text into an array of token IDs.
Returns the token IDs produced by the model's tokenizer.
Raises Whisper::Error if the text produces more tokens than max_tokens.
Transcribes pre-loaded audio samples into text segments.
samples must be 32-bit float PCM audio normalized to [-1.0, 1.0], mono, at 16kHz.
Use #transcribe_file to load and convert a WAV file automatically.
- language: BCP-47 language code (e.g.
"en","es"), ornilfor auto-detection. - n_threads: number of CPU threads for inference.
- translate: when
true, translates speech to English regardless of source language. - token_timestamps: when
true, enables per-token timestamp computation.
Raises Whisper::Error if the context is closed or transcription fails.
Transcribes a WAV file into text segments.
The file must be 16-bit signed PCM, mono, 16kHz. Convert other formats with:
ffmpeg -i input.mp3 -ar 16000 -ac 1 -f wav output.wav
Accepts the same keyword arguments as #transcribe.
Raises Whisper::Error if the file is missing or not a valid WAV.
Transcribes audio using multiple processors for potential speedup.
Splits input audio into chunks and processes each with whisper_full_with_state.
Results are stored in the default context state. Not thread safe if called
in parallel on the same context.
Accepts the same keyword arguments as #transcribe, plus n_processors.