Skip to content

Commit

Permalink
Group tests for #transcribe
Browse files Browse the repository at this point in the history
  • Loading branch information
KitaitiMakoto committed Oct 19, 2024
1 parent 81e6df3 commit 71b65b0
Showing 1 changed file with 32 additions and 32 deletions.
64 changes: 32 additions & 32 deletions bindings/ruby/tests/test_whisper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -116,38 +116,38 @@ def test_split_on_word
assert !@params.split_on_word
end

def test_whisper
@whisper = Whisper::Context.new(File.join(TOPDIR, '..', '..', 'models', 'ggml-base.en.bin'))
params = Whisper::Params.new
params.print_timestamps = false

jfk = File.join(TOPDIR, '..', '..', 'samples', 'jfk.wav')
@whisper.transcribe(jfk, params) {|text|
assert_match /ask not what your country can do for you, ask what you can do for your country/, text
}
end

def test_new_segment_callback_lambda
counter = 0
@params.new_segment_callback = ->(text, start_time, end_time, index) {
assert_kind_of String, text
assert_kind_of Integer, start_time
assert_kind_of Integer, end_time
assert_same index, counter
counter += 1
}
whisper = Whisper::Context.new(File.join(TOPDIR, '..', '..', 'models', 'ggml-base.en.bin'))
jfk = File.join(TOPDIR, '..', '..', 'samples', 'jfk.wav')
whisper.transcribe(jfk, @params)
end

def test_new_segment_callback_proc
@params.new_segment_callback = proc {|text| # proc checks arguments loosly
assert_kind_of String, text
}
whisper = Whisper::Context.new(File.join(TOPDIR, '..', '..', 'models', 'ggml-base.en.bin'))
jfk = File.join(TOPDIR, '..', '..', 'samples', 'jfk.wav')
whisper.transcribe(jfk, @params)
sub_test_case "#transcribe" do
def setup
@whisper = Whisper::Context.new(File.join(TOPDIR, '..', '..', 'models', 'ggml-base.en.bin'))
@params = Whisper::Params.new
@params.print_timestamps = false
@jfk = File.join(TOPDIR, '..', '..', 'samples', 'jfk.wav')
end

def test_whisper
@whisper.transcribe(@jfk, @params) {|text|
assert_match /ask not what your country can do for you, ask what you can do for your country/, text
}
end

def test_new_segment_callback_lambda
counter = 0
@params.new_segment_callback = ->(text, start_time, end_time, index) {
assert_kind_of String, text
assert_kind_of Integer, start_time
assert_kind_of Integer, end_time
assert_same index, counter
counter += 1
}
@whisper.transcribe(@jfk, @params)
end

def test_new_segment_callback_proc
@params.new_segment_callback = proc {|text| # proc checks arguments loosly
assert_kind_of String, text
}
@whisper.transcribe(@jfk, @params)
end
end

def test_build
Expand Down

0 comments on commit 71b65b0

Please sign in to comment.