@@ -38,6 +38,9 @@ VALUE cContext;
3838VALUE cParams;
3939VALUE eError;
4040
41+ VALUE cSegment;
42+ VALUE cModel;
43+
4144static ID id_to_s;
4245static ID id_call;
4346static ID id___method__;
@@ -46,6 +49,7 @@ static ID id_length;
4649static ID id_next;
4750static ID id_new;
4851static ID id_to_path;
52+ static ID id_pre_converted_models;
4953
5054static bool is_log_callback_finalized = false ;
5155
@@ -187,6 +191,7 @@ static VALUE ruby_whisper_params_allocate(VALUE klass) {
187191 ruby_whisper_params *rwp;
188192 rwp = ALLOC (ruby_whisper_params);
189193 rwp->params = whisper_full_default_params (WHISPER_SAMPLING_GREEDY);
194+ rwp->diarize = false ;
190195 rwp->new_segment_callback_container = rb_whisper_callback_container_allocate ();
191196 rwp->progress_callback_container = rb_whisper_callback_container_allocate ();
192197 rwp->abort_callback_container = rb_whisper_callback_container_allocate ();
@@ -195,7 +200,7 @@ static VALUE ruby_whisper_params_allocate(VALUE klass) {
195200
196201/*
197202 * call-seq:
198- * new(Whisper::Model[ "base.en"] ) -> Whisper::Context
203+ * new("base.en") -> Whisper::Context
199204 * new("path/to/model.bin") -> Whisper::Context
200205 * new(Whisper::Model::URI.new("https://example.net/uri/of/model.bin")) -> Whisper::Context
201206 */
@@ -207,6 +212,11 @@ static VALUE ruby_whisper_initialize(int argc, VALUE *argv, VALUE self) {
207212 rb_scan_args (argc, argv, " 01" , &whisper_model_file_path);
208213 Data_Get_Struct (self, ruby_whisper, rw);
209214
215+ VALUE pre_converted_models = rb_funcall (cModel, id_pre_converted_models, 0 );
216+ VALUE pre_converted_model = rb_hash_aref (pre_converted_models, whisper_model_file_path);
217+ if (!NIL_P (pre_converted_model)) {
218+ whisper_model_file_path = pre_converted_model;
219+ }
210220 if (rb_respond_to (whisper_model_file_path, id_to_path)) {
211221 whisper_model_file_path = rb_funcall (whisper_model_file_path, id_to_path, 0 );
212222 }
@@ -1251,6 +1261,25 @@ static VALUE ruby_whisper_params_set_logprob_thold(VALUE self, VALUE value) {
12511261 rwp->params .logprob_thold = RFLOAT_VALUE (value);
12521262 return value;
12531263}
1264+ /*
1265+ * call-seq:
1266+ * no_speech_thold -> Float
1267+ */
1268+ static VALUE ruby_whisper_params_get_no_speech_thold (VALUE self) {
1269+ ruby_whisper_params *rwp;
1270+ Data_Get_Struct (self, ruby_whisper_params, rwp);
1271+ return DBL2NUM (rwp->params .no_speech_thold );
1272+ }
1273+ /*
1274+ * call-seq:
1275+ * no_speech_thold = threshold -> threshold
1276+ */
1277+ static VALUE ruby_whisper_params_set_no_speech_thold (VALUE self, VALUE value) {
1278+ ruby_whisper_params *rwp;
1279+ Data_Get_Struct (self, ruby_whisper_params, rwp);
1280+ rwp->params .no_speech_thold = RFLOAT_VALUE (value);
1281+ return value;
1282+ }
12541283/*
12551284 * Sets new segment callback, called for every newly generated text segment.
12561285 *
@@ -1347,9 +1376,6 @@ typedef struct {
13471376 VALUE context;
13481377} ruby_whisper_model;
13491378
1350- VALUE cSegment;
1351- VALUE cModel;
1352-
13531379static void rb_whisper_segment_mark (ruby_whisper_segment *rws) {
13541380 rb_gc_mark (rws->context );
13551381}
@@ -1740,6 +1766,7 @@ void Init_whisper() {
17401766 id_next = rb_intern (" next" );
17411767 id_new = rb_intern (" new" );
17421768 id_to_path = rb_intern (" to_path" );
1769+ id_pre_converted_models = rb_intern (" pre_converted_models" );
17431770
17441771 mWhisper = rb_define_module (" Whisper" );
17451772 cContext = rb_define_class_under (mWhisper , " Context" , rb_cObject);
@@ -1835,6 +1862,8 @@ void Init_whisper() {
18351862 rb_define_method (cParams, " entropy_thold=" , ruby_whisper_params_set_entropy_thold, 1 );
18361863 rb_define_method (cParams, " logprob_thold" , ruby_whisper_params_get_logprob_thold, 0 );
18371864 rb_define_method (cParams, " logprob_thold=" , ruby_whisper_params_set_logprob_thold, 1 );
1865+ rb_define_method (cParams, " no_speech_thold" , ruby_whisper_params_get_no_speech_thold, 0 );
1866+ rb_define_method (cParams, " no_speech_thold=" , ruby_whisper_params_set_no_speech_thold, 1 );
18381867
18391868 rb_define_method (cParams, " new_segment_callback=" , ruby_whisper_params_set_new_segment_callback, 1 );
18401869 rb_define_method (cParams, " new_segment_callback_user_data=" , ruby_whisper_params_set_new_segment_callback_user_data, 1 );
0 commit comments