Class: Whisper::Context
- Inherits:
-
Object
- Object
- Whisper::Context
- Includes:
- Output::Context
- Defined in:
- sig/whisper.rbs
Defined Under Namespace
Classes: Params
Class Method Summary collapse
Instance Method Summary collapse
-
#each_segment {|arg0| ... } ⇒ Object
Yields each Whisper::Segment:.
-
#full ⇒ Object
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.
- #full_get_segment ⇒ Segment
- #full_get_segment_no_speech_prob ⇒ Float
-
#full_get_segment_speaker_turn_next ⇒ true, false
Whether the next segment indexed by
segment_indexis predicated as a speaker turn. -
#full_get_segment_t0 ⇒ Integer
Start time of a segment indexed by
segment_indexin centiseconds (10 times milliseconds). -
#full_get_segment_t1 ⇒ Integer
End time of a segment indexed by
segment_indexin centiseconds (10 times milliseconds). -
#full_get_segment_text ⇒ String
Text of a segment indexed by
segment_index. - #full_get_vad_segment_t0 ⇒ Integer
- #full_get_vad_segment_t1 ⇒ Integer
-
#full_lang_id ⇒ Integer
Language ID, which can be converted to string by Whisper.lang_str and Whisper.lang_str_full.
- #full_n_segments ⇒ Integer
- #full_n_vad_segments ⇒ Integer
-
#full_parallel ⇒ Object
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. - #model ⇒ Model
- #model_ftype ⇒ Integer
- #model_n_audio_ctx ⇒ Integer
- #model_n_audio_state ⇒ Integer
- #model_n_mels ⇒ Integer
- #model_n_text_head ⇒ Integer
- #model_n_text_layer ⇒ Integer
- #model_n_vocab ⇒ Integer
- #model_type ⇒ String
-
#transcribe {|arg0| ... } ⇒ Object
transcribe a single file can emit to a block results.
Methods included from Output::Context
Class Method Details
.new ⇒ instance
58 |
# File 'sig/whisper.rbs', line 58
def self.new: (String | path | ::URI::HTTP) -> instance
|
Instance Method Details
#each_segment ⇒ void #each_segment ⇒ Enumerator[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>, ...]
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.
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_segment ⇒ Segment
101 |
# File 'sig/whisper.rbs', line 101
def full_get_segment: (Integer nth) -> Segment
|
#full_get_segment_no_speech_prob ⇒ Float
132 |
# File 'sig/whisper.rbs', line 132
def full_get_segment_no_speech_prob: (Integer) -> Float
|
#full_get_segment_speaker_turn_next ⇒ true, false
Whether the next segment indexed by segment_index is predicated as a speaker turn.
full_get_segment_speacker_turn_next(3) # => true
124 |
# File 'sig/whisper.rbs', line 124
def full_get_segment_speaker_turn_next: (Integer) -> (true | false)
|
#full_get_segment_t0 ⇒ Integer
Start time of a segment indexed by segment_index in centiseconds (10 times milliseconds).
full_get_segment_t0(3) # => 1668 (16680 ms)
112 |
# File 'sig/whisper.rbs', line 112
def full_get_segment_t0: (Integer) -> Integer
|
#full_get_segment_t1 ⇒ Integer
End time of a segment indexed by segment_index in centiseconds (10 times milliseconds).
full_get_segment_t1(3) # => 1668 (16680 ms)
118 |
# File 'sig/whisper.rbs', line 118
def full_get_segment_t1: (Integer) -> Integer
|
#full_get_segment_text ⇒ String
Text of a segment indexed by segment_index.
full_get_segment_text(3) # => "ask not what your country can do for you, ..."
130 |
# File 'sig/whisper.rbs', line 130
def full_get_segment_text: (Integer) -> String
|
#full_get_vad_segment_t0 ⇒ Integer
136 |
# File 'sig/whisper.rbs', line 136
def full_get_vad_segment_t0: (Integer) -> Integer
|
#full_get_vad_segment_t1 ⇒ Integer
138 |
# File 'sig/whisper.rbs', line 138
def full_get_vad_segment_t1: (Integer) -> Integer
|
#full_lang_id ⇒ Integer
Language ID, which can be converted to string by Whisper.lang_str and Whisper.lang_str_full.
106 |
# File 'sig/whisper.rbs', line 106
def full_lang_id: () -> Integer
|
#full_n_segments ⇒ Integer
102 |
# File 'sig/whisper.rbs', line 102
def full_n_segments: () -> Integer
|
#full_n_vad_segments ⇒ 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
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
|
#model_ftype ⇒ Integer
81 |
# File 'sig/whisper.rbs', line 81
def model_ftype: () -> Integer
|
#model_n_audio_ctx ⇒ Integer
76 |
# File 'sig/whisper.rbs', line 76
def model_n_audio_ctx: () -> Integer
|
#model_n_audio_state ⇒ Integer
77 |
# File 'sig/whisper.rbs', line 77
def model_n_audio_state: () -> Integer
|
#model_n_mels ⇒ Integer
80 |
# File 'sig/whisper.rbs', line 80
def model_n_mels: () -> Integer
|
#model_n_text_head ⇒ Integer
78 |
# File 'sig/whisper.rbs', line 78
def model_n_text_head: () -> Integer
|
#model_n_text_layer ⇒ Integer
79 |
# File 'sig/whisper.rbs', line 79
def model_n_text_layer: () -> Integer
|
#model_n_vocab ⇒ Integer
75 |
# File 'sig/whisper.rbs', line 75
def model_n_vocab: () -> Integer
|
#model_type ⇒ 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
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
|