@@ -2654,7 +2654,7 @@ static std::string whisper_get_coreml_path_encoder(std::string path_bin) {
2654
2654
2655
2655
#ifdef WHISPER_USE_OPENVINO
2656
2656
// 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) {
2658
2658
auto pos = path_bin.rfind (' .' );
2659
2659
if (pos != std::string::npos) {
2660
2660
path_bin = path_bin.substr (0 , pos);
@@ -2665,7 +2665,7 @@ static std::string whisper_get_openvino_path_encoder(std::string path_bin) {
2665
2665
return path_bin;
2666
2666
}
2667
2667
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) {
2669
2669
auto pos = path_bin.rfind (' .' );
2670
2670
if (pos != std::string::npos) {
2671
2671
path_bin = path_bin.substr (0 , pos);
@@ -2743,55 +2743,52 @@ struct whisper_state * whisper_init_state(whisper_context * ctx) {
2743
2743
return state;
2744
2744
}
2745
2745
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) {
2751
2751
#ifndef WHISPER_USE_OPENVINO
2752
2752
(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 ;
2757
2758
#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 ;
2762
2762
}
2763
2763
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;
2771
2770
}
2772
2771
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;
2780
2778
}
2781
2779
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 ());
2783
2781
fprintf (stderr, " %s: first run on a device may take a while ...\n " , __func__);
2784
2782
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 ());
2786
2784
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 {
2791
2788
fprintf (stderr, " %s: OpenVINO model loaded\n " , __func__);
2792
2789
}
2793
2790
2794
- return 1 ;
2791
+ return 0 ;
2795
2792
#endif
2796
2793
}
2797
2794
0 commit comments