mirror of
https://github.com/pstrueb/piper.git
synced 2026-06-01 09:27:02 +00:00
Merge pull request #47 from t-mat/msvc-2
Improve path related compatibility in C++
This commit is contained in:
@@ -15,6 +15,12 @@
|
||||
#include <pcaudiolib/audio.h>
|
||||
#endif
|
||||
|
||||
#ifdef _MSC_VER
|
||||
#define WIN32_LEAN_AND_MEAN
|
||||
#define NOMINMAX
|
||||
#include <windows.h>
|
||||
#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;
|
||||
|
||||
+1
-1
@@ -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<double>(endTime - startTime);
|
||||
}
|
||||
|
||||
+5
-3
@@ -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");
|
||||
|
||||
Reference in New Issue
Block a user