@@ -2654,7 +2654,7 @@ static std::string whisper_get_coreml_path_encoder(std::string path_bin) {
26542654
26552655#ifdef WHISPER_USE_OPENVINO
26562656// replace .bin with-encoder-openvino.xml
2657- static std::string whisper_get_openvino_path_encoder (std::string path_bin) {
2657+ static std::string whisper_openvino_get_path_encoder (std::string path_bin) {
26582658 auto pos = path_bin.rfind (' .' );
26592659 if (pos != std::string::npos) {
26602660 path_bin = path_bin.substr (0 , pos);
@@ -2665,7 +2665,7 @@ static std::string whisper_get_openvino_path_encoder(std::string path_bin) {
26652665 return path_bin;
26662666}
26672667
2668- static std::string whisper_get_openvino_path_cache (std::string path_bin) {
2668+ static std::string whisper_openvino_get_path_cache (std::string path_bin) {
26692669 auto pos = path_bin.rfind (' .' );
26702670 if (pos != std::string::npos) {
26712671 path_bin = path_bin.substr (0 , pos);
@@ -2743,55 +2743,52 @@ struct whisper_state * whisper_init_state(whisper_context * ctx) {
27432743 return state;
27442744}
27452745
2746- int whisper_ctx_init_openvino_encoder (struct whisper_context * ctx,
2747- const char * openvino_model_path ,
2748- const char * openvino_device ,
2749- const char * openvino_cache_dir)
2750- {
2746+ int whisper_ctx_init_openvino_encoder (
2747+ struct whisper_context * ctx ,
2748+ const char * model_path ,
2749+ const char * device,
2750+ const char * cache_dir) {
27512751#ifndef WHISPER_USE_OPENVINO
27522752 (void )(ctx);
2753- (void )(openvino_model_path);
2754- (void )(openvino_device);
2755- (void )(openvino_cache_dir);
2756- return 0 ;
2753+ (void )(model_path);
2754+ (void )(device);
2755+ (void )(cache_dir);
2756+
2757+ return 1 ;
27572758#else
2758- if (!openvino_model_path && ctx->path_model .empty ())
2759- {
2760- fprintf (stderr, " %s: openvino_model_path is nullptr, and ctx has no model_path set.\n " , __func__);
2761- return 0 ;
2759+ if (!model_path && ctx->path_model .empty ()) {
2760+ fprintf (stderr, " %s: model_path is nullptr, and ctx has no model_path set.\n " , __func__);
2761+ return 1 ;
27622762 }
27632763
2764- std::string path_openvino;
2765- if (!openvino_model_path) {
2766- // if openvino_model_path is not set, attempt to find it in the same directory as ggml-<model>.bin model
2767- path_openvino = whisper_get_openvino_path_encoder (ctx->path_model );
2768- }
2769- else {
2770- path_openvino = openvino_model_path;
2764+ std::string path_encoder;
2765+ if (!model_path) {
2766+ // if model_path is not set, attempt to find it in the same directory as ggml-<model>.bin model
2767+ path_encoder = whisper_openvino_get_path_encoder (ctx->path_model );
2768+ } else {
2769+ path_encoder = model_path;
27712770 }
27722771
2773- std::string path_openvino_cache_dir;
2774- if (!openvino_cache_dir) {
2775- // if openvino_cache_dir is not set, set it as a dir residing next to ggml-<model>.bin
2776- path_openvino_cache_dir = whisper_get_openvino_path_cache (ctx->path_model );
2777- }
2778- else {
2779- path_openvino_cache_dir = openvino_cache_dir;
2772+ std::string path_cache;
2773+ if (!cache_dir) {
2774+ // if cache_dir is not set, set it as a dir residing next to ggml-<model>.bin
2775+ path_cache = whisper_openvino_get_path_cache (ctx->path_model );
2776+ } else {
2777+ path_cache = cache_dir;
27802778 }
27812779
2782- fprintf (stderr, " %s: loading OpenVINO model from '%s'\n " , __func__, path_openvino .c_str ());
2780+ fprintf (stderr, " %s: loading OpenVINO model from '%s'\n " , __func__, path_encoder .c_str ());
27832781 fprintf (stderr, " %s: first run on a device may take a while ...\n " , __func__);
27842782
2785- ctx->state ->ctx_openvino = whisper_openvino_init (path_openvino .c_str (), openvino_device, path_openvino_cache_dir .c_str ());
2783+ ctx->state ->ctx_openvino = whisper_openvino_init (path_encoder .c_str (), device, path_cache .c_str ());
27862784 if (!ctx->state ->ctx_openvino ) {
2787- fprintf (stderr, " %s: failed to init OpenVINO encoder from '%s'\n " , __func__, path_openvino.c_str ());
2788- return 0 ;
2789- }
2790- else {
2785+ fprintf (stderr, " %s: failed to init OpenVINO encoder from '%s'\n " , __func__, path_encoder.c_str ());
2786+ return 1 ;
2787+ } else {
27912788 fprintf (stderr, " %s: OpenVINO model loaded\n " , __func__);
27922789 }
27932790
2794- return 1 ;
2791+ return 0 ;
27952792#endif
27962793}
27972794
0 commit comments