Spaces:
Sleeping
Sleeping
ruby : add Whisper::VERSION (#3292)
Browse files* 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
CHANGED
|
@@ -64,7 +64,7 @@ class Options
|
|
| 64 |
def configure_coreml
|
| 65 |
if enabled?("WHISPER_COREML")
|
| 66 |
$LDFLAGS << " -framework Foundation -framework CoreML"
|
| 67 |
-
$
|
| 68 |
end
|
| 69 |
end
|
| 70 |
|
|
@@ -73,10 +73,13 @@ class Options
|
|
| 73 |
end
|
| 74 |
|
| 75 |
def enabled?(option)
|
| 76 |
-
|
|
|
|
|
|
|
|
|
|
| 77 |
cmake_options[option][1]
|
| 78 |
else
|
| 79 |
-
|
| 80 |
end
|
| 81 |
end
|
| 82 |
end
|
|
|
|
| 64 |
def configure_coreml
|
| 65 |
if enabled?("WHISPER_COREML")
|
| 66 |
$LDFLAGS << " -framework Foundation -framework CoreML"
|
| 67 |
+
$defs << "-DRUBY_WHISPER_USE_COREML"
|
| 68 |
end
|
| 69 |
end
|
| 70 |
|
|
|
|
| 73 |
end
|
| 74 |
|
| 75 |
def enabled?(option)
|
| 76 |
+
op = @options[option]
|
| 77 |
+
raise "Option not exist: #{option}" unless op
|
| 78 |
+
raise "Option not boolean: #{option}(#{op[0]})" unless op[0] == "BOOL"
|
| 79 |
+
if op[1].nil?
|
| 80 |
cmake_options[option][1]
|
| 81 |
else
|
| 82 |
+
op[1]
|
| 83 |
end
|
| 84 |
end
|
| 85 |
end
|
bindings/ruby/ext/ruby_whisper.c
CHANGED
|
@@ -148,6 +148,7 @@ void Init_whisper() {
|
|
| 148 |
mWhisper = rb_define_module("Whisper");
|
| 149 |
mVAD = rb_define_module_under(mWhisper, "VAD");
|
| 150 |
|
|
|
|
| 151 |
rb_define_const(mWhisper, "LOG_LEVEL_NONE", INT2NUM(GGML_LOG_LEVEL_NONE));
|
| 152 |
rb_define_const(mWhisper, "LOG_LEVEL_INFO", INT2NUM(GGML_LOG_LEVEL_INFO));
|
| 153 |
rb_define_const(mWhisper, "LOG_LEVEL_WARN", INT2NUM(GGML_LOG_LEVEL_WARN));
|
|
|
|
| 148 |
mWhisper = rb_define_module("Whisper");
|
| 149 |
mVAD = rb_define_module_under(mWhisper, "VAD");
|
| 150 |
|
| 151 |
+
rb_define_const(mWhisper, "VERSION", rb_str_new2(whisper_version()));
|
| 152 |
rb_define_const(mWhisper, "LOG_LEVEL_NONE", INT2NUM(GGML_LOG_LEVEL_NONE));
|
| 153 |
rb_define_const(mWhisper, "LOG_LEVEL_INFO", INT2NUM(GGML_LOG_LEVEL_INFO));
|
| 154 |
rb_define_const(mWhisper, "LOG_LEVEL_WARN", INT2NUM(GGML_LOG_LEVEL_WARN));
|
bindings/ruby/sig/whisper.rbs
CHANGED
|
@@ -10,6 +10,7 @@ module Whisper
|
|
| 10 |
type encoder_begin_callback = ^(Whisper::Context, void, Object user_data) -> void
|
| 11 |
type abort_callback = ^(Whisper::Context, void, Object user_data) -> boolish
|
| 12 |
|
|
|
|
| 13 |
LOG_LEVEL_NONE: Integer
|
| 14 |
LOG_LEVEL_INFO: Integer
|
| 15 |
LOG_LEVEL_WARN: Integer
|
|
|
|
| 10 |
type encoder_begin_callback = ^(Whisper::Context, void, Object user_data) -> void
|
| 11 |
type abort_callback = ^(Whisper::Context, void, Object user_data) -> boolish
|
| 12 |
|
| 13 |
+
VERSION: String
|
| 14 |
LOG_LEVEL_NONE: Integer
|
| 15 |
LOG_LEVEL_INFO: Integer
|
| 16 |
LOG_LEVEL_WARN: Integer
|
bindings/ruby/test/test_package.rb
CHANGED
|
@@ -31,10 +31,11 @@ class TestPackage < TestBase
|
|
| 31 |
Dir.mktmpdir do |dir|
|
| 32 |
system "gem", "install", "--install-dir", dir.shellescape, "--no-document", "pkg/#{gemspec.file_name.shellescape}", "--", "--enable-whisper-coreml", exception: true
|
| 33 |
assert_installed dir, gemspec.version
|
|
|
|
| 34 |
assert_nothing_raised do
|
| 35 |
-
libdir = File.join(dir, "gems", "#{gemspec.name}-#{gemspec.version}", "lib")
|
| 36 |
system "ruby", "-I", libdir, "-r", "whisper", "-e", "Whisper::Context.new('tiny')", exception: true
|
| 37 |
end
|
|
|
|
| 38 |
end
|
| 39 |
end
|
| 40 |
end
|
|
|
|
| 31 |
Dir.mktmpdir do |dir|
|
| 32 |
system "gem", "install", "--install-dir", dir.shellescape, "--no-document", "pkg/#{gemspec.file_name.shellescape}", "--", "--enable-whisper-coreml", exception: true
|
| 33 |
assert_installed dir, gemspec.version
|
| 34 |
+
libdir = File.join(dir, "gems", "#{gemspec.name}-#{gemspec.version}", "lib")
|
| 35 |
assert_nothing_raised do
|
|
|
|
| 36 |
system "ruby", "-I", libdir, "-r", "whisper", "-e", "Whisper::Context.new('tiny')", exception: true
|
| 37 |
end
|
| 38 |
+
assert_match(/COREML = 1/, `ruby -I #{libdir.shellescape} -r whisper -e 'puts Whisper.system_info_str'`)
|
| 39 |
end
|
| 40 |
end
|
| 41 |
end
|
bindings/ruby/test/test_segment.rb
CHANGED
|
@@ -72,6 +72,16 @@ class TestSegment < TestBase
|
|
| 72 |
whisper.transcribe(AUDIO, params)
|
| 73 |
end
|
| 74 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 75 |
def test_pattern_matching
|
| 76 |
segment = whisper.each_segment.first
|
| 77 |
segment => {start_time:, end_time:, text:, no_speech_prob:, speaker_turn_next:}
|
|
|
|
| 72 |
whisper.transcribe(AUDIO, params)
|
| 73 |
end
|
| 74 |
|
| 75 |
+
def test_transcription_after_segment_retrieved
|
| 76 |
+
params = Whisper::Params.new
|
| 77 |
+
segment = whisper.each_segment.first
|
| 78 |
+
assert_match(/ask not what your country can do for you, ask what you can do for your country/, segment.text)
|
| 79 |
+
|
| 80 |
+
whisper.transcribe(AUDIO, Whisper::Params.new(offset: 5000))
|
| 81 |
+
assert_not_match(/ask not what your country can do for you, ask what you can do for your country/, segment.text)
|
| 82 |
+
assert_match(/what you can do for your country/i, segment.text)
|
| 83 |
+
end
|
| 84 |
+
|
| 85 |
def test_pattern_matching
|
| 86 |
segment = whisper.each_segment.first
|
| 87 |
segment => {start_time:, end_time:, text:, no_speech_prob:, speaker_turn_next:}
|
bindings/ruby/test/test_whisper.rb
CHANGED
|
@@ -116,6 +116,10 @@ class TestWhisper < TestBase
|
|
| 116 |
assert_match(/\AWHISPER : COREML = \d | OPENVINO = \d |/, Whisper.system_info_str)
|
| 117 |
end
|
| 118 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 119 |
def test_log_set
|
| 120 |
user_data = Object.new
|
| 121 |
logs = []
|
|
|
|
| 116 |
assert_match(/\AWHISPER : COREML = \d | OPENVINO = \d |/, Whisper.system_info_str)
|
| 117 |
end
|
| 118 |
|
| 119 |
+
def test_version
|
| 120 |
+
assert_kind_of String, Whisper::VERSION
|
| 121 |
+
end
|
| 122 |
+
|
| 123 |
def test_log_set
|
| 124 |
user_data = Object.new
|
| 125 |
logs = []
|