From 4cb59eb8f90817c59a8b04258fbab9eedb4d4d74 Mon Sep 17 00:00:00 2001 From: Kitaiti Makoto Date: Thu, 26 Jun 2025 22:12:46 +0900 Subject: [PATCH 1/7] Add a test for segment --- bindings/ruby/test/test_segment.rb | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/bindings/ruby/test/test_segment.rb b/bindings/ruby/test/test_segment.rb index 5b63e0c4455..cb4ba9eb705 100644 --- a/bindings/ruby/test/test_segment.rb +++ b/bindings/ruby/test/test_segment.rb @@ -72,6 +72,16 @@ def test_on_new_segment_twice whisper.transcribe(AUDIO, params) end + def test_transcription_after_segment_retrieved + params = Whisper::Params.new + segment = whisper.each_segment.first + assert_match(/ask not what your country can do for you, ask what you can do for your country/, segment.text) + + whisper.transcribe(AUDIO, Whisper::Params.new(offset: 5000)) + assert_not_match(/ask not what your country can do for you, ask what you can do for your country/, segment.text) + assert_match(/what you can do for your country/i, segment.text) + end + def test_pattern_matching segment = whisper.each_segment.first segment => {start_time:, end_time:, text:, no_speech_prob:, speaker_turn_next:} From 4db42b289b98d685f186ba2933c87a9f0c378dd2 Mon Sep 17 00:00:00 2001 From: Kitaiti Makoto Date: Thu, 26 Jun 2025 22:15:24 +0900 Subject: [PATCH 2/7] Check option existence --- bindings/ruby/ext/options.rb | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/bindings/ruby/ext/options.rb b/bindings/ruby/ext/options.rb index 30cda0f8018..d37fcc686d3 100644 --- a/bindings/ruby/ext/options.rb +++ b/bindings/ruby/ext/options.rb @@ -73,10 +73,13 @@ def option_name(name) end def enabled?(option) - if @options[option][1].nil? + op = @options[option] + raise "Option not exist: #{option}" unless op + raise "Option not boolean: #{option}(#{op[0]})" unless op[0] == "BOOL" + if op[1].nil? cmake_options[option][1] else - @options[option][1] + op[1] end end end From 754f4c23fa0296eb645c2f592dd74e8bea4657e9 Mon Sep 17 00:00:00 2001 From: Kitaiti Makoto Date: Thu, 26 Jun 2025 22:16:10 +0900 Subject: [PATCH 3/7] Use more proper variable to define build option --- bindings/ruby/ext/options.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bindings/ruby/ext/options.rb b/bindings/ruby/ext/options.rb index d37fcc686d3..ede80c0656b 100644 --- a/bindings/ruby/ext/options.rb +++ b/bindings/ruby/ext/options.rb @@ -64,7 +64,7 @@ def configure_metal def configure_coreml if enabled?("WHISPER_COREML") $LDFLAGS << " -framework Foundation -framework CoreML" - $CPPFLAGS << " -DRUBY_WHISPER_USE_COREML" + $defs << "-DRUBY_WHISPER_USE_COREML" end end From af665e381b9e08b5e79f56ef9e74660cde1c5794 Mon Sep 17 00:00:00 2001 From: Kitaiti Makoto Date: Fri, 27 Jun 2025 01:13:43 +0900 Subject: [PATCH 4/7] Assert Core ML enabled --- bindings/ruby/test/test_package.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/bindings/ruby/test/test_package.rb b/bindings/ruby/test/test_package.rb index 33cd2a3c195..108f34efbeb 100644 --- a/bindings/ruby/test/test_package.rb +++ b/bindings/ruby/test/test_package.rb @@ -31,10 +31,11 @@ def test_install_with_coreml Dir.mktmpdir do |dir| system "gem", "install", "--install-dir", dir.shellescape, "--no-document", "pkg/#{gemspec.file_name.shellescape}", "--", "--enable-whisper-coreml", exception: true assert_installed dir, gemspec.version + libdir = File.join(dir, "gems", "#{gemspec.name}-#{gemspec.version}", "lib") assert_nothing_raised do - libdir = File.join(dir, "gems", "#{gemspec.name}-#{gemspec.version}", "lib") system "ruby", "-I", libdir, "-r", "whisper", "-e", "Whisper::Context.new('tiny')", exception: true end + assert_match(/COREML = 1/, `ruby -I #{libdir.shellescape} -r whisper -e 'puts Whisper.system_info_str'`) end end end From 7d264ca65636b75d6a30e005a7e6bf76e76c1b52 Mon Sep 17 00:00:00 2001 From: Kitaiti Makoto Date: Fri, 27 Jun 2025 01:17:40 +0900 Subject: [PATCH 5/7] Define Whisper::VERSION --- bindings/ruby/ext/ruby_whisper.c | 1 + 1 file changed, 1 insertion(+) diff --git a/bindings/ruby/ext/ruby_whisper.c b/bindings/ruby/ext/ruby_whisper.c index 35c196abb41..533bda74205 100644 --- a/bindings/ruby/ext/ruby_whisper.c +++ b/bindings/ruby/ext/ruby_whisper.c @@ -148,6 +148,7 @@ void Init_whisper() { mWhisper = rb_define_module("Whisper"); mVAD = rb_define_module_under(mWhisper, "VAD"); + rb_define_const(mWhisper, "VERSION", rb_str_new2(whisper_version())); rb_define_const(mWhisper, "LOG_LEVEL_NONE", INT2NUM(GGML_LOG_LEVEL_NONE)); rb_define_const(mWhisper, "LOG_LEVEL_INFO", INT2NUM(GGML_LOG_LEVEL_INFO)); rb_define_const(mWhisper, "LOG_LEVEL_WARN", INT2NUM(GGML_LOG_LEVEL_WARN)); From d63a4f38ee5da42cd770365da84f4f576f416346 Mon Sep 17 00:00:00 2001 From: Kitaiti Makoto Date: Fri, 27 Jun 2025 01:17:56 +0900 Subject: [PATCH 6/7] Add test for Whisper::VERSION --- bindings/ruby/test/test_whisper.rb | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/bindings/ruby/test/test_whisper.rb b/bindings/ruby/test/test_whisper.rb index e429c54317f..12b82a8de09 100644 --- a/bindings/ruby/test/test_whisper.rb +++ b/bindings/ruby/test/test_whisper.rb @@ -116,6 +116,10 @@ def test_system_info_str assert_match(/\AWHISPER : COREML = \d | OPENVINO = \d |/, Whisper.system_info_str) end + def test_version + assert_kind_of String, Whisper::VERSION + end + def test_log_set user_data = Object.new logs = [] From f036c8f18ded6f221d8320e010f2d9137b88ed40 Mon Sep 17 00:00:00 2001 From: Kitaiti Makoto Date: Fri, 27 Jun 2025 01:18:03 +0900 Subject: [PATCH 7/7] Add signature of Whisper::VERSION --- bindings/ruby/sig/whisper.rbs | 1 + 1 file changed, 1 insertion(+) diff --git a/bindings/ruby/sig/whisper.rbs b/bindings/ruby/sig/whisper.rbs index e6c0e139492..5966ce31592 100644 --- a/bindings/ruby/sig/whisper.rbs +++ b/bindings/ruby/sig/whisper.rbs @@ -10,6 +10,7 @@ module Whisper type encoder_begin_callback = ^(Whisper::Context, void, Object user_data) -> void type abort_callback = ^(Whisper::Context, void, Object user_data) -> boolish + VERSION: String LOG_LEVEL_NONE: Integer LOG_LEVEL_INFO: Integer LOG_LEVEL_WARN: Integer