Class: Whisper::Context

Inherits:
Object
  • Object
show all
Includes:
Output::Context
Defined in:
sig/whisper.rbs

Defined Under Namespace

Classes: Params

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Output::Context

#to_srt, #to_webvtt

Class Method Details

.newinstance

Parameters:

  • (String, path, ::URI::HTTP)

Returns:

  • (instance)


58
# File 'sig/whisper.rbs', line 58

def self.new: (String | path | ::URI::HTTP) -> instance

Instance Method Details

#each_segmentvoid #each_segmentEnumerator[Segment]

Yields each Whisper::Segment:

whisper.transcribe("path/to/audio.wav", params)
whisper.each_segment do |segment|
  puts segment.text
end

Returns an Enumerator if no block given:

whisper.transcribe("path/to/audio.wav", params)
enum = whisper.each_segment
enum.to_a # => [#<Whisper::Segment>, ...]

Overloads:

  • #each_segmentvoid

    This method returns an undefined value.

  • #each_segmentEnumerator[Segment]

    Returns:

Yields:

Yield Parameters:

Yield Returns:

  • (void)


97
98
# File 'sig/whisper.rbs', line 97

def each_segment: { (Segment) -> void } -> void
| () -> Enumerator[Segment]

#full(arg0, samples, n_samples) ⇒ self #full(arg0, arg1, n_samples) ⇒ self

Run the entire model: PCM -> log mel spectrogram -> encoder -> decoder -> text Not thread safe for same context Uses the specified decoding strategy to obtain the text.

The second argument samples must be an array of samples, respond to :length, or be a MemoryView of an array of float. It must be 32 bit float PCM audio data.

Overloads:

  • #full(arg0, samples, n_samples) ⇒ self

    Parameters:

    Returns:

    • (self)
  • #full(arg0, arg1, n_samples) ⇒ self

    Parameters:

    Returns:

    • (self)


146
147
# File 'sig/whisper.rbs', line 146

def full: (Whisper::Params, Array[Float] samples, ?Integer n_samples) -> self
| (Whisper::Params, _Samples, ?Integer n_samples) -> self

#full_get_segmentSegment

Parameters:

  • nth (Integer)

Returns:



101
# File 'sig/whisper.rbs', line 101

def full_get_segment: (Integer nth) -> Segment

#full_get_segment_no_speech_probFloat

Parameters:

  • (Integer)

Returns:

  • (Float)


132
# File 'sig/whisper.rbs', line 132

def full_get_segment_no_speech_prob: (Integer) -> Float

#full_get_segment_speaker_turn_nexttrue, false

Whether the next segment indexed by segment_index is predicated as a speaker turn.

full_get_segment_speacker_turn_next(3) # => true

Parameters:

  • (Integer)

Returns:

  • (true, false)


124
# File 'sig/whisper.rbs', line 124

def full_get_segment_speaker_turn_next: (Integer) -> (true | false)

#full_get_segment_t0Integer

Start time of a segment indexed by segment_index in centiseconds (10 times milliseconds).

full_get_segment_t0(3) # => 1668 (16680 ms)

Parameters:

  • (Integer)

Returns:

  • (Integer)


112
# File 'sig/whisper.rbs', line 112

def full_get_segment_t0: (Integer) -> Integer

#full_get_segment_t1Integer

End time of a segment indexed by segment_index in centiseconds (10 times milliseconds).

full_get_segment_t1(3) # => 1668 (16680 ms)

Parameters:

  • (Integer)

Returns:

  • (Integer)


118
# File 'sig/whisper.rbs', line 118

def full_get_segment_t1: (Integer) -> Integer

#full_get_segment_textString

Text of a segment indexed by segment_index.

full_get_segment_text(3) # => "ask not what your country can do for you, ..."

Parameters:

  • (Integer)

Returns:

  • (String)


130
# File 'sig/whisper.rbs', line 130

def full_get_segment_text: (Integer) -> String

#full_get_vad_segment_t0Integer

Parameters:

  • (Integer)

Returns:

  • (Integer)


136
# File 'sig/whisper.rbs', line 136

def full_get_vad_segment_t0: (Integer) -> Integer

#full_get_vad_segment_t1Integer

Parameters:

  • (Integer)

Returns:

  • (Integer)


138
# File 'sig/whisper.rbs', line 138

def full_get_vad_segment_t1: (Integer) -> Integer

#full_lang_idInteger

Language ID, which can be converted to string by Whisper.lang_str and Whisper.lang_str_full.

Returns:

  • (Integer)


106
# File 'sig/whisper.rbs', line 106

def full_lang_id: () -> Integer

#full_n_segmentsInteger

Returns:

  • (Integer)


102
# File 'sig/whisper.rbs', line 102

def full_n_segments: () -> Integer

#full_n_vad_segmentsInteger

Returns:

  • (Integer)


134
# File 'sig/whisper.rbs', line 134

def full_n_vad_segments: () -> Integer

#full_parallel(arg0, arg1, n_samples) ⇒ self #full_parallel(arg0, arg1, n_samples) ⇒ self #full_parallel(arg0, arg1, n_samples, n_processors) ⇒ self

Split the input audio in chunks and process each chunk separately using whisper_full_with_state() Result is stored in the default state of the context Not thread safe if executed in parallel on the same context. It seems this approach can offer some speedup in some cases. However, the transcription accuracy can be worse at the beginning and end of each chunk.

If n_processors is greater than 1, you cannot set any callbacks including new_segment_callback, progress_callback, encoder_begin_callback, abort_callback, and log_callback set by Whisper.log_set

Overloads:

  • #full_parallel(arg0, arg1, n_samples) ⇒ self

    Parameters:

    Returns:

    • (self)
  • #full_parallel(arg0, arg1, n_samples) ⇒ self

    Parameters:

    Returns:

    • (self)
  • #full_parallel(arg0, arg1, n_samples, n_processors) ⇒ self

    Parameters:

    Returns:

    • (self)


158
159
160
# File 'sig/whisper.rbs', line 158

def full_parallel: (Whisper::Params, Array[Float], ?Integer n_samples) -> self
| (Whisper::Params, _Samples, ?Integer n_samples) -> self
| (Whisper::Params, _Samples, ?Integer? n_samples, Integer n_processors) -> self

#modelModel

Returns:



100
# File 'sig/whisper.rbs', line 100

def model: () -> Model

#model_ftypeInteger

Returns:

  • (Integer)


81
# File 'sig/whisper.rbs', line 81

def model_ftype: () -> Integer

#model_n_audio_ctxInteger

Returns:

  • (Integer)


76
# File 'sig/whisper.rbs', line 76

def model_n_audio_ctx: () -> Integer

#model_n_audio_stateInteger

Returns:

  • (Integer)


77
# File 'sig/whisper.rbs', line 77

def model_n_audio_state: () -> Integer

#model_n_melsInteger

Returns:

  • (Integer)


80
# File 'sig/whisper.rbs', line 80

def model_n_mels: () -> Integer

#model_n_text_headInteger

Returns:

  • (Integer)


78
# File 'sig/whisper.rbs', line 78

def model_n_text_head: () -> Integer

#model_n_text_layerInteger

Returns:

  • (Integer)


79
# File 'sig/whisper.rbs', line 79

def model_n_text_layer: () -> Integer

#model_n_vocabInteger

Returns:

  • (Integer)


75
# File 'sig/whisper.rbs', line 75

def model_n_vocab: () -> Integer

#model_typeString

Returns:

  • (String)


82
# File 'sig/whisper.rbs', line 82

def model_type: () -> String

#transcribe(arg0, arg1, n_processors:) ⇒ self #transcribe(arg0, arg1, n_processors:) ⇒ self

transcribe a single file can emit to a block results

params = Whisper::Params.new
params.duration = 60_000
whisper.transcribe "path/to/audio.wav", params do |text|
  puts text
end

If n_processors is greater than 1, you cannot set any callbacks including new_segment_callback, progress_callback, encoder_begin_callback, abort_callback, and log_callback set by Whisper.log_set

Overloads:

  • #transcribe(arg0, arg1, n_processors:) ⇒ self

    Parameters:

    Returns:

    • (self)
  • #transcribe(arg0, arg1, n_processors:) ⇒ self

    Parameters:

    Returns:

    • (self)

Yields:

Yield Parameters:

  • arg0 (String)

Yield Returns:

  • (void)


72
73
# File 'sig/whisper.rbs', line 72

def transcribe: (path, Whisper::Params, ?n_processors: Integer) -> self
| (path, Whisper::Params, ?n_processors: Integer) { (String) -> void } -> self