Skip to content

Commit 5f00362

Browse files
committed
Add Whisper::Context#full_get_segment_no_speech_prob and Whisper::Segment#no_speech_prob
1 parent 8bf0ba7 commit 5f00362

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

bindings/ruby/ext/ruby_whisper.cpp

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -835,6 +835,18 @@ static VALUE ruby_whisper_full_get_segment_text(VALUE self, VALUE i_segment) {
835835
return rb_str_new2(text);
836836
}
837837

838+
/*
839+
* call-seq:
840+
* full_get_segment_no_speech_prob -> Float
841+
*/
842+
static VALUE ruby_whisper_full_get_segment_no_speech_prob(VALUE self, VALUE i_segment) {
843+
ruby_whisper *rw;
844+
Data_Get_Struct(self, ruby_whisper, rw);
845+
const int c_i_segment = ruby_whisper_full_check_segment_index(rw, i_segment);
846+
const float no_speech_prob = whisper_full_get_segment_no_speech_prob(rw->context, c_i_segment);
847+
return DBL2NUM(no_speech_prob);
848+
}
849+
838850
/*
839851
* params.language = "auto" | "en", etc...
840852
*
@@ -1559,6 +1571,18 @@ static VALUE ruby_whisper_segment_get_text(VALUE self) {
15591571
return rb_str_new2(text);
15601572
}
15611573

1574+
/*
1575+
* call-seq:
1576+
* no_speech_prob -> Float
1577+
*/
1578+
static VALUE ruby_whisper_segment_get_no_speech_prob(VALUE self) {
1579+
ruby_whisper_segment *rws;
1580+
Data_Get_Struct(self, ruby_whisper_segment, rws);
1581+
ruby_whisper *rw;
1582+
Data_Get_Struct(rws->context, ruby_whisper, rw);
1583+
return DBL2NUM(whisper_full_get_segment_no_speech_prob(rw->context, rws->index));
1584+
}
1585+
15621586
static void rb_whisper_model_mark(ruby_whisper_model *rwm) {
15631587
rb_gc_mark(rwm->context);
15641588
}
@@ -1821,6 +1845,7 @@ void Init_whisper() {
18211845
rb_define_method(cContext, "full_get_segment_t1", ruby_whisper_full_get_segment_t1, 1);
18221846
rb_define_method(cContext, "full_get_segment_speaker_turn_next", ruby_whisper_full_get_segment_speaker_turn_next, 1);
18231847
rb_define_method(cContext, "full_get_segment_text", ruby_whisper_full_get_segment_text, 1);
1848+
rb_define_method(cContext, "full_get_segment_no_speech_prob", ruby_whisper_full_get_segment_no_speech_prob, 1);
18241849
rb_define_method(cContext, "full", ruby_whisper_full, -1);
18251850
rb_define_method(cContext, "full_parallel", ruby_whisper_full_parallel, -1);
18261851

@@ -1899,6 +1924,7 @@ void Init_whisper() {
18991924
rb_define_method(cSegment, "end_time", ruby_whisper_segment_get_end_time, 0);
19001925
rb_define_method(cSegment, "speaker_next_turn?", ruby_whisper_segment_get_speaker_turn_next, 0);
19011926
rb_define_method(cSegment, "text", ruby_whisper_segment_get_text, 0);
1927+
rb_define_method(cSegment, "no_speech_prob", ruby_whisper_segment_get_no_speech_prob, 0);
19021928

19031929
cModel = rb_define_class_under(mWhisper, "Model", rb_cObject);
19041930
rb_define_alloc_func(cModel, ruby_whisper_model_allocate);

0 commit comments

Comments
 (0)