Spaces:
Running
Running
thewh1teagle
commited on
whisper : fix model path encoding in windows (#2086)
Browse files* fix: model path encoding in windows
* fix: convert model path to wide string only for MSVC compiler
- whisper.cpp +8 -1
whisper.cpp
CHANGED
|
@@ -41,6 +41,7 @@
|
|
| 41 |
#include <regex>
|
| 42 |
#include <random>
|
| 43 |
#include <functional>
|
|
|
|
| 44 |
|
| 45 |
#if defined(_MSC_VER)
|
| 46 |
#pragma warning(disable: 4244 4267) // possible loss of data
|
|
@@ -3362,8 +3363,14 @@ struct whisper_context_params whisper_context_default_params() {
|
|
| 3362 |
|
| 3363 |
struct whisper_context * whisper_init_from_file_with_params_no_state(const char * path_model, struct whisper_context_params params) {
|
| 3364 |
WHISPER_LOG_INFO("%s: loading model from '%s'\n", __func__, path_model);
|
| 3365 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3366 |
auto fin = std::ifstream(path_model, std::ios::binary);
|
|
|
|
| 3367 |
if (!fin) {
|
| 3368 |
WHISPER_LOG_ERROR("%s: failed to open '%s'\n", __func__, path_model);
|
| 3369 |
return nullptr;
|
|
|
|
| 41 |
#include <regex>
|
| 42 |
#include <random>
|
| 43 |
#include <functional>
|
| 44 |
+
#include <codecvt>
|
| 45 |
|
| 46 |
#if defined(_MSC_VER)
|
| 47 |
#pragma warning(disable: 4244 4267) // possible loss of data
|
|
|
|
| 3363 |
|
| 3364 |
struct whisper_context * whisper_init_from_file_with_params_no_state(const char * path_model, struct whisper_context_params params) {
|
| 3365 |
WHISPER_LOG_INFO("%s: loading model from '%s'\n", __func__, path_model);
|
| 3366 |
+
#ifdef _MSC_VER
|
| 3367 |
+
// Convert UTF-8 path to wide string (UTF-16) for Windows, resolving character encoding issues.
|
| 3368 |
+
std::wstring_convert<std::codecvt_utf8<wchar_t>> converter;
|
| 3369 |
+
std::wstring path_model_wide = converter.from_bytes(path_model);
|
| 3370 |
+
auto fin = std::ifstream(path_model_wide, std::ios::binary);
|
| 3371 |
+
#else
|
| 3372 |
auto fin = std::ifstream(path_model, std::ios::binary);
|
| 3373 |
+
#endif
|
| 3374 |
if (!fin) {
|
| 3375 |
WHISPER_LOG_ERROR("%s: failed to open '%s'\n", __func__, path_model);
|
| 3376 |
return nullptr;
|