mirror of
https://github.com/ggerganov/whisper.cpp
synced 2026-03-21 14:20:39 +01:00
* Add Whisper::VAD::Context * Add test for Whisper::VAD::Context * Add Whisper::VAD::Segment * Add Whisper::VAD::Segments * Add Whisper::VAD::Context#detect * Define Whisper::VAD::Segments#each * Define Whisper::VAD::Segment#start_time and #end_time * Define Whisper::VAD::Segment#deconstruct_keys * Add tests for Whisper::VAD family * Add signatures for VAD family * Add document on VAD in README * Define Whisper::VAD::Segments#length * Add test for Whisper::VAD::Segments#length * Add signature of Segments#length * Make vad_segments responsible to initialize VAD::Segments * Remove meaningless argument check * Check NULL of segments member * Add tests for Whisper::VAD::Segments * Initialize Whisper::VAD::Segment on .allocate * Add tests for Whisper::VAD::Segment * Check NULL of context member * Add test for Whisper::VAD::Context.allocate
51 lines
1.5 KiB
C++
51 lines
1.5 KiB
C++
#include <ruby.h>
|
|
#include "ruby_whisper.h"
|
|
#include "common-whisper.h"
|
|
#include <string>
|
|
#include <vector>
|
|
|
|
#ifdef __cplusplus
|
|
extern "C" {
|
|
#endif
|
|
|
|
extern VALUE cVADSegments;
|
|
|
|
extern const rb_data_type_t ruby_whisper_vad_context_type;
|
|
extern const rb_data_type_t ruby_whisper_vad_params_type;
|
|
extern const rb_data_type_t ruby_whisper_vad_segments_type;
|
|
|
|
extern VALUE ruby_whisper_vad_segments_s_init(struct whisper_vad_segments *segments);
|
|
|
|
VALUE
|
|
ruby_whisper_vad_detect(VALUE self, VALUE file_path, VALUE params) {
|
|
ruby_whisper_vad_context *rwvc;
|
|
ruby_whisper_vad_params *rwvp;
|
|
std::string cpp_file_path;
|
|
std::vector<float> pcmf32;
|
|
std::vector<std::vector<float>> pcmf32s;
|
|
whisper_vad_segments *segments;
|
|
|
|
TypedData_Get_Struct(self, ruby_whisper_vad_context, &ruby_whisper_vad_context_type, rwvc);
|
|
if (rwvc->context == NULL) {
|
|
rb_raise(rb_eRuntimeError, "Doesn't have referenxe to context internally");
|
|
}
|
|
TypedData_Get_Struct(params, ruby_whisper_vad_params, &ruby_whisper_vad_params_type, rwvp);
|
|
|
|
cpp_file_path = StringValueCStr(file_path);
|
|
|
|
if (!read_audio_data(cpp_file_path, pcmf32, pcmf32s, false)) {
|
|
rb_raise(rb_eRuntimeError, "Failed to open '%s' as WAV file\n", cpp_file_path.c_str());
|
|
}
|
|
|
|
segments = whisper_vad_segments_from_samples(rwvc->context, rwvp->params, pcmf32.data(), pcmf32.size());
|
|
if (segments == nullptr) {
|
|
rb_raise(rb_eRuntimeError, "Failed to process audio\n");
|
|
}
|
|
|
|
return ruby_whisper_vad_segments_s_init(segments);
|
|
}
|
|
|
|
#ifdef __cplusplus
|
|
}
|
|
#endif
|