whispercpp 1.3.0 → 1.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.gitignore +5 -0
- data/LICENSE +1 -1
- data/README.md +165 -434
- data/Rakefile +60 -11
- data/ext/.gitignore +13 -0
- data/ext/cpu.mk +9 -0
- data/ext/{dr_wav.h → examples/dr_wav.h} +3560 -1179
- data/ext/extconf.rb +185 -16
- data/ext/ggml/include/ggml-alloc.h +76 -0
- data/ext/ggml/include/ggml-backend.h +352 -0
- data/ext/ggml/include/ggml-blas.h +25 -0
- data/ext/ggml/include/ggml-cann.h +123 -0
- data/ext/ggml/include/ggml-cpp.h +38 -0
- data/ext/ggml/include/ggml-cpu.h +135 -0
- data/ext/ggml/include/ggml-cuda.h +47 -0
- data/ext/ggml/include/ggml-kompute.h +50 -0
- data/ext/ggml/include/ggml-metal.h +66 -0
- data/ext/ggml/include/ggml-opencl.h +26 -0
- data/ext/ggml/include/ggml-opt.h +216 -0
- data/ext/ggml/include/ggml-rpc.h +28 -0
- data/ext/ggml/include/ggml-sycl.h +49 -0
- data/ext/ggml/include/ggml-vulkan.h +31 -0
- data/ext/{ggml.h → ggml/include/ggml.h} +479 -596
- data/ext/ggml/src/ggml-alloc.c +1037 -0
- data/ext/ggml/src/ggml-amx/common.h +94 -0
- data/ext/ggml/src/ggml-amx/ggml-amx.cpp +446 -0
- data/ext/ggml/src/ggml-amx/mmq.cpp +2510 -0
- data/ext/ggml/src/ggml-amx/mmq.h +17 -0
- data/ext/ggml/src/ggml-backend-impl.h +256 -0
- data/ext/ggml/src/ggml-backend-reg.cpp +552 -0
- data/ext/ggml/src/ggml-backend.cpp +1999 -0
- data/ext/ggml/src/ggml-blas/ggml-blas.cpp +517 -0
- data/ext/ggml/src/ggml-cann/acl_tensor.cpp +175 -0
- data/ext/ggml/src/ggml-cann/acl_tensor.h +258 -0
- data/ext/ggml/src/ggml-cann/aclnn_ops.cpp +3427 -0
- data/ext/ggml/src/ggml-cann/aclnn_ops.h +592 -0
- data/ext/ggml/src/ggml-cann/common.h +286 -0
- data/ext/ggml/src/ggml-cann/ggml-cann.cpp +2188 -0
- data/ext/ggml/src/ggml-cann/kernels/ascendc_kernels.h +19 -0
- data/ext/ggml/src/ggml-cann/kernels/dup.cpp +236 -0
- data/ext/ggml/src/ggml-cann/kernels/get_row_f16.cpp +197 -0
- data/ext/ggml/src/ggml-cann/kernels/get_row_f32.cpp +190 -0
- data/ext/ggml/src/ggml-cann/kernels/get_row_q4_0.cpp +204 -0
- data/ext/ggml/src/ggml-cann/kernels/get_row_q8_0.cpp +191 -0
- data/ext/ggml/src/ggml-cann/kernels/quantize_f16_q8_0.cpp +218 -0
- data/ext/ggml/src/ggml-cann/kernels/quantize_f32_q8_0.cpp +216 -0
- data/ext/ggml/src/ggml-cann/kernels/quantize_float_to_q4_0.cpp +295 -0
- data/ext/ggml/src/ggml-common.h +1853 -0
- data/ext/ggml/src/ggml-cpu/amx/amx.cpp +220 -0
- data/ext/ggml/src/ggml-cpu/amx/amx.h +8 -0
- data/ext/ggml/src/ggml-cpu/amx/common.h +91 -0
- data/ext/ggml/src/ggml-cpu/amx/mmq.cpp +2511 -0
- data/ext/ggml/src/ggml-cpu/amx/mmq.h +10 -0
- data/ext/ggml/src/ggml-cpu/cpu-feats-x86.cpp +323 -0
- data/ext/ggml/src/ggml-cpu/ggml-cpu-aarch64.cpp +4262 -0
- data/ext/ggml/src/ggml-cpu/ggml-cpu-aarch64.h +8 -0
- data/ext/ggml/src/ggml-cpu/ggml-cpu-hbm.cpp +55 -0
- data/ext/ggml/src/ggml-cpu/ggml-cpu-hbm.h +8 -0
- data/ext/ggml/src/ggml-cpu/ggml-cpu-impl.h +386 -0
- data/ext/ggml/src/ggml-cpu/ggml-cpu-quants.c +10835 -0
- data/ext/ggml/src/ggml-cpu/ggml-cpu-quants.h +63 -0
- data/ext/ggml/src/ggml-cpu/ggml-cpu-traits.cpp +36 -0
- data/ext/ggml/src/ggml-cpu/ggml-cpu-traits.h +38 -0
- data/ext/ggml/src/ggml-cpu/ggml-cpu.c +14123 -0
- data/ext/ggml/src/ggml-cpu/ggml-cpu.cpp +622 -0
- data/ext/ggml/src/ggml-cpu/llamafile/sgemm.cpp +1884 -0
- data/ext/ggml/src/ggml-cpu/llamafile/sgemm.h +14 -0
- data/ext/ggml/src/ggml-cuda/vendors/cuda.h +14 -0
- data/ext/ggml/src/ggml-cuda/vendors/hip.h +186 -0
- data/ext/ggml/src/ggml-cuda/vendors/musa.h +134 -0
- data/ext/ggml/src/ggml-impl.h +556 -0
- data/ext/ggml/src/ggml-kompute/ggml-kompute.cpp +2251 -0
- data/ext/ggml/src/ggml-metal/ggml-metal-impl.h +288 -0
- data/ext/ggml/src/ggml-metal/ggml-metal.m +4884 -0
- data/ext/ggml/src/ggml-metal/ggml-metal.metal +6732 -0
- data/ext/ggml/src/ggml-opt.cpp +854 -0
- data/ext/ggml/src/ggml-quants.c +5238 -0
- data/ext/ggml/src/ggml-quants.h +100 -0
- data/ext/ggml/src/ggml-rpc/ggml-rpc.cpp +1406 -0
- data/ext/ggml/src/ggml-sycl/common.cpp +95 -0
- data/ext/ggml/src/ggml-sycl/concat.cpp +196 -0
- data/ext/ggml/src/ggml-sycl/conv.cpp +99 -0
- data/ext/ggml/src/ggml-sycl/convert.cpp +547 -0
- data/ext/ggml/src/ggml-sycl/dmmv.cpp +1023 -0
- data/ext/ggml/src/ggml-sycl/element_wise.cpp +1030 -0
- data/ext/ggml/src/ggml-sycl/ggml-sycl.cpp +4729 -0
- data/ext/ggml/src/ggml-sycl/im2col.cpp +126 -0
- data/ext/ggml/src/ggml-sycl/mmq.cpp +3031 -0
- data/ext/ggml/src/ggml-sycl/mmvq.cpp +1015 -0
- data/ext/ggml/src/ggml-sycl/norm.cpp +378 -0
- data/ext/ggml/src/ggml-sycl/outprod.cpp +56 -0
- data/ext/ggml/src/ggml-sycl/rope.cpp +276 -0
- data/ext/ggml/src/ggml-sycl/softmax.cpp +251 -0
- data/ext/ggml/src/ggml-sycl/tsembd.cpp +72 -0
- data/ext/ggml/src/ggml-sycl/wkv6.cpp +141 -0
- data/ext/ggml/src/ggml-threading.cpp +12 -0
- data/ext/ggml/src/ggml-threading.h +14 -0
- data/ext/ggml/src/ggml-vulkan/ggml-vulkan.cpp +8657 -0
- data/ext/ggml/src/ggml-vulkan/vulkan-shaders/vulkan-shaders-gen.cpp +593 -0
- data/ext/ggml/src/ggml.c +7694 -0
- data/ext/{whisper.h → include/whisper.h} +23 -22
- data/ext/metal-embed.mk +17 -0
- data/ext/metal.mk +6 -0
- data/ext/ruby_whisper.cpp +1492 -9
- data/ext/ruby_whisper.h +10 -0
- data/ext/scripts/get-flags.mk +38 -0
- data/ext/src/coreml/whisper-decoder-impl.h +146 -0
- data/ext/src/coreml/whisper-decoder-impl.m +201 -0
- data/ext/src/coreml/whisper-encoder-impl.h +142 -0
- data/ext/src/coreml/whisper-encoder-impl.m +197 -0
- data/ext/src/coreml/whisper-encoder.h +26 -0
- data/ext/src/openvino/whisper-openvino-encoder.cpp +108 -0
- data/ext/src/openvino/whisper-openvino-encoder.h +31 -0
- data/ext/{whisper.cpp → src/whisper.cpp} +661 -492
- data/extsources.rb +6 -0
- data/lib/whisper/model/uri.rb +157 -0
- data/lib/whisper.rb +2 -0
- data/tests/helper.rb +7 -0
- data/tests/jfk_reader/.gitignore +5 -0
- data/tests/jfk_reader/extconf.rb +3 -0
- data/tests/jfk_reader/jfk_reader.c +68 -0
- data/tests/test_callback.rb +160 -0
- data/tests/test_error.rb +20 -0
- data/tests/test_model.rb +71 -0
- data/tests/test_package.rb +31 -0
- data/tests/test_params.rb +160 -0
- data/tests/test_segment.rb +83 -0
- data/tests/test_whisper.rb +211 -123
- data/whispercpp.gemspec +36 -0
- metadata +137 -11
- data/ext/ggml.c +0 -21755
@@ -0,0 +1,83 @@
|
|
1
|
+
require_relative "helper"
|
2
|
+
|
3
|
+
class TestSegment < TestBase
|
4
|
+
class << self
|
5
|
+
attr_reader :whisper
|
6
|
+
|
7
|
+
def startup
|
8
|
+
@whisper = Whisper::Context.new("base.en")
|
9
|
+
params = Whisper::Params.new
|
10
|
+
params.print_timestamps = false
|
11
|
+
@whisper.transcribe(TestBase::AUDIO, params)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
def test_iteration
|
16
|
+
whisper.each_segment do |segment|
|
17
|
+
assert_instance_of Whisper::Segment, segment
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def test_enumerator
|
22
|
+
enum = whisper.each_segment
|
23
|
+
assert_instance_of Enumerator, enum
|
24
|
+
enum.to_a.each_with_index do |segment, index|
|
25
|
+
assert_instance_of Whisper::Segment, segment
|
26
|
+
assert_kind_of Integer, index
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
def test_start_time
|
31
|
+
i = 0
|
32
|
+
whisper.each_segment do |segment|
|
33
|
+
assert_equal 0, segment.start_time if i == 0
|
34
|
+
i += 1
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
def test_end_time
|
39
|
+
i = 0
|
40
|
+
whisper.each_segment do |segment|
|
41
|
+
assert_equal whisper.full_get_segment_t1(i) * 10, segment.end_time
|
42
|
+
i += 1
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
def test_on_new_segment
|
47
|
+
params = Whisper::Params.new
|
48
|
+
seg = nil
|
49
|
+
index = 0
|
50
|
+
params.on_new_segment do |segment|
|
51
|
+
assert_instance_of Whisper::Segment, segment
|
52
|
+
if index == 0
|
53
|
+
seg = segment
|
54
|
+
assert_equal 0, segment.start_time
|
55
|
+
assert_match /ask not what your country can do for you, ask what you can do for your country/, segment.text
|
56
|
+
end
|
57
|
+
index += 1
|
58
|
+
end
|
59
|
+
whisper.transcribe(AUDIO, params)
|
60
|
+
assert_equal 0, seg.start_time
|
61
|
+
assert_match /ask not what your country can do for you, ask what you can do for your country/, seg.text
|
62
|
+
end
|
63
|
+
|
64
|
+
def test_on_new_segment_twice
|
65
|
+
params = Whisper::Params.new
|
66
|
+
seg = nil
|
67
|
+
params.on_new_segment do |segment|
|
68
|
+
seg = segment
|
69
|
+
return
|
70
|
+
end
|
71
|
+
params.on_new_segment do |segment|
|
72
|
+
assert_same seg, segment
|
73
|
+
return
|
74
|
+
end
|
75
|
+
whisper.transcribe(AUDIO, params)
|
76
|
+
end
|
77
|
+
|
78
|
+
private
|
79
|
+
|
80
|
+
def whisper
|
81
|
+
self.class.whisper
|
82
|
+
end
|
83
|
+
end
|
data/tests/test_whisper.rb
CHANGED
@@ -1,138 +1,226 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
#$:.unshift(LIBDIR)
|
5
|
-
$:.unshift(EXTDIR)
|
1
|
+
require_relative "helper"
|
2
|
+
require "stringio"
|
3
|
+
require "etc"
|
6
4
|
|
7
|
-
|
8
|
-
|
5
|
+
# Exists to detect memory-related bug
|
6
|
+
Whisper.log_set ->(level, buffer, user_data) {}, nil
|
9
7
|
|
10
|
-
class TestWhisper <
|
8
|
+
class TestWhisper < TestBase
|
11
9
|
def setup
|
12
10
|
@params = Whisper::Params.new
|
13
11
|
end
|
14
12
|
|
15
|
-
def test_language
|
16
|
-
@params.language = "en"
|
17
|
-
assert_equal @params.language, "en"
|
18
|
-
@params.language = "auto"
|
19
|
-
assert_equal @params.language, "auto"
|
20
|
-
end
|
21
|
-
|
22
|
-
def test_offset
|
23
|
-
@params.offset = 10_000
|
24
|
-
assert_equal @params.offset, 10_000
|
25
|
-
@params.offset = 0
|
26
|
-
assert_equal @params.offset, 0
|
27
|
-
end
|
28
|
-
|
29
|
-
def test_duration
|
30
|
-
@params.duration = 60_000
|
31
|
-
assert_equal @params.duration, 60_000
|
32
|
-
@params.duration = 0
|
33
|
-
assert_equal @params.duration, 0
|
34
|
-
end
|
35
|
-
|
36
|
-
def test_max_text_tokens
|
37
|
-
@params.max_text_tokens = 300
|
38
|
-
assert_equal @params.max_text_tokens, 300
|
39
|
-
@params.max_text_tokens = 0
|
40
|
-
assert_equal @params.max_text_tokens, 0
|
41
|
-
end
|
42
|
-
|
43
|
-
def test_translate
|
44
|
-
@params.translate = true
|
45
|
-
assert @params.translate
|
46
|
-
@params.translate = false
|
47
|
-
assert !@params.translate
|
48
|
-
end
|
49
|
-
|
50
|
-
def test_no_context
|
51
|
-
@params.no_context = true
|
52
|
-
assert @params.no_context
|
53
|
-
@params.no_context = false
|
54
|
-
assert !@params.no_context
|
55
|
-
end
|
56
|
-
|
57
|
-
def test_single_segment
|
58
|
-
@params.single_segment = true
|
59
|
-
assert @params.single_segment
|
60
|
-
@params.single_segment = false
|
61
|
-
assert !@params.single_segment
|
62
|
-
end
|
63
|
-
|
64
|
-
def test_print_special
|
65
|
-
@params.print_special = true
|
66
|
-
assert @params.print_special
|
67
|
-
@params.print_special = false
|
68
|
-
assert !@params.print_special
|
69
|
-
end
|
70
|
-
|
71
|
-
def test_print_progress
|
72
|
-
@params.print_progress = true
|
73
|
-
assert @params.print_progress
|
74
|
-
@params.print_progress = false
|
75
|
-
assert !@params.print_progress
|
76
|
-
end
|
77
|
-
|
78
|
-
def test_print_realtime
|
79
|
-
@params.print_realtime = true
|
80
|
-
assert @params.print_realtime
|
81
|
-
@params.print_realtime = false
|
82
|
-
assert !@params.print_realtime
|
83
|
-
end
|
84
|
-
|
85
|
-
def test_print_timestamps
|
86
|
-
@params.print_timestamps = true
|
87
|
-
assert @params.print_timestamps
|
88
|
-
@params.print_timestamps = false
|
89
|
-
assert !@params.print_timestamps
|
90
|
-
end
|
91
|
-
|
92
|
-
def test_suppress_blank
|
93
|
-
@params.suppress_blank = true
|
94
|
-
assert @params.suppress_blank
|
95
|
-
@params.suppress_blank = false
|
96
|
-
assert !@params.suppress_blank
|
97
|
-
end
|
98
|
-
|
99
|
-
def test_suppress_non_speech_tokens
|
100
|
-
@params.suppress_non_speech_tokens = true
|
101
|
-
assert @params.suppress_non_speech_tokens
|
102
|
-
@params.suppress_non_speech_tokens = false
|
103
|
-
assert !@params.suppress_non_speech_tokens
|
104
|
-
end
|
105
|
-
|
106
|
-
def test_token_timestamps
|
107
|
-
@params.token_timestamps = true
|
108
|
-
assert @params.token_timestamps
|
109
|
-
@params.token_timestamps = false
|
110
|
-
assert !@params.token_timestamps
|
111
|
-
end
|
112
|
-
|
113
|
-
def test_split_on_word
|
114
|
-
@params.split_on_word = true
|
115
|
-
assert @params.split_on_word
|
116
|
-
@params.split_on_word = false
|
117
|
-
assert !@params.split_on_word
|
118
|
-
end
|
119
|
-
|
120
|
-
def test_speed_up
|
121
|
-
@params.speed_up = true
|
122
|
-
assert @params.speed_up
|
123
|
-
@params.speed_up = false
|
124
|
-
assert !@params.speed_up
|
125
|
-
end
|
126
|
-
|
127
13
|
def test_whisper
|
128
|
-
@whisper = Whisper::Context.new(
|
14
|
+
@whisper = Whisper::Context.new("base.en")
|
129
15
|
params = Whisper::Params.new
|
130
16
|
params.print_timestamps = false
|
131
17
|
|
132
|
-
|
133
|
-
@whisper.transcribe(jfk, params) {|text|
|
18
|
+
@whisper.transcribe(AUDIO, params) {|text|
|
134
19
|
assert_match /ask not what your country can do for you, ask what you can do for your country/, text
|
135
20
|
}
|
136
21
|
end
|
137
22
|
|
23
|
+
sub_test_case "After transcription" do
|
24
|
+
class << self
|
25
|
+
attr_reader :whisper
|
26
|
+
|
27
|
+
def startup
|
28
|
+
@whisper = Whisper::Context.new("base.en")
|
29
|
+
params = Whisper::Params.new
|
30
|
+
params.print_timestamps = false
|
31
|
+
@whisper.transcribe(TestBase::AUDIO, params)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
def whisper
|
36
|
+
self.class.whisper
|
37
|
+
end
|
38
|
+
|
39
|
+
def test_full_n_segments
|
40
|
+
assert_equal 1, whisper.full_n_segments
|
41
|
+
end
|
42
|
+
|
43
|
+
def test_full_lang_id
|
44
|
+
assert_equal 0, whisper.full_lang_id
|
45
|
+
end
|
46
|
+
|
47
|
+
def test_full_get_segment_t0
|
48
|
+
assert_equal 0, whisper.full_get_segment_t0(0)
|
49
|
+
assert_raise IndexError do
|
50
|
+
whisper.full_get_segment_t0(whisper.full_n_segments)
|
51
|
+
end
|
52
|
+
assert_raise IndexError do
|
53
|
+
whisper.full_get_segment_t0(-1)
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
def test_full_get_segment_t1
|
58
|
+
t1 = whisper.full_get_segment_t1(0)
|
59
|
+
assert_kind_of Integer, t1
|
60
|
+
assert t1 > 0
|
61
|
+
assert_raise IndexError do
|
62
|
+
whisper.full_get_segment_t1(whisper.full_n_segments)
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
def test_full_get_segment_speaker_turn_next
|
67
|
+
assert_false whisper.full_get_segment_speaker_turn_next(0)
|
68
|
+
end
|
69
|
+
|
70
|
+
def test_full_get_segment_text
|
71
|
+
assert_match /ask not what your country can do for you, ask what you can do for your country/, whisper.full_get_segment_text(0)
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
def test_lang_max_id
|
76
|
+
assert_kind_of Integer, Whisper.lang_max_id
|
77
|
+
end
|
78
|
+
|
79
|
+
def test_lang_id
|
80
|
+
assert_equal 0, Whisper.lang_id("en")
|
81
|
+
assert_raise ArgumentError do
|
82
|
+
Whisper.lang_id("non existing language")
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
def test_lang_str
|
87
|
+
assert_equal "en", Whisper.lang_str(0)
|
88
|
+
assert_raise IndexError do
|
89
|
+
Whisper.lang_str(Whisper.lang_max_id + 1)
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
def test_lang_str_full
|
94
|
+
assert_equal "english", Whisper.lang_str_full(0)
|
95
|
+
assert_raise IndexError do
|
96
|
+
Whisper.lang_str_full(Whisper.lang_max_id + 1)
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
def test_log_set
|
101
|
+
user_data = Object.new
|
102
|
+
logs = []
|
103
|
+
log_callback = ->(level, buffer, udata) {
|
104
|
+
logs << [level, buffer, udata]
|
105
|
+
}
|
106
|
+
Whisper.log_set log_callback, user_data
|
107
|
+
Whisper::Context.new("base.en")
|
108
|
+
|
109
|
+
assert logs.length > 30
|
110
|
+
logs.each do |log|
|
111
|
+
assert_include [Whisper::LOG_LEVEL_DEBUG, Whisper::LOG_LEVEL_INFO, Whisper::LOG_LEVEL_WARN], log[0]
|
112
|
+
assert_same user_data, log[2]
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
116
|
+
def test_log_suppress
|
117
|
+
stderr = $stderr
|
118
|
+
Whisper.log_set ->(level, buffer, user_data) {
|
119
|
+
# do nothing
|
120
|
+
}, nil
|
121
|
+
dev = StringIO.new("")
|
122
|
+
$stderr = dev
|
123
|
+
Whisper::Context.new("base.en")
|
124
|
+
assert_empty dev.string
|
125
|
+
ensure
|
126
|
+
$stderr = stderr
|
127
|
+
end
|
128
|
+
|
129
|
+
sub_test_case "full" do
|
130
|
+
def setup
|
131
|
+
super
|
132
|
+
@whisper = Whisper::Context.new("base.en")
|
133
|
+
@samples = File.read(AUDIO, nil, 78).unpack("s<*").collect {|i| i.to_f / 2**15}
|
134
|
+
end
|
135
|
+
|
136
|
+
def test_full
|
137
|
+
@whisper.full(@params, @samples, @samples.length)
|
138
|
+
|
139
|
+
assert_equal 1, @whisper.full_n_segments
|
140
|
+
assert_match /ask not what your country can do for you, ask what you can do for your country/, @whisper.each_segment.first.text
|
141
|
+
end
|
142
|
+
|
143
|
+
def test_full_without_length
|
144
|
+
@whisper.full(@params, @samples)
|
145
|
+
|
146
|
+
assert_equal 1, @whisper.full_n_segments
|
147
|
+
assert_match /ask not what your country can do for you, ask what you can do for your country/, @whisper.each_segment.first.text
|
148
|
+
end
|
149
|
+
|
150
|
+
def test_full_enumerator
|
151
|
+
samples = @samples.each
|
152
|
+
@whisper.full(@params, samples, @samples.length)
|
153
|
+
|
154
|
+
assert_equal 1, @whisper.full_n_segments
|
155
|
+
assert_match /ask not what your country can do for you, ask what you can do for your country/, @whisper.each_segment.first.text
|
156
|
+
end
|
157
|
+
|
158
|
+
def test_full_enumerator_without_length
|
159
|
+
samples = @samples.each
|
160
|
+
assert_raise ArgumentError do
|
161
|
+
@whisper.full(@params, samples)
|
162
|
+
end
|
163
|
+
end
|
164
|
+
|
165
|
+
def test_full_enumerator_with_too_large_length
|
166
|
+
samples = @samples.each.take(10).to_enum
|
167
|
+
assert_raise StopIteration do
|
168
|
+
@whisper.full(@params, samples, 11)
|
169
|
+
end
|
170
|
+
end
|
171
|
+
|
172
|
+
def test_full_with_memory_view
|
173
|
+
samples = JFKReader.new(AUDIO)
|
174
|
+
@whisper.full(@params, samples)
|
175
|
+
|
176
|
+
assert_equal 1, @whisper.full_n_segments
|
177
|
+
assert_match /ask not what your country can do for you, ask what you can do for your country/, @whisper.each_segment.first.text
|
178
|
+
end
|
179
|
+
|
180
|
+
def test_full_parallel
|
181
|
+
@whisper.full_parallel(@params, @samples, @samples.length, Etc.nprocessors)
|
182
|
+
|
183
|
+
assert_equal Etc.nprocessors, @whisper.full_n_segments
|
184
|
+
text = @whisper.each_segment.collect(&:text).join
|
185
|
+
assert_match /ask what you can do/i, text
|
186
|
+
assert_match /for your country/i, text
|
187
|
+
end
|
188
|
+
|
189
|
+
def test_full_parallel_with_memory_view
|
190
|
+
samples = JFKReader.new(AUDIO)
|
191
|
+
@whisper.full_parallel(@params, samples, nil, Etc.nprocessors)
|
192
|
+
|
193
|
+
assert_equal Etc.nprocessors, @whisper.full_n_segments
|
194
|
+
text = @whisper.each_segment.collect(&:text).join
|
195
|
+
assert_match /ask what you can do/i, text
|
196
|
+
assert_match /for your country/i, text
|
197
|
+
end
|
198
|
+
|
199
|
+
def test_full_parallel_without_length_and_n_processors
|
200
|
+
@whisper.full_parallel(@params, @samples)
|
201
|
+
|
202
|
+
assert_equal 1, @whisper.full_n_segments
|
203
|
+
text = @whisper.each_segment.collect(&:text).join
|
204
|
+
assert_match /ask what you can do/i, text
|
205
|
+
assert_match /for your country/i, text
|
206
|
+
end
|
207
|
+
|
208
|
+
def test_full_parallel_without_length
|
209
|
+
@whisper.full_parallel(@params, @samples, nil, Etc.nprocessors)
|
210
|
+
|
211
|
+
assert_equal Etc.nprocessors, @whisper.full_n_segments
|
212
|
+
text = @whisper.each_segment.collect(&:text).join
|
213
|
+
assert_match /ask what you can do/i, text
|
214
|
+
assert_match /for your country/i, text
|
215
|
+
end
|
216
|
+
|
217
|
+
def test_full_parallel_without_n_processors
|
218
|
+
@whisper.full_parallel(@params, @samples, @samples.length)
|
219
|
+
|
220
|
+
assert_equal 1, @whisper.full_n_segments
|
221
|
+
text = @whisper.each_segment.collect(&:text).join
|
222
|
+
assert_match /ask what you can do/i, text
|
223
|
+
assert_match /for your country/i, text
|
224
|
+
end
|
225
|
+
end
|
138
226
|
end
|
data/whispercpp.gemspec
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
require_relative "extsources"
|
2
|
+
|
3
|
+
Gem::Specification.new do |s|
|
4
|
+
s.name = "whispercpp"
|
5
|
+
s.authors = ["Georgi Gerganov", "Todd A. Fisher"]
|
6
|
+
s.version = '1.3.1'
|
7
|
+
s.date = '2024-12-19'
|
8
|
+
s.description = %q{High-performance inference of OpenAI's Whisper automatic speech recognition (ASR) model via Ruby}
|
9
|
+
s.email = 'todd.fisher@gmail.com'
|
10
|
+
s.extra_rdoc_files = ['LICENSE', 'README.md']
|
11
|
+
|
12
|
+
s.files = `git ls-files . -z`.split("\x0") +
|
13
|
+
EXTSOURCES.collect {|file|
|
14
|
+
basename = File.basename(file)
|
15
|
+
if s.extra_rdoc_files.include?(basename)
|
16
|
+
basename
|
17
|
+
else
|
18
|
+
file.sub("../..", "ext")
|
19
|
+
end
|
20
|
+
}
|
21
|
+
|
22
|
+
s.summary = %q{Ruby whisper.cpp bindings}
|
23
|
+
s.test_files = s.files.select {|file| file.start_with? "tests/"}
|
24
|
+
|
25
|
+
s.extensions << 'ext/extconf.rb'
|
26
|
+
s.required_ruby_version = '>= 3.1.0'
|
27
|
+
|
28
|
+
#### Documentation and testing.
|
29
|
+
s.homepage = 'https://github.com/ggerganov/whisper.cpp'
|
30
|
+
s.rdoc_options = ['--main', 'README.md']
|
31
|
+
|
32
|
+
|
33
|
+
s.platform = Gem::Platform::RUBY
|
34
|
+
|
35
|
+
s.licenses = ['MIT']
|
36
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: whispercpp
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.3.
|
4
|
+
version: 1.3.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Georgi Gerganov
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2024-
|
12
|
+
date: 2024-12-19 00:00:00.000000000 Z
|
13
13
|
dependencies: []
|
14
14
|
description: High-performance inference of OpenAI's Whisper automatic speech recognition
|
15
15
|
(ASR) model via Ruby
|
@@ -21,18 +21,135 @@ extra_rdoc_files:
|
|
21
21
|
- LICENSE
|
22
22
|
- README.md
|
23
23
|
files:
|
24
|
+
- ".gitignore"
|
24
25
|
- LICENSE
|
25
26
|
- README.md
|
26
27
|
- Rakefile
|
27
|
-
- ext
|
28
|
+
- ext/.gitignore
|
29
|
+
- ext/cpu.mk
|
30
|
+
- ext/examples/dr_wav.h
|
28
31
|
- ext/extconf.rb
|
29
|
-
- ext/ggml.
|
30
|
-
- ext/ggml.h
|
32
|
+
- ext/ggml/include/ggml-alloc.h
|
33
|
+
- ext/ggml/include/ggml-backend.h
|
34
|
+
- ext/ggml/include/ggml-blas.h
|
35
|
+
- ext/ggml/include/ggml-cann.h
|
36
|
+
- ext/ggml/include/ggml-cpp.h
|
37
|
+
- ext/ggml/include/ggml-cpu.h
|
38
|
+
- ext/ggml/include/ggml-cuda.h
|
39
|
+
- ext/ggml/include/ggml-kompute.h
|
40
|
+
- ext/ggml/include/ggml-metal.h
|
41
|
+
- ext/ggml/include/ggml-opencl.h
|
42
|
+
- ext/ggml/include/ggml-opt.h
|
43
|
+
- ext/ggml/include/ggml-rpc.h
|
44
|
+
- ext/ggml/include/ggml-sycl.h
|
45
|
+
- ext/ggml/include/ggml-vulkan.h
|
46
|
+
- ext/ggml/include/ggml.h
|
47
|
+
- ext/ggml/src/ggml-alloc.c
|
48
|
+
- ext/ggml/src/ggml-amx/common.h
|
49
|
+
- ext/ggml/src/ggml-amx/ggml-amx.cpp
|
50
|
+
- ext/ggml/src/ggml-amx/mmq.cpp
|
51
|
+
- ext/ggml/src/ggml-amx/mmq.h
|
52
|
+
- ext/ggml/src/ggml-backend-impl.h
|
53
|
+
- ext/ggml/src/ggml-backend-reg.cpp
|
54
|
+
- ext/ggml/src/ggml-backend.cpp
|
55
|
+
- ext/ggml/src/ggml-blas/ggml-blas.cpp
|
56
|
+
- ext/ggml/src/ggml-cann/acl_tensor.cpp
|
57
|
+
- ext/ggml/src/ggml-cann/acl_tensor.h
|
58
|
+
- ext/ggml/src/ggml-cann/aclnn_ops.cpp
|
59
|
+
- ext/ggml/src/ggml-cann/aclnn_ops.h
|
60
|
+
- ext/ggml/src/ggml-cann/common.h
|
61
|
+
- ext/ggml/src/ggml-cann/ggml-cann.cpp
|
62
|
+
- ext/ggml/src/ggml-cann/kernels/ascendc_kernels.h
|
63
|
+
- ext/ggml/src/ggml-cann/kernels/dup.cpp
|
64
|
+
- ext/ggml/src/ggml-cann/kernels/get_row_f16.cpp
|
65
|
+
- ext/ggml/src/ggml-cann/kernels/get_row_f32.cpp
|
66
|
+
- ext/ggml/src/ggml-cann/kernels/get_row_q4_0.cpp
|
67
|
+
- ext/ggml/src/ggml-cann/kernels/get_row_q8_0.cpp
|
68
|
+
- ext/ggml/src/ggml-cann/kernels/quantize_f16_q8_0.cpp
|
69
|
+
- ext/ggml/src/ggml-cann/kernels/quantize_f32_q8_0.cpp
|
70
|
+
- ext/ggml/src/ggml-cann/kernels/quantize_float_to_q4_0.cpp
|
71
|
+
- ext/ggml/src/ggml-common.h
|
72
|
+
- ext/ggml/src/ggml-cpu/amx/amx.cpp
|
73
|
+
- ext/ggml/src/ggml-cpu/amx/amx.h
|
74
|
+
- ext/ggml/src/ggml-cpu/amx/common.h
|
75
|
+
- ext/ggml/src/ggml-cpu/amx/mmq.cpp
|
76
|
+
- ext/ggml/src/ggml-cpu/amx/mmq.h
|
77
|
+
- ext/ggml/src/ggml-cpu/cpu-feats-x86.cpp
|
78
|
+
- ext/ggml/src/ggml-cpu/ggml-cpu-aarch64.cpp
|
79
|
+
- ext/ggml/src/ggml-cpu/ggml-cpu-aarch64.h
|
80
|
+
- ext/ggml/src/ggml-cpu/ggml-cpu-hbm.cpp
|
81
|
+
- ext/ggml/src/ggml-cpu/ggml-cpu-hbm.h
|
82
|
+
- ext/ggml/src/ggml-cpu/ggml-cpu-impl.h
|
83
|
+
- ext/ggml/src/ggml-cpu/ggml-cpu-quants.c
|
84
|
+
- ext/ggml/src/ggml-cpu/ggml-cpu-quants.h
|
85
|
+
- ext/ggml/src/ggml-cpu/ggml-cpu-traits.cpp
|
86
|
+
- ext/ggml/src/ggml-cpu/ggml-cpu-traits.h
|
87
|
+
- ext/ggml/src/ggml-cpu/ggml-cpu.c
|
88
|
+
- ext/ggml/src/ggml-cpu/ggml-cpu.cpp
|
89
|
+
- ext/ggml/src/ggml-cpu/llamafile/sgemm.cpp
|
90
|
+
- ext/ggml/src/ggml-cpu/llamafile/sgemm.h
|
91
|
+
- ext/ggml/src/ggml-cuda/vendors/cuda.h
|
92
|
+
- ext/ggml/src/ggml-cuda/vendors/hip.h
|
93
|
+
- ext/ggml/src/ggml-cuda/vendors/musa.h
|
94
|
+
- ext/ggml/src/ggml-impl.h
|
95
|
+
- ext/ggml/src/ggml-kompute/ggml-kompute.cpp
|
96
|
+
- ext/ggml/src/ggml-metal/ggml-metal-impl.h
|
97
|
+
- ext/ggml/src/ggml-metal/ggml-metal.m
|
98
|
+
- ext/ggml/src/ggml-metal/ggml-metal.metal
|
99
|
+
- ext/ggml/src/ggml-opt.cpp
|
100
|
+
- ext/ggml/src/ggml-quants.c
|
101
|
+
- ext/ggml/src/ggml-quants.h
|
102
|
+
- ext/ggml/src/ggml-rpc/ggml-rpc.cpp
|
103
|
+
- ext/ggml/src/ggml-sycl/common.cpp
|
104
|
+
- ext/ggml/src/ggml-sycl/concat.cpp
|
105
|
+
- ext/ggml/src/ggml-sycl/conv.cpp
|
106
|
+
- ext/ggml/src/ggml-sycl/convert.cpp
|
107
|
+
- ext/ggml/src/ggml-sycl/dmmv.cpp
|
108
|
+
- ext/ggml/src/ggml-sycl/element_wise.cpp
|
109
|
+
- ext/ggml/src/ggml-sycl/ggml-sycl.cpp
|
110
|
+
- ext/ggml/src/ggml-sycl/im2col.cpp
|
111
|
+
- ext/ggml/src/ggml-sycl/mmq.cpp
|
112
|
+
- ext/ggml/src/ggml-sycl/mmvq.cpp
|
113
|
+
- ext/ggml/src/ggml-sycl/norm.cpp
|
114
|
+
- ext/ggml/src/ggml-sycl/outprod.cpp
|
115
|
+
- ext/ggml/src/ggml-sycl/rope.cpp
|
116
|
+
- ext/ggml/src/ggml-sycl/softmax.cpp
|
117
|
+
- ext/ggml/src/ggml-sycl/tsembd.cpp
|
118
|
+
- ext/ggml/src/ggml-sycl/wkv6.cpp
|
119
|
+
- ext/ggml/src/ggml-threading.cpp
|
120
|
+
- ext/ggml/src/ggml-threading.h
|
121
|
+
- ext/ggml/src/ggml-vulkan/ggml-vulkan.cpp
|
122
|
+
- ext/ggml/src/ggml-vulkan/vulkan-shaders/vulkan-shaders-gen.cpp
|
123
|
+
- ext/ggml/src/ggml.c
|
124
|
+
- ext/include/whisper.h
|
125
|
+
- ext/metal-embed.mk
|
126
|
+
- ext/metal.mk
|
31
127
|
- ext/ruby_whisper.cpp
|
32
128
|
- ext/ruby_whisper.h
|
33
|
-
- ext/
|
34
|
-
- ext/whisper.h
|
129
|
+
- ext/scripts/get-flags.mk
|
130
|
+
- ext/src/coreml/whisper-decoder-impl.h
|
131
|
+
- ext/src/coreml/whisper-decoder-impl.m
|
132
|
+
- ext/src/coreml/whisper-encoder-impl.h
|
133
|
+
- ext/src/coreml/whisper-encoder-impl.m
|
134
|
+
- ext/src/coreml/whisper-encoder.h
|
135
|
+
- ext/src/openvino/whisper-openvino-encoder.cpp
|
136
|
+
- ext/src/openvino/whisper-openvino-encoder.h
|
137
|
+
- ext/src/whisper.cpp
|
138
|
+
- extsources.rb
|
139
|
+
- lib/whisper.rb
|
140
|
+
- lib/whisper/model/uri.rb
|
141
|
+
- tests/helper.rb
|
142
|
+
- tests/jfk_reader/.gitignore
|
143
|
+
- tests/jfk_reader/extconf.rb
|
144
|
+
- tests/jfk_reader/jfk_reader.c
|
145
|
+
- tests/test_callback.rb
|
146
|
+
- tests/test_error.rb
|
147
|
+
- tests/test_model.rb
|
148
|
+
- tests/test_package.rb
|
149
|
+
- tests/test_params.rb
|
150
|
+
- tests/test_segment.rb
|
35
151
|
- tests/test_whisper.rb
|
152
|
+
- whispercpp.gemspec
|
36
153
|
homepage: https://github.com/ggerganov/whisper.cpp
|
37
154
|
licenses:
|
38
155
|
- MIT
|
@@ -40,24 +157,33 @@ metadata: {}
|
|
40
157
|
post_install_message:
|
41
158
|
rdoc_options:
|
42
159
|
- "--main"
|
43
|
-
-
|
160
|
+
- README.md
|
44
161
|
require_paths:
|
45
162
|
- lib
|
46
|
-
- ext
|
47
163
|
required_ruby_version: !ruby/object:Gem::Requirement
|
48
164
|
requirements:
|
49
165
|
- - ">="
|
50
166
|
- !ruby/object:Gem::Version
|
51
|
-
version:
|
167
|
+
version: 3.1.0
|
52
168
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
53
169
|
requirements:
|
54
170
|
- - ">="
|
55
171
|
- !ruby/object:Gem::Version
|
56
172
|
version: '0'
|
57
173
|
requirements: []
|
58
|
-
rubygems_version: 3.5.
|
174
|
+
rubygems_version: 3.5.22
|
59
175
|
signing_key:
|
60
176
|
specification_version: 4
|
61
177
|
summary: Ruby whisper.cpp bindings
|
62
178
|
test_files:
|
179
|
+
- tests/helper.rb
|
180
|
+
- tests/jfk_reader/.gitignore
|
181
|
+
- tests/jfk_reader/extconf.rb
|
182
|
+
- tests/jfk_reader/jfk_reader.c
|
183
|
+
- tests/test_callback.rb
|
184
|
+
- tests/test_error.rb
|
185
|
+
- tests/test_model.rb
|
186
|
+
- tests/test_package.rb
|
187
|
+
- tests/test_params.rb
|
188
|
+
- tests/test_segment.rb
|
63
189
|
- tests/test_whisper.rb
|