Skip to content

Commit 81e6df3

Browse files
committed
Add tests for Params#new_segment_callback=
1 parent 647c5f6 commit 81e6df3

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

bindings/ruby/tests/test_whisper.rb

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,29 @@ def test_whisper
127127
}
128128
end
129129

130+
def test_new_segment_callback_lambda
131+
counter = 0
132+
@params.new_segment_callback = ->(text, start_time, end_time, index) {
133+
assert_kind_of String, text
134+
assert_kind_of Integer, start_time
135+
assert_kind_of Integer, end_time
136+
assert_same index, counter
137+
counter += 1
138+
}
139+
whisper = Whisper::Context.new(File.join(TOPDIR, '..', '..', 'models', 'ggml-base.en.bin'))
140+
jfk = File.join(TOPDIR, '..', '..', 'samples', 'jfk.wav')
141+
whisper.transcribe(jfk, @params)
142+
end
143+
144+
def test_new_segment_callback_proc
145+
@params.new_segment_callback = proc {|text| # proc checks arguments loosly
146+
assert_kind_of String, text
147+
}
148+
whisper = Whisper::Context.new(File.join(TOPDIR, '..', '..', 'models', 'ggml-base.en.bin'))
149+
jfk = File.join(TOPDIR, '..', '..', 'samples', 'jfk.wav')
150+
whisper.transcribe(jfk, @params)
151+
end
152+
130153
def test_build
131154
Tempfile.create do |file|
132155
assert system("gem", "build", "whispercpp.gemspec", "--output", file.to_path.shellescape, exception: true)

0 commit comments

Comments
 (0)