mirror of
https://github.com/ggerganov/whisper.cpp.git
synced 2025-01-05 04:04:09 +00:00
fc49ee4479
* Add Params#new_segment_callback= method * Add tests for Params#new_segment_callback= * Group tests for #transcribe * Don't use static for thread-safety * Set new_segment_callback only when necessary * Remove redundant check * [skip ci] Add Ruby version README * Revert "Group tests for #transcribe" This reverts commit71b65b00cc
. * Revert "Add tests for Params#new_segment_callback=" This reverts commit81e6df3bab
. * Add test for Context#full_n_segments * Add Context#full_n_segments * Add tests for lang API * Add lang API * Add tests for Context#full_lang_id API * Add Context#full_lang_id * Add abnormal test cases for lang * Raise appropriate errors from lang APIs * Add tests for Context#full_get_segment_t{0,1} API * Add Context#full_get_segment_t{0,1} * Add tests for Context#full_get_segment_speaker_turn_next API * Add Context#full_get_segment_speaker_turn_next * Add tests for Context#full_get_segment_text * Add Context#full_get_setgment_text * Add tests for Params#new_segment_callback= * Run new segment callback * Split tests to multiple files * Use container struct for new segment callback * Add tests for Params#new_segment_callback_user_data= * Add Whisper::Params#new_user_callback_user_data= * Add GC-related test for new segment callback * Protect new segment callback related structs from GC * Add meaningful test for build * Rename: new_segment_callback_user_data -> new_segment_callback_container * Add tests for Whisper::Segment * Add Whisper::Segment and Whisper::Context#each_segment * Extract c_ruby_whisper_callback_container_allocate() * Add test for Whisper::Params#on_new_segment * Add Whisper::Params#on_new_egment * Assign symbol IDs to variables * Make extsources.yaml simpler * Update README * Add document comments * Add test for calling Whisper::Params#on_new_segment multiple times * Add file dependencies to GitHub actions config and .gitignore * Add more files to ext/.gitignore
100 lines
2.6 KiB
Ruby
100 lines
2.6 KiB
Ruby
require 'whisper'
|
|
require 'test/unit'
|
|
|
|
class TestWhisper < Test::Unit::TestCase
|
|
TOPDIR = File.expand_path(File.join(File.dirname(__FILE__), '..'))
|
|
|
|
def setup
|
|
@params = Whisper::Params.new
|
|
end
|
|
|
|
def test_whisper
|
|
@whisper = Whisper::Context.new(File.join(TOPDIR, '..', '..', 'models', 'ggml-base.en.bin'))
|
|
params = Whisper::Params.new
|
|
params.print_timestamps = false
|
|
|
|
jfk = File.join(TOPDIR, '..', '..', 'samples', 'jfk.wav')
|
|
@whisper.transcribe(jfk, params) {|text|
|
|
assert_match /ask not what your country can do for you, ask what you can do for your country/, text
|
|
}
|
|
end
|
|
|
|
sub_test_case "After transcription" do
|
|
class << self
|
|
attr_reader :whisper
|
|
|
|
def startup
|
|
@whisper = Whisper::Context.new(File.join(TOPDIR, '..', '..', 'models', 'ggml-base.en.bin'))
|
|
params = Whisper::Params.new
|
|
params.print_timestamps = false
|
|
jfk = File.join(TOPDIR, '..', '..', 'samples', 'jfk.wav')
|
|
@whisper.transcribe(jfk, params)
|
|
end
|
|
end
|
|
|
|
def whisper
|
|
self.class.whisper
|
|
end
|
|
|
|
def test_full_n_segments
|
|
assert_equal 1, whisper.full_n_segments
|
|
end
|
|
|
|
def test_full_lang_id
|
|
assert_equal 0, whisper.full_lang_id
|
|
end
|
|
|
|
def test_full_get_segment_t0
|
|
assert_equal 0, whisper.full_get_segment_t0(0)
|
|
assert_raise IndexError do
|
|
whisper.full_get_segment_t0(whisper.full_n_segments)
|
|
end
|
|
assert_raise IndexError do
|
|
whisper.full_get_segment_t0(-1)
|
|
end
|
|
end
|
|
|
|
def test_full_get_segment_t1
|
|
t1 = whisper.full_get_segment_t1(0)
|
|
assert_kind_of Integer, t1
|
|
assert t1 > 0
|
|
assert_raise IndexError do
|
|
whisper.full_get_segment_t1(whisper.full_n_segments)
|
|
end
|
|
end
|
|
|
|
def test_full_get_segment_speaker_turn_next
|
|
assert_false whisper.full_get_segment_speaker_turn_next(0)
|
|
end
|
|
|
|
def test_full_get_segment_text
|
|
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)
|
|
end
|
|
end
|
|
|
|
def test_lang_max_id
|
|
assert_kind_of Integer, Whisper.lang_max_id
|
|
end
|
|
|
|
def test_lang_id
|
|
assert_equal 0, Whisper.lang_id("en")
|
|
assert_raise ArgumentError do
|
|
Whisper.lang_id("non existing language")
|
|
end
|
|
end
|
|
|
|
def test_lang_str
|
|
assert_equal "en", Whisper.lang_str(0)
|
|
assert_raise IndexError do
|
|
Whisper.lang_str(Whisper.lang_max_id + 1)
|
|
end
|
|
end
|
|
|
|
def test_lang_str_full
|
|
assert_equal "english", Whisper.lang_str_full(0)
|
|
assert_raise IndexError do
|
|
Whisper.lang_str_full(Whisper.lang_max_id + 1)
|
|
end
|
|
end
|
|
end
|