mirror of
https://github.com/ggml-org/whisper.cpp.git
synced 2026-07-23 11:10:57 -05:00
* Add Whisper::Parakeet::Params * Add tests for Parakeet::Params * Remove unused variabel * Add callbacks to Parakeet::Params * Group callback and user_data params * Undefine local macros * Define GetParakeetParams * Remove unused variable * Use ITERATE_CALLBACK_PARAMS * Use ITERATE_CALLBACK_PARAMS instead of ITERATE_USER_DATA_PARAMS * Fix memsize * Remove unnecessary macros * Simplify params registration * Define Parakeet * Add hook methods to Parakeet::Params * Fix typo * Check callback container in GetParakeetParams * Reduce if * Free parakeet_full_params * Implement Parakeet::Context#initialize * Add TestParakeetContext * Add Parakeet::Segment * Prevent double-free * Add Parakeet::Context#transcribe * Add Parakeet::Context#each_segment * Define Parakeet::Segment attributes * Define Parakeet::Segment#deconstruct_keys * Add tests for Parakeet::Segment#deconstruct_keys * Run Parakeet::Context#transcribe without GVL * Make it to abort for Parakeet * Add Parakeet.log_set * Define Parakeet::Token * Define Parakeet::Segment#each_token * Implement some hooks of Parakeet::Params * Convert int to VALUE * Implement hooks for Parakeet * Implement Parakeet::Context#full * Add tests for Parakeet::Context#full * Add Parakeet to RBS * Fix ruby_whisper_parakeet_params_free * Free ruby_whisper_parakeet_context * Add tests for hooks * Add Parakeet section to README * Add more attributes of Parakeet::Context * Add tests for Parakeet::Context's attributes * Update RBS * Register parakeet-tdt-0.6b-v3 * Narrow scope of log constants * Extract activate and deactivate of log_queue * Make start_log_callback_thread private * Don't call start_log_callback_thread unncecessarilly * Early return from log_queue_enqueue when not active * Gropu log_queue members * is_active -> is_open * Fix English * Share parakeet full body function * ruby_whisper_parakeet_abort_callback_user_data -> ruby_whisper_abort_callback_user_data * NULL check for callback containers * Fix Parakeet.log_set * Omit Parakeet tests on CI * Extract Whisper::LogSettable * Join log callback thread in a log queue function * Revert Join log callback thread in a log queue function * Extract output methods to modules * Move Parakeet init functions into init_parakeet() * Add output methods to Parakeet classes * Add Parakeet's output methods to RBS * Use Whisper::Output in RBS * Add LogSettable to RBS * Fix module Token -> class Token * Add Parakeet::Model * Add test for Parakeet::Model * Add Parakeet::Model to RBS * Move position of Parakeet::Model in RBS * Parakeet -> TestBase::Parakeet * Add Parakeet::Context#model in RBS * Add Whisper::Output * Fix nil check * Define ruby_whisper_parakeet_model_memsize * Fix order of declaration in ruby_whisper_parakeet_model_get_xxx * Define Parakeet.system_info_str * Add test for Parakeet.system_info_str * Add signature of Parakeet.system_info_str * Define Parakeet::VERSION * Add test for Parakeet::VERSION * Add signature of Parakeet::VERSION * Add Parakeet::Context::Params * Make Parakeet::Context.new accept Context::Params * Add test for Parakeet::Context.new with Context::Params * Update RBS * Remove params from Parakeet::Params which are moved from whisper_parakeet_full_params * Remove tests for removed params * Make Parakeet tests follow original behavior changes * Add Parakeet model shortcuts * Alloc token data in factory instead of alloc func * Fix variable name * Update RBS * Refactor log settable module * Use log settable for Whisper * Address deadlock * Make test follow change of log queue implementation * Refactor to make abort callback use the same way to parakeet's way * Remove redundant structs * Fix test name * Fix README * Add missing parallel transcription * Fix test for parakeet info * Remove removed params * Wait for logs dequeued * Fix instance variable name * Load etc feature * Remove unnecessary comment * Remove unnecessary thread safety check * Remove outdated comment * Skip downloading model if cache exists * Change Hugging Face URI for Parakeet models * Bump required Ruby version to 3.3 * Fix English
118 lines
3.4 KiB
C
118 lines
3.4 KiB
C
#include "ruby_whisper.h"
|
|
|
|
#define ITERATE_ATTRS(ITERATOR) \
|
|
ITERATOR(use_gpu, BOOL) \
|
|
ITERATOR(gpu_device, INT)
|
|
|
|
#define VAL_FROM_BOOL(v) ((v) ? Qtrue : Qfalse)
|
|
#define VAL_TO_BOOL(v) (RTEST(v))
|
|
#define VAL_FROM_INT(v) (INT2NUM(v))
|
|
#define VAL_TO_INT(v) (NUM2INT(v))
|
|
#define READER(type) VAL_FROM_##type
|
|
#define WRITER(type) VAL_TO_##type
|
|
|
|
#define DEF_ATTR(name, type) \
|
|
static VALUE \
|
|
ruby_whisper_parakeet_context_params_get_##name(VALUE self) \
|
|
{ \
|
|
ruby_whisper_parakeet_context_params *rwpcp; \
|
|
GetParakeetContextParams(self, rwpcp); \
|
|
return READER(type)(rwpcp->params.name); \
|
|
} \
|
|
static VALUE \
|
|
ruby_whisper_parakeet_context_params_set_##name(VALUE self, VALUE val) \
|
|
{ \
|
|
ruby_whisper_parakeet_context_params *rwpcp; \
|
|
GetParakeetContextParams(self, rwpcp); \
|
|
rwpcp->params.name = WRITER(type)(val); \
|
|
return val; \
|
|
}
|
|
|
|
enum {
|
|
#define DEF_IDX(name, type) RUBY_WHISPER_PARAKEET_CONTEXT_PARAMS_##name,
|
|
|
|
ITERATE_ATTRS(DEF_IDX)
|
|
RUBY_WHISPER_PARAKEET_NUM_CONTEXT_PARAMS
|
|
};
|
|
|
|
extern VALUE cParakeetContextParams;
|
|
|
|
typedef VALUE (*param_writer_t)(VALUE, VALUE);
|
|
|
|
static ID param_names[RUBY_WHISPER_PARAKEET_NUM_CONTEXT_PARAMS];
|
|
static param_writer_t param_writers[RUBY_WHISPER_PARAKEET_NUM_CONTEXT_PARAMS];
|
|
|
|
static size_t
|
|
ruby_whisper_parakeet_context_params_memsize(const void *p)
|
|
{
|
|
if (!p) {
|
|
return 0;
|
|
}
|
|
return sizeof(ruby_whisper_parakeet_context_params);
|
|
}
|
|
|
|
const rb_data_type_t ruby_whisper_parakeet_context_params_type = {
|
|
"ruby_whisper_parakeet_context_params",
|
|
{0, RUBY_DEFAULT_FREE, ruby_whisper_parakeet_context_params_memsize,},
|
|
0, 0,
|
|
0,
|
|
};
|
|
|
|
static VALUE
|
|
ruby_whisper_parakeet_context_params_s_allocate(VALUE klass)
|
|
{
|
|
ruby_whisper_parakeet_context_params *rwpcp;
|
|
return TypedData_Make_Struct(klass, ruby_whisper_parakeet_context_params, &ruby_whisper_parakeet_context_params_type, rwpcp);
|
|
}
|
|
|
|
static VALUE
|
|
ruby_whisper_parakeet_context_params_initialize(int argc, VALUE *argv, VALUE self)
|
|
{
|
|
VALUE kw_hash;
|
|
VALUE values[RUBY_WHISPER_PARAKEET_NUM_CONTEXT_PARAMS] = {Qundef};
|
|
VALUE value;
|
|
ruby_whisper_parakeet_context_params *rwpcp;
|
|
int i;
|
|
|
|
TypedData_Get_Struct(self, ruby_whisper_parakeet_context_params, &ruby_whisper_parakeet_context_params_type, rwpcp);
|
|
rwpcp->params = parakeet_context_default_params();
|
|
|
|
rb_scan_args_kw(RB_SCAN_ARGS_KEYWORDS, argc, argv, ":", &kw_hash);
|
|
if (NIL_P(kw_hash)) {
|
|
return Qnil;
|
|
}
|
|
|
|
rb_get_kwargs(kw_hash, param_names, 0, RUBY_WHISPER_PARAKEET_NUM_CONTEXT_PARAMS, values);
|
|
for (i = 0; i < RUBY_WHISPER_PARAKEET_NUM_CONTEXT_PARAMS; i++) {
|
|
value = values[i];
|
|
if (value == Qundef) {
|
|
continue;
|
|
}
|
|
param_writers[i](self, value);
|
|
}
|
|
|
|
return Qnil;
|
|
}
|
|
|
|
ITERATE_ATTRS(DEF_ATTR)
|
|
|
|
void
|
|
init_ruby_whisper_parakeet_context_params(VALUE *cParakeetContext)
|
|
{
|
|
cParakeetContextParams = rb_define_class_under(*cParakeetContext, "Params", rb_cObject);
|
|
|
|
rb_define_alloc_func(cParakeetContextParams, ruby_whisper_parakeet_context_params_s_allocate);
|
|
|
|
rb_define_method(cParakeetContextParams, "initialize", ruby_whisper_parakeet_context_params_initialize, -1);
|
|
|
|
int i = 0;
|
|
#define REGISTER_ATTR(name, type) \
|
|
param_names[i] = rb_intern(#name); \
|
|
param_writers[i] = ruby_whisper_parakeet_context_params_set_##name; \
|
|
rb_define_method(cParakeetContextParams, #name, ruby_whisper_parakeet_context_params_get_##name, 0); \
|
|
rb_define_method(cParakeetContextParams, #name "=", ruby_whisper_parakeet_context_params_set_##name, 1); \
|
|
i++;
|
|
|
|
ITERATE_ATTRS(REGISTER_ATTR)
|
|
}
|