From: thewh1teagle Date: Tue, 14 May 2024 06:43:41 +0000 (+0300) Subject: whisper : fix model path encoding in windows (whisper/2086) X-Git-Tag: upstream/0.0.1642~703 X-Git-Url: https://git.djapps.eu/?a=commitdiff_plain;h=1ecd55e91a528254ede9f3cdfd9b352e9bc98e48;p=pkg%2Fggml%2Fsources%2Fggml whisper : fix model path encoding in windows (whisper/2086) * fix: model path encoding in windows * fix: convert model path to wide string only for MSVC compiler --- diff --git a/examples/whisper/whisper.cpp b/examples/whisper/whisper.cpp index bdcf3de4..ff4223da 100644 --- a/examples/whisper/whisper.cpp +++ b/examples/whisper/whisper.cpp @@ -41,6 +41,7 @@ #include #include #include +#include #if defined(_MSC_VER) #pragma warning(disable: 4244 4267) // possible loss of data @@ -3362,8 +3363,14 @@ struct whisper_context_params whisper_context_default_params() { struct whisper_context * whisper_init_from_file_with_params_no_state(const char * path_model, struct whisper_context_params params) { WHISPER_LOG_INFO("%s: loading model from '%s'\n", __func__, path_model); - +#ifdef _MSC_VER + // Convert UTF-8 path to wide string (UTF-16) for Windows, resolving character encoding issues. + std::wstring_convert> converter; + std::wstring path_model_wide = converter.from_bytes(path_model); + auto fin = std::ifstream(path_model_wide, std::ios::binary); +#else auto fin = std::ifstream(path_model, std::ios::binary); +#endif if (!fin) { WHISPER_LOG_ERROR("%s: failed to open '%s'\n", __func__, path_model); return nullptr;