-
Notifications
You must be signed in to change notification settings - Fork 465
Expand file tree
/
Copy pathmain.cpp
More file actions
120 lines (100 loc) · 2.93 KB
/
Copy pathmain.cpp
File metadata and controls
120 lines (100 loc) · 2.93 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
#include <chrono>
#include <condition_variable>
#include <filesystem>
#include <fstream>
#include <functional>
#include <iostream>
#include <map>
#include <sstream>
#include <stdexcept>
#include <string>
#include <thread>
#include <vector>
#ifdef _MSC_VER
#define WIN32_LEAN_AND_MEAN
#define NOMINMAX
#include <windows.h>
#endif
#ifdef _WIN32
#include <fcntl.h>
#include <io.h>
#endif
#ifdef __APPLE__
#include <mach-o/dyld.h>
#endif
#include "utils/main_utils.hpp"
#include "utils/process.hpp"
#include "json.hpp"
#include "piper.h"
#include "piper_impl.hpp"
using namespace std;
// ----------------------------------------------------------------------------
int main(int argc, char *argv[]) {
piper::RunConfig runConfig;
parseArgs(argc, argv, runConfig);
#ifdef _WIN32
// Required on Windows to show IPA symbols
SetConsoleOutputCP(CP_UTF8);
#endif
piper_synthesizer *piper;
// Get the path to the piper executable so we can locate espeak-ng-data, etc.
// next to it.
#ifdef _MSC_VER
auto exePath = []() {
wchar_t moduleFileName[MAX_PATH] = {0};
GetModuleFileNameW(nullptr, moduleFileName, std::size(moduleFileName));
return filesystem::path(moduleFileName);
}();
#else
#ifdef __APPLE__
auto exePath = []() {
char moduleFileName[PATH_MAX] = {0};
uint32_t moduleFileNameSize = std::size(moduleFileName);
_NSGetExecutablePath(moduleFileName, &moduleFileNameSize);
return filesystem::path(moduleFileName);
}();
#else
auto exePath = filesystem::canonical("/proc/self/exe");
#endif
#endif
if (runConfig.eSpeakDataPath) {
// User provided path
runConfig.eSpeakDataPath = runConfig.eSpeakDataPath.value().string();
} else {
// Assume next to piper executable
runConfig.eSpeakDataPath =
std::filesystem::absolute(
exePath.parent_path().append("espeak-ng-data"))
.string();
}
auto startTime = chrono::steady_clock::now();
piper = piper_create(runConfig.modelPath.string().c_str(),
runConfig.modelConfigPath.string().c_str(),
runConfig.eSpeakDataPath->string().c_str());
auto endTime = chrono::steady_clock::now();
piper_synthesize_options options;
options.speaker_id = 0;
options.length_scale = DEFAULT_LENGTH_SCALE;
options.noise_scale = DEFAULT_NOISE_SCALE;
options.noise_w_scale = DEFAULT_NOISE_W_SCALE;
// Speaker ID
if (runConfig.speakerId) {
options.speaker_id = runConfig.speakerId.value();
}
// Scales
if (runConfig.noiseScale) {
options.noise_scale = runConfig.noiseScale.value();
}
if (runConfig.lengthScale) {
options.length_scale = runConfig.lengthScale.value();
}
if (runConfig.noiseW) {
options.noise_w_scale = runConfig.noiseW.value();
}
if (runConfig.outputType == piper::OUTPUT_DIRECTORY) {
runConfig.outputPath = filesystem::absolute(runConfig.outputPath.value());
}
processInputStream(runConfig, piper, &options);
piper_free(piper);
return EXIT_SUCCESS;
}