From 08a793699d787d421fd992ed02cac5e809458d18 Mon Sep 17 00:00:00 2001 From: Dennis Parker Date: Mon, 22 Dec 2025 12:54:14 -0600 Subject: [PATCH 1/2] Applied change to copy constructor suggested by absadiki and tested on Framework laptop with and without Vulkan support --- src/main.cpp | 62 +++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 61 insertions(+), 1 deletion(-) diff --git a/src/main.cpp b/src/main.cpp index a2c46cb..47f5d8a 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -295,7 +295,7 @@ int whisper_ctx_init_openvino_encoder_wrapper(struct whisper_context_wrapper * c const char * cache_dir){ return whisper_ctx_init_openvino_encoder(ctx->ptr, model_path, device, cache_dir); } - +/* class WhisperFullParamsWrapper : public whisper_full_params { std::string initial_prompt_str; std::string suppress_regex_str; @@ -338,6 +338,66 @@ class WhisperFullParamsWrapper : public whisper_full_params { } }; +*/ +struct WhisperFullParamsWrapper : public whisper_full_params { + std::string initial_prompt_str; + std::string suppress_regex_str; +public: + py::function py_progress_callback; + WhisperFullParamsWrapper(const whisper_full_params& params = whisper_full_params()) + : whisper_full_params(params), + initial_prompt_str(params.initial_prompt ? params.initial_prompt : ""), + suppress_regex_str(params.suppress_regex ? params.suppress_regex : "") { + initial_prompt = initial_prompt_str.empty() ? nullptr : initial_prompt_str.c_str(); + suppress_regex = suppress_regex_str.empty() ? nullptr : suppress_regex_str.c_str(); + // progress callback + progress_callback_user_data = this; + progress_callback = [](struct whisper_context* ctx, struct whisper_state* state, int progress, void* user_data) { + auto* self = static_cast(user_data); + if(self && self->print_progress){ + if (self->py_progress_callback) { + // call the python callback + py::gil_scoped_acquire gil; + self->py_progress_callback(progress); // Call Python callback + } + else { + fprintf(stderr, "Progress: %3d%%\n", progress); + } // Default message + } + } ; + } + WhisperFullParamsWrapper(const WhisperFullParamsWrapper& other) + : whisper_full_params(static_cast(other)), // Copy base struct + initial_prompt_str(other.initial_prompt_str), + suppress_regex_str(other.suppress_regex_str), + py_progress_callback(other.py_progress_callback) { + // Reset pointers to new string copies + initial_prompt = initial_prompt_str.empty() ? nullptr : initial_prompt_str.c_str(); + suppress_regex = suppress_regex_str.empty() ? nullptr : suppress_regex_str.c_str(); + progress_callback_user_data = this; + progress_callback = [](struct whisper_context* ctx, struct whisper_state* state, int progress, void* user_data) { + auto* self = static_cast(user_data); + if(self && self->print_progress){ + if (self->py_progress_callback) { + // call the python callback + py::gil_scoped_acquire gil; + self->py_progress_callback(progress); // Call Python callback + } + else { + fprintf(stderr, "Progress: %3d%%\n", progress); + } // Default message + } + }; + } + void set_initial_prompt(const std::string& prompt) { + initial_prompt_str = prompt; + initial_prompt = initial_prompt_str.c_str(); + } + void set_suppress_regex(const std::string& regex) { + suppress_regex_str = regex; + suppress_regex = suppress_regex_str.c_str(); + } +}; WhisperFullParamsWrapper whisper_full_default_params_wrapper(enum whisper_sampling_strategy strategy) { return WhisperFullParamsWrapper(whisper_full_default_params(strategy)); } From ed01e78ac6d92fc3e638ef47d2c54d7bd8a1cf4f Mon Sep 17 00:00:00 2001 From: Dennis Parker Date: Sat, 27 Dec 2025 16:26:44 -0600 Subject: [PATCH 2/2] Remove commented-out WhisperFullParamsWrapper Removed commented-out class definition for WhisperFullParamsWrapper. --- src/main.cpp | 43 ------------------------------------------- 1 file changed, 43 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 47f5d8a..6f36bc4 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -295,50 +295,7 @@ int whisper_ctx_init_openvino_encoder_wrapper(struct whisper_context_wrapper * c const char * cache_dir){ return whisper_ctx_init_openvino_encoder(ctx->ptr, model_path, device, cache_dir); } -/* -class WhisperFullParamsWrapper : public whisper_full_params { - std::string initial_prompt_str; - std::string suppress_regex_str; -public: - py::function py_progress_callback; - WhisperFullParamsWrapper(const whisper_full_params& params = whisper_full_params()) - : whisper_full_params(params), - initial_prompt_str(params.initial_prompt ? params.initial_prompt : ""), - suppress_regex_str(params.suppress_regex ? params.suppress_regex : "") { - initial_prompt = initial_prompt_str.empty() ? nullptr : initial_prompt_str.c_str(); - suppress_regex = suppress_regex_str.empty() ? nullptr : suppress_regex_str.c_str(); - // progress callback - progress_callback_user_data = this; - progress_callback = [](struct whisper_context* ctx, struct whisper_state* state, int progress, void* user_data) { - auto* self = static_cast(user_data); - if(self && self->print_progress){ - if (self->py_progress_callback) { - // call the python callback - py::gil_scoped_acquire gil; - self->py_progress_callback(progress); // Call Python callback - } - else { - fprintf(stderr, "Progress: %3d%%\n", progress); - } // Default message - } - } ; - } - - WhisperFullParamsWrapper(const WhisperFullParamsWrapper& other) - : WhisperFullParamsWrapper(static_cast(other)) {} - - void set_initial_prompt(const std::string& prompt) { - initial_prompt_str = prompt; - initial_prompt = initial_prompt_str.c_str(); - } - - void set_suppress_regex(const std::string& regex) { - suppress_regex_str = regex; - suppress_regex = suppress_regex_str.c_str(); - } -}; -*/ struct WhisperFullParamsWrapper : public whisper_full_params { std::string initial_prompt_str; std::string suppress_regex_str;