From 267cdda97d84659ed413ade0db4c7586d329a1f0 Mon Sep 17 00:00:00 2001 From: Takayuki Matsuoka Date: Sun, 23 Apr 2023 19:25:56 +0900 Subject: [PATCH 1/3] Fix: retrieve canonical executable path in Windows environment --- src/cpp/main.cpp | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/cpp/main.cpp b/src/cpp/main.cpp index c47ec68..f827d47 100644 --- a/src/cpp/main.cpp +++ b/src/cpp/main.cpp @@ -15,6 +15,12 @@ #include #endif +#ifdef _MSC_VER +#define WIN32_LEAN_AND_MEAN +#define NOMINMAX +#include +#endif + #include "piper.hpp" using namespace std; @@ -54,7 +60,15 @@ int main(int argc, char *argv[]) { parseArgs(argc, argv, runConfig); // NOTE: This won't work for Windows (need GetModuleFileName) +#ifdef _MSC_VER + auto exePath = []() { + wchar_t moduleFileName[MAX_PATH] = { 0 }; + GetModuleFileNameW(nullptr, moduleFileName, std::size(moduleFileName)); + return filesystem::path(moduleFileName); + }(); +#else auto exePath = filesystem::canonical("/proc/self/exe"); +#endif piper::initialize(exePath.parent_path()); piper::Voice voice; From 5cf014ff266612db5ebc15ab6348df8dcd6de659 Mon Sep 17 00:00:00 2001 From: Takayuki Matsuoka Date: Sun, 23 Apr 2023 19:26:57 +0900 Subject: [PATCH 2/3] Fix: improve compatibility with ORTCHAR_T --- src/cpp/model.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cpp/model.hpp b/src/cpp/model.hpp index 4adcf82..01070a7 100644 --- a/src/cpp/model.hpp +++ b/src/cpp/model.hpp @@ -43,7 +43,7 @@ void loadModel(string modelPath, ModelSession &session) { session.options.DisableProfiling(); auto startTime = chrono::steady_clock::now(); - session.onnx = Ort::Session(session.env, modelPath.c_str(), session.options); + session.onnx = Ort::Session(session.env, filesystem::path(modelPath).c_str(), session.options); auto endTime = chrono::steady_clock::now(); auto loadDuration = chrono::duration(endTime - startTime); } From 9e973fc73e9e564a0b6e0f09a3793521405cf980 Mon Sep 17 00:00:00 2001 From: Takayuki Matsuoka Date: Sun, 23 Apr 2023 19:27:33 +0900 Subject: [PATCH 3/3] Fix: improve compatibility with Windows' filesystem::path --- src/cpp/piper.hpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/cpp/piper.hpp b/src/cpp/piper.hpp index 7f07afc..933d8cc 100644 --- a/src/cpp/piper.hpp +++ b/src/cpp/piper.hpp @@ -28,17 +28,19 @@ struct Voice { }; void initialize(std::filesystem::path cwd) { - const char *dataPath = NULL; + string dataPath; auto cwdDataPath = std::filesystem::absolute(cwd.append("espeak-ng-data")); if (std::filesystem::is_directory(cwdDataPath)) { - dataPath = cwdDataPath.c_str(); + dataPath = cwdDataPath.string(); } + cerr << "dataPath: " << dataPath << endl; + // Set up espeak-ng for calling espeak_TextToPhonemes int result = espeak_Initialize(AUDIO_OUTPUT_SYNCHRONOUS, /*buflength*/ 0, - /*path*/ dataPath, + /*path*/ dataPath.c_str(), /*options*/ 0); if (result < 0) { throw runtime_error("Failed to initialize eSpeak-ng");