mirror of
https://github.com/ggerganov/whisper.cpp.git
synced 2024-12-24 06:46:37 +00:00
3a27b2b91b
* Remove Whisper::Model.[] * Fix Whisper::Model::URI#request * Make Whisper::Context#initialize accept pre-converted model name * Use downloading pre-converted model feature for testing * Update README * Remove unnecessary task * Move whisper/model.rb -> whisper/model/uri.rb * Update document comment of Whisper::Context#initialize * Don't show download progress when not tty * Pass String to raise * Use cache model file if download fails * Add test for auto download * Specify required Ruby version * Fix a typo * Remove unnecessary flags * Initialize Whisper::Params#diarize explicitely * Remove redundant code from README for simplicity * Add Whisper::Params#no_speech_thold attribute * Add test for Whisper::Params#no_speech_thold
84 lines
1.9 KiB
Ruby
84 lines
1.9 KiB
Ruby
require_relative "helper"
|
|
|
|
class TestSegment < TestBase
|
|
class << self
|
|
attr_reader :whisper
|
|
|
|
def startup
|
|
@whisper = Whisper::Context.new("base.en")
|
|
params = Whisper::Params.new
|
|
params.print_timestamps = false
|
|
@whisper.transcribe(TestBase::AUDIO, params)
|
|
end
|
|
end
|
|
|
|
def test_iteration
|
|
whisper.each_segment do |segment|
|
|
assert_instance_of Whisper::Segment, segment
|
|
end
|
|
end
|
|
|
|
def test_enumerator
|
|
enum = whisper.each_segment
|
|
assert_instance_of Enumerator, enum
|
|
enum.to_a.each_with_index do |segment, index|
|
|
assert_instance_of Whisper::Segment, segment
|
|
assert_kind_of Integer, index
|
|
end
|
|
end
|
|
|
|
def test_start_time
|
|
i = 0
|
|
whisper.each_segment do |segment|
|
|
assert_equal 0, segment.start_time if i == 0
|
|
i += 1
|
|
end
|
|
end
|
|
|
|
def test_end_time
|
|
i = 0
|
|
whisper.each_segment do |segment|
|
|
assert_equal whisper.full_get_segment_t1(i) * 10, segment.end_time
|
|
i += 1
|
|
end
|
|
end
|
|
|
|
def test_on_new_segment
|
|
params = Whisper::Params.new
|
|
seg = nil
|
|
index = 0
|
|
params.on_new_segment do |segment|
|
|
assert_instance_of Whisper::Segment, segment
|
|
if index == 0
|
|
seg = segment
|
|
assert_equal 0, segment.start_time
|
|
assert_match /ask not what your country can do for you, ask what you can do for your country/, segment.text
|
|
end
|
|
index += 1
|
|
end
|
|
whisper.transcribe(AUDIO, params)
|
|
assert_equal 0, seg.start_time
|
|
assert_match /ask not what your country can do for you, ask what you can do for your country/, seg.text
|
|
end
|
|
|
|
def test_on_new_segment_twice
|
|
params = Whisper::Params.new
|
|
seg = nil
|
|
params.on_new_segment do |segment|
|
|
seg = segment
|
|
return
|
|
end
|
|
params.on_new_segment do |segment|
|
|
assert_same seg, segment
|
|
return
|
|
end
|
|
whisper.transcribe(AUDIO, params)
|
|
end
|
|
|
|
private
|
|
|
|
def whisper
|
|
self.class.whisper
|
|
end
|
|
end
|