]> git.djapps.eu Git - pkg/ggml/sources/whisper.cpp/commitdiff
whisper : fix model path encoding in windows (#2086)
authorthewh1teagle <redacted>
Tue, 14 May 2024 06:43:41 +0000 (09:43 +0300)
committerGitHub <redacted>
Tue, 14 May 2024 06:43:41 +0000 (09:43 +0300)
* fix: model path encoding in windows

* fix: convert model path to wide string only for MSVC compiler

whisper.cpp

index bdcf3de40e25cda20098ec974f6c83c8c5434b21..ff4223daf429ea416261f6fea3256fa2cdf203df 100644 (file)
@@ -41,6 +41,7 @@
 #include <regex>
 #include <random>
 #include <functional>
+#include <codecvt>
 
 #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<std::codecvt_utf8<wchar_t>> 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;