Skip to content

Commit 9fa352c

Browse files
committed
Make Whisper::Context.new accept URI string and URI
1 parent 8a2d663 commit 9fa352c

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

bindings/ruby/ext/ruby_whisper.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ static ID id_length;
4949
static ID id_next;
5050
static ID id_new;
5151
static ID id_to_path;
52+
static ID id_URI;
5253
static ID id_pre_converted_models;
5354

5455
static bool is_log_callback_finalized = false;
@@ -283,6 +284,17 @@ static VALUE ruby_whisper_initialize(int argc, VALUE *argv, VALUE self) {
283284
if (!NIL_P(pre_converted_model)) {
284285
whisper_model_file_path = pre_converted_model;
285286
}
287+
if (TYPE(whisper_model_file_path) == T_STRING) {
288+
const char * whisper_model_file_path_str = StringValueCStr(whisper_model_file_path);
289+
if (strncmp("http://", whisper_model_file_path_str, 7) == 0 || strncmp("https://", whisper_model_file_path_str, 8) == 0) {
290+
VALUE uri_class = rb_const_get(cModel, id_URI);
291+
whisper_model_file_path = rb_class_new_instance(1, &whisper_model_file_path, uri_class);
292+
}
293+
}
294+
if (rb_obj_is_kind_of(whisper_model_file_path, rb_path2class("URI::HTTP"))) {
295+
VALUE uri_class = rb_const_get(cModel, id_URI);
296+
whisper_model_file_path = rb_class_new_instance(1, &whisper_model_file_path, uri_class);
297+
}
286298
if (rb_respond_to(whisper_model_file_path, id_to_path)) {
287299
whisper_model_file_path = rb_funcall(whisper_model_file_path, id_to_path, 0);
288300
}
@@ -1802,6 +1814,7 @@ void Init_whisper() {
18021814
id_next = rb_intern("next");
18031815
id_new = rb_intern("new");
18041816
id_to_path = rb_intern("to_path");
1817+
id_URI = rb_intern("URI");
18051818
id_pre_converted_models = rb_intern("pre_converted_models");
18061819

18071820
mWhisper = rb_define_module("Whisper");

0 commit comments

Comments
 (0)