@@ -77,25 +77,27 @@ struct whisper_context *init_whisper_context(const std::string &model_path)
77
77
obs_log (LOG_INFO, " Loading whisper model from %s" , model_path.c_str ());
78
78
79
79
#ifdef _WIN32
80
- // convert model path UTF8 to wstring (wchar_t) for whisper
81
- int count = MultiByteToWideChar (CP_UTF8, 0 , model_path.c_str (), (int )model_path.length (), NULL , 0 );
82
- std::wstring model_path_ws (count, 0 );
83
- MultiByteToWideChar (CP_UTF8, 0 , model_path.c_str (), (int )model_path.length (), &model_path_ws[0 ], count);
84
-
85
- // Read model into buffer
86
- std::ifstream modelFile (model_path_ws, std::ios::binary);
87
- if (!modelFile.is_open ()) {
88
- obs_log (LOG_ERROR, " Failed to open whisper model file %s" , model_path.c_str ());
89
- return nullptr ;
90
- }
91
- modelFile.seekg (0 , std::ios::end);
92
- const size_t modelFileSize = modelFile.tellg ();
93
- modelFile.seekg (0 , std::ios::beg);
94
- std::vector<char > modelBuffer (modelFileSize);
95
- modelFile.read (modelBuffer.data (), modelFileSize);
96
- modelFile.close ();
97
-
98
- // Initialize whisper
80
+ // convert model path UTF8 to wstring (wchar_t) for whisper
81
+ int count = MultiByteToWideChar (CP_UTF8, 0 , model_path.c_str (), (int )model_path.length (),
82
+ NULL , 0 );
83
+ std::wstring model_path_ws (count, 0 );
84
+ MultiByteToWideChar (CP_UTF8, 0 , model_path.c_str (), (int )model_path.length (),
85
+ &model_path_ws[0 ], count);
86
+
87
+ // Read model into buffer
88
+ std::ifstream modelFile (model_path_ws, std::ios::binary);
89
+ if (!modelFile.is_open ()) {
90
+ obs_log (LOG_ERROR, " Failed to open whisper model file %s" , model_path.c_str ());
91
+ return nullptr ;
92
+ }
93
+ modelFile.seekg (0 , std::ios::end);
94
+ const size_t modelFileSize = modelFile.tellg ();
95
+ modelFile.seekg (0 , std::ios::beg);
96
+ std::vector<char > modelBuffer (modelFileSize);
97
+ modelFile.read (modelBuffer.data (), modelFileSize);
98
+ modelFile.close ();
99
+
100
+ // Initialize whisper
99
101
struct whisper_context *ctx = whisper_init_from_buffer (modelBuffer.data (), modelFileSize);
100
102
#else
101
103
struct whisper_context *ctx = whisper_init_from_file (model_path.c_str ());
0 commit comments