From 81e6df3bab7662da5379db51f28a989db7408c02 Mon Sep 17 00:00:00 2001 From: Kitaiti Makoto Date: Fri, 18 Oct 2024 01:23:43 +0900 Subject: [PATCH] Add tests for Params#new_segment_callback= --- bindings/ruby/tests/test_whisper.rb | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/bindings/ruby/tests/test_whisper.rb b/bindings/ruby/tests/test_whisper.rb index 410b5248..a496b3ae 100644 --- a/bindings/ruby/tests/test_whisper.rb +++ b/bindings/ruby/tests/test_whisper.rb @@ -127,6 +127,29 @@ class TestWhisper < Test::Unit::TestCase } 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) + end + def test_build Tempfile.create do |file| assert system("gem", "build", "whispercpp.gemspec", "--output", file.to_path.shellescape, exception: true)