]> git.djapps.eu Git - pkg/ggml/sources/whisper.cpp/commitdiff
ruby : add Whisper::VERSION (#3292)
authorKITAITI Makoto <redacted>
Fri, 27 Jun 2025 02:41:26 +0000 (11:41 +0900)
committerGitHub <redacted>
Fri, 27 Jun 2025 02:41:26 +0000 (04:41 +0200)
* Add a test for segment

* Check option existence

* Use more proper variable to define build option

* Assert Core ML enabled

* Define Whisper::VERSION

* Add test for Whisper::VERSION

* Add signature of Whisper::VERSION

bindings/ruby/ext/options.rb
bindings/ruby/ext/ruby_whisper.c
bindings/ruby/sig/whisper.rbs
bindings/ruby/test/test_package.rb
bindings/ruby/test/test_segment.rb
bindings/ruby/test/test_whisper.rb

index 30cda0f80188fa80faaf5001173e93673fb5d37c..ede80c0656b7390f545972c267c4e3bef0e557f1 100644 (file)
@@ -64,7 +64,7 @@ class Options
   def configure_coreml
     if enabled?("WHISPER_COREML")
       $LDFLAGS << " -framework Foundation -framework CoreML"
-      $CPPFLAGS << " -DRUBY_WHISPER_USE_COREML"
+      $defs << "-DRUBY_WHISPER_USE_COREML"
     end
   end
 
@@ -73,10 +73,13 @@ class Options
   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
index 35c196abb41330c3a1fd3cc21a14748333d68c02..533bda74205ced6c0a245f6ea0fea047f8d9f705 100644 (file)
@@ -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));
index e6c0e139492f9177989877cb6d258d99e493d5c1..5966ce315926da343fdaf0bf611e249f80c377ea 100644 (file)
@@ -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
index 33cd2a3c195752e7519103a5a44dde27ccc7d320..108f34efbebc7960543bb6769e0849a997f69d47 100644 (file)
@@ -31,10 +31,11 @@ class TestPackage < TestBase
         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
index 5b63e0c445592d6743df63b101b2ab032eb34cd4..cb4ba9eb705c8c72825553645d3678b721c9a486 100644 (file)
@@ -72,6 +72,16 @@ class TestSegment < TestBase
     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:}
index e429c54317f2328ec110797d0fbbb47b1591ee69..12b82a8de0984efa2ea3930adb108b8393d97f43 100644 (file)
@@ -116,6 +116,10 @@ class TestWhisper < TestBase
     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 = []