Skip to content

Commit

Permalink
whisper : fix model path encoding in windows (#2086)
Browse files Browse the repository at this point in the history
* fix: model path encoding in windows

* fix: convert model path to wide string only for MSVC compiler
  • Loading branch information
thewh1teagle committed May 14, 2024
1 parent 4ef8d9f commit d8356a1
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion whisper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit d8356a1

Please sign in to comment.