Some checks failed
Bindings Tests (Go) / ubuntu-22 (push) Failing after 31s
CI (sycl) / ubuntu-22-cmake-sycl (linux/arm/v7, icx, icpx, ON) (push) Failing after 3s
CI (sycl) / ubuntu-22-cmake-sycl (linux/ppc64le, icx, icpx, ON) (push) Failing after 2s
CI (sycl) / ubuntu-22-cmake-sycl-fp16 (linux/amd64, icx, icpx, ON) (push) Failing after 3s
CI (sycl) / ubuntu-22-cmake-sycl-fp16 (linux/arm/v7, icx, icpx, ON) (push) Failing after 3s
CI (sycl) / ubuntu-22-cmake-sycl-fp16 (linux/arm64, icx, icpx, ON) (push) Failing after 3s
CI (sycl) / ubuntu-22-cmake-sycl-fp16 (linux/ppc64le, icx, icpx, ON) (push) Failing after 3s
CI (vad) / vad (push) Failing after 3s
CI (wasm) / emscripten (Release) (push) Failing after 4s
Bindings Tests (Ruby) / ubuntu-22 (push) Failing after 37s
CI (android) / android (push) Failing after 16s
CI (android) / android_java (push) Failing after 3s
CI (clang) / ubuntu-22-clang (linux/amd64, Debug) (push) Failing after 3s
CI (clang) / ubuntu-22-clang (linux/amd64, Release) (push) Failing after 2s
CI (clang) / ubuntu-22-clang (linux/ppc64le, Debug) (push) Failing after 3s
CI (clang) / ubuntu-22-clang (linux/ppc64le, Release) (push) Failing after 3s
CI (cpu) / ggml-ci-x64-cpu-low-perf (push) Failing after 3s
CI (cpu) / ggml-ci-x64-cpu-high-perf (push) Failing after 2s
CI (gcc) / ubuntu-22-gcc (linux/amd64, Debug) (push) Failing after 3s
CI (gcc) / ubuntu-22-gcc (linux/amd64, Release) (push) Failing after 3s
CI (gcc) / ubuntu-22-gcc (linux/ppc64le, Debug) (push) Failing after 3s
CI (gcc) / ubuntu-22-gcc (linux/ppc64le, Release) (push) Failing after 4s
CI (gcc) / ubuntu-22-gcc-arm-v7 (linux/arm/v7, Debug) (push) Failing after 3s
CI (gcc) / ubuntu-22-gcc-arm-v7 (linux/arm/v7, Release) (push) Failing after 3s
CI (quantize) / quantize (push) Failing after 3s
CI (sanitize) / ubuntu-22-gcc-sanitized (ADDRESS) (push) Failing after 3s
CI (sanitize) / ubuntu-22-gcc-sanitized (THREAD) (push) Failing after 3s
CI (sanitize) / ubuntu-22-gcc-sanitized (UNDEFINED) (push) Failing after 2s
CI (sycl) / ubuntu-22-cmake-sycl (linux/amd64, icx, icpx, ON) (push) Failing after 3s
CI (sycl) / ubuntu-22-cmake-sycl (linux/arm64, icx, icpx, ON) (push) Failing after 3s
Examples WASM / deploy-wasm-github-pages (push) Failing after 3s
Examples Tests / addon_node-ubuntu-22 (20.x) (push) Failing after 3s
Examples Tests / addon_node-ubuntu-22 (22.x) (push) Failing after 2s
CI (coreml) / coreml-base-en (push) Has been cancelled
CI (self-hosted) / gpu-vulkan (push) Has been cancelled
CI (self-hosted) / npu-amd-windows (push) Has been cancelled
CI (self-hosted) / gpu-vulkan-nvidia-cm2 (push) Has been cancelled
CI (clang) / ubuntu-22-clang-arm64 (Debug) (push) Has been cancelled
CI (clang) / ubuntu-22-clang-arm64 (Release) (push) Has been cancelled
CI (self-hosted) / gpu-cuda (push) Has been cancelled
CI (self-hosted) / gpu-vulkan-nvidia-cm (push) Has been cancelled
CI (cpu) / ggml-ci-arm64-cpu-low-perf (push) Has been cancelled
CI (cpu) / ggml-ci-arm64-cpu-high-perf (push) Has been cancelled
CI (cpu) / ggml-ci-arm64-cpu-high-perf-sve (push) Has been cancelled
CI (freebsd) / freeBSD-latest (push) Has been cancelled
CI (self-hosted) / gpu-metal (push) Has been cancelled
CI (gcc) / ubuntu-22-gcc-arm64 (Debug) (push) Has been cancelled
CI (gcc) / ubuntu-22-gcc-arm64 (Release) (push) Has been cancelled
CI (macOS) / macOS-latest (generic/platform=iOS) (push) Has been cancelled
CI (macOS) / macOS-latest (generic/platform=macOS) (push) Has been cancelled
CI (macOS) / macOS-latest (generic/platform=tvOS) (push) Has been cancelled
CI (self-hosted) / npu-amd-linux (push) Has been cancelled
CI (windows) / windows-msys2 (Release, clang, clang-x86_64, CLANG64) (push) Has been cancelled
CI (windows) / windows-msys2 (Release, gcc, ucrt-x86_64, UCRT64) (push) Has been cancelled
Publish Docker image / Push Docker image to Docker Hub (map[dockerfile:.devops/main-cuda.Dockerfile platform:linux/amd64 runs_on:ubuntu-24.04 tag:main-cuda]) (push) Has been cancelled
Publish Docker image / Push Docker image to Docker Hub (map[dockerfile:.devops/main-intel.Dockerfile platform:linux/amd64 runs_on:ubuntu-24.04 tag:main-intel]) (push) Has been cancelled
Publish Docker image / Push Docker image to Docker Hub (map[dockerfile:.devops/main-musa.Dockerfile platform:linux/amd64 runs_on:ubuntu-24.04 tag:main-musa]) (push) Has been cancelled
Publish Docker image / Push Docker image to Docker Hub (map[dockerfile:.devops/main-vulkan.Dockerfile platform:linux/amd64 runs_on:ubuntu-24.04 tag:main-vulkan]) (push) Has been cancelled
Publish Docker image / Push Docker image to Docker Hub (map[dockerfile:.devops/main-vulkan.Dockerfile platform:linux/arm64 runs_on:ubuntu-24.04-arm tag:main-vulkan-arm64]) (push) Has been cancelled
Publish Docker image / Push Docker image to Docker Hub (map[dockerfile:.devops/main.Dockerfile platform:linux/amd64 runs_on:ubuntu-24.04 tag:main]) (push) Has been cancelled
Publish Docker image / Push Docker image to Docker Hub (map[dockerfile:.devops/main.Dockerfile platform:linux/arm64 runs_on:ubuntu-24.04-arm tag:main-arm64]) (push) Has been cancelled
Mark inactive issues stale / mark-issues (push) Failing after 1s
158 lines
4.4 KiB
C
158 lines
4.4 KiB
C
#include "ruby_whisper.h"
|
|
|
|
#define ITERATE_ATTRS(ITERATOR) \
|
|
ITERATOR(start_time, t0, TIME) \
|
|
ITERATOR(end_time, t1, TIME) \
|
|
ITERATOR(text, text, STRING)
|
|
|
|
enum {
|
|
#define DEF_IDX(name, c_name, type) RUBY_WHISPER_PARAKEET_SEGMENT_##name,
|
|
|
|
ITERATE_ATTRS(DEF_IDX)
|
|
RUBY_WHISPER_PARAKEET_SEGMENT_NUM_ATTRS,
|
|
};
|
|
|
|
#define VAL_FROM_TIME(v) (LONG2NUM((v) * 10))
|
|
#define VAL_FROM_STRING(v) (rb_str_new2(v))
|
|
#define READER(type) VAL_FROM_##type
|
|
#define DEF_ATTR(rb_name, c_name, type) \
|
|
static VALUE \
|
|
ruby_whisper_parakeet_get_##rb_name(VALUE self) \
|
|
{ \
|
|
ruby_whisper_parakeet_segment *rwps; \
|
|
GetParakeetSegment(self, rwps); \
|
|
ruby_whisper_parakeet_context *rwpc; \
|
|
GetParakeetContext(rwps->context, rwpc); \
|
|
return READER(type)(parakeet_full_get_segment_##c_name(rwpc->context, rwps->index)); \
|
|
}
|
|
|
|
extern ID id___method__;
|
|
extern ID id_to_enum;
|
|
extern VALUE cParakeetSegment;
|
|
extern VALUE sym_start_time;
|
|
extern VALUE sym_end_time;
|
|
extern VALUE sym_text;
|
|
extern const rb_data_type_t ruby_whisper_parakeet_context_type;
|
|
extern VALUE ruby_whisper_parakeet_token_s_from_index(struct parakeet_context *context, int i_segment, int i_token);
|
|
|
|
static void
|
|
rb_whisper_parakeet_segment_mark(void *p)
|
|
{
|
|
ruby_whisper_parakeet_segment *rwps = (ruby_whisper_parakeet_segment *)p;
|
|
rb_gc_mark(rwps->context);
|
|
}
|
|
|
|
static size_t
|
|
ruby_whisper_parakeet_segment_memsize(const void *p)
|
|
{
|
|
const ruby_whisper_parakeet_segment *rwps = (const ruby_whisper_parakeet_segment *)p;
|
|
if (!rwps) {
|
|
return 0;
|
|
}
|
|
return sizeof(*rwps);
|
|
}
|
|
|
|
static const rb_data_type_t ruby_whisper_parakeet_segment_type = {
|
|
"ruby_whisper_parakeet_segment",
|
|
{rb_whisper_parakeet_segment_mark, RUBY_DEFAULT_FREE, ruby_whisper_parakeet_segment_memsize,},
|
|
0, 0,
|
|
0
|
|
};
|
|
|
|
static VALUE
|
|
ruby_whisper_parakeet_segment_s_allocate(VALUE klass)
|
|
{
|
|
ruby_whisper_parakeet_segment *rwps;
|
|
return TypedData_Make_Struct(klass, ruby_whisper_parakeet_segment, &ruby_whisper_parakeet_segment_type, rwps);
|
|
}
|
|
|
|
VALUE
|
|
ruby_whisper_parakeet_segment_init(VALUE context, int index)
|
|
{
|
|
ruby_whisper_parakeet_segment *rwps;
|
|
|
|
const VALUE segment = ruby_whisper_parakeet_segment_s_allocate(cParakeetSegment);
|
|
TypedData_Get_Struct(segment, ruby_whisper_parakeet_segment, &ruby_whisper_parakeet_segment_type, rwps);
|
|
rwps->context = context;
|
|
rwps->index = index;
|
|
|
|
return segment;
|
|
}
|
|
|
|
ITERATE_ATTRS(DEF_ATTR)
|
|
|
|
static VALUE
|
|
ruby_whisper_parakeet_segment_each_token(VALUE self)
|
|
{
|
|
if (!rb_block_given_p()) {
|
|
const VALUE method_name = rb_funcall(self, id___method__, 0);
|
|
return rb_funcall(self, id_to_enum, 1, method_name);
|
|
}
|
|
|
|
ruby_whisper_parakeet_segment *rwps;
|
|
GetParakeetSegment(self, rwps);
|
|
ruby_whisper_parakeet_context *rwpc;
|
|
GetParakeetContext(rwps->context, rwpc);
|
|
|
|
const int n_tokens = parakeet_full_n_tokens(rwpc->context, rwps->index);
|
|
for (int i = 0; i < n_tokens; i++) {
|
|
rb_yield(ruby_whisper_parakeet_token_s_from_index(rwpc->context, rwps->index, i));
|
|
}
|
|
|
|
return self;
|
|
}
|
|
|
|
static VALUE
|
|
ruby_whisper_parakeet_segment_deconstruct_keys(VALUE self, VALUE keys)
|
|
{
|
|
ruby_whisper_parakeet_segment *rwps;
|
|
GetParakeetSegment(self, rwps);
|
|
ruby_whisper_parakeet_context *rwpc;
|
|
GetParakeetContext(rwps->context, rwpc);
|
|
|
|
VALUE hash = rb_hash_new();
|
|
long n_keys;
|
|
if (NIL_P(keys)) {
|
|
keys = rb_ary_new3(
|
|
RUBY_WHISPER_PARAKEET_SEGMENT_NUM_ATTRS,
|
|
sym_start_time,
|
|
sym_end_time,
|
|
sym_text
|
|
);
|
|
n_keys = RUBY_WHISPER_PARAKEET_SEGMENT_NUM_ATTRS;
|
|
} else {
|
|
n_keys = RARRAY_LEN(keys);
|
|
if (n_keys > RUBY_WHISPER_PARAKEET_SEGMENT_NUM_ATTRS) {
|
|
return hash;
|
|
}
|
|
}
|
|
for (int i = 0; i < n_keys; i++) {
|
|
VALUE key = rb_ary_entry(keys, i);
|
|
|
|
#define CHECK_AND_SET_KEY(rb_name, c_name, type) \
|
|
if (key == sym_##rb_name) { \
|
|
rb_hash_aset(hash, key, ruby_whisper_parakeet_get_##rb_name(self)); \
|
|
}
|
|
|
|
ITERATE_ATTRS(CHECK_AND_SET_KEY)
|
|
}
|
|
|
|
return hash;
|
|
}
|
|
|
|
void
|
|
init_ruby_whisper_parakeet_segment(VALUE *mParakeet)
|
|
{
|
|
cParakeetSegment = rb_define_class_under(*mParakeet, "Segment", rb_cObject);
|
|
|
|
rb_define_alloc_func(cParakeetSegment, ruby_whisper_parakeet_segment_s_allocate);
|
|
|
|
#define REGISTER_ATTR(rb_name, c_name, type) \
|
|
rb_define_method(cParakeetSegment, #rb_name, ruby_whisper_parakeet_get_##rb_name, 0);
|
|
|
|
ITERATE_ATTRS(REGISTER_ATTR)
|
|
|
|
rb_define_method(cParakeetSegment, "each_token", ruby_whisper_parakeet_segment_each_token, 0);
|
|
rb_define_method(cParakeetSegment, "deconstruct_keys", ruby_whisper_parakeet_segment_deconstruct_keys, 1);
|
|
}
|