class

Whisper::State

Inherits Reference < Object

Independent inference state for parallel transcription.

Multiple State instances can run inference concurrently on the same model context. Each state maintains its own mel spectrogram, encoder output, and decoder state.

whisper = Whisper.new("/path/to/model.bin")
state = whisper.create_state
# ... use state for inference ...
state.close
whisper.close

Instance methods

close

Frees the underlying whisper state. Safe to call multiple times.

Source
closed?
Source
decode(tokens : Array(Int32), n_past : Int32, n_threads : Int32 = 4) : Int32

Runs the decoder on the given token context in this state.

Source
detected_language

Returns the detected language ID from the most recent transcription on this state.

Source
encode(offset : Int32 = 0, n_threads : Int32 = 4) : Int32

Runs the encoder on the mel spectrogram in this state.

Source
finalize
Source
lang_auto_detect(offset_ms : Int32 = 0, n_threads : Int32 = 4) : Tuple(String, Hash(String, Float32))

Runs language auto-detection on this state's mel spectrogram.

Source
logits

Returns a Slice of logits from the last decode call on this state.

Source
mel_length

Returns the mel spectrogram length from this state.

Source
pcm_to_mel(samples : Array(Float32), n_threads : Int32 = 4) : Int32

Converts raw PCM audio to mel spectrogram in this state.

Source
set_mel(data : Array(Float32), n_len : Int32, n_mel : Int32 = 80) : Int32

Sets a custom mel spectrogram in this state.

Source
transcribe(samples : Array(Float32), language : String | Nil = "en", n_threads : Int32 = 4, translate : Bool = false, token_timestamps : Bool = false, tdrz_enable : Bool = false) : Array(Segment)

Runs full inference with this state on the given audio samples.

samples must be 32-bit float PCM audio normalized to [-1.0, 1.0], mono, at 16kHz.

Source