Skip to content

Commit

Permalink
added logging
Browse files Browse the repository at this point in the history
  • Loading branch information
deguodedongxi committed Dec 19, 2024
1 parent 49e67a8 commit 07eb79e
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 5 deletions.
10 changes: 10 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,13 @@ htmlcov

.venv/
lightning_logs/
.vs/
.vscode/

**/*.Identifier

**/models

**/audio

**/espeak**
Binary file added src/cpp/libtashkeel_model.ort
Binary file not shown.
Binary file added src/cpp/onnxruntime.dll
Binary file not shown.
Binary file added src/cpp/onnxruntime_providers_shared.dll
Binary file not shown.
Binary file added src/cpp/piper_phonemize.dll
Binary file not shown.
31 changes: 26 additions & 5 deletions src/cpp/server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -138,25 +138,33 @@ int main(int argc, char *argv[])
try {
RunConfig runConfig;
// // Log Body
// std::cout << "Request body: " << req.body << std::endl;
std::cout << "Request body: " << req.body << std::endl;
parseArgsFromJson(json::parse(req.body), runConfig);

#ifdef _WIN32
// Required on Windows to show IPA symbols
SetConsoleOutputCP(CP_UTF8);
#endif

std::cout << "Model Path: " << runConfig.modelPath << std::endl;
std::cout << "Sentence: " << runConfig.sentence << std::endl;
std::cout << "Output Path: " << runConfig.outputPath.value().string() << std::endl;
std::cout << "Use CUDA: " << runConfig.useCuda << std::endl;

if (modelPath != runConfig.modelPath.string())
{
spdlog::debug("Loading voice from {} (config={})",
runConfig.modelPath.string(),
runConfig.modelConfigPath.string());
auto startTime = chrono::steady_clock::now();
modelPath = runConfig.modelPath.string();
std::cout << "Loading voice from " << runConfig.modelPath.string() << " (config=" << runConfig.modelConfigPath.string() << ")" << std::endl;
piper::loadVoice(piperConfig, runConfig.modelPath.string(),
runConfig.modelConfigPath.string(), voice, runConfig.speakerId,
runConfig.useCuda);
auto endTime = chrono::steady_clock::now();
std::cout << "Loaded onnx model in " << std::chrono::duration<double>(endTime - startTime).count() << " second(s)" << std::endl;
}
else
{
std::cout << "Model already loaded" << std::endl;
}

// Get the path to the piper executable so we can locate espeak-ng-data, etc.
Expand Down Expand Up @@ -317,7 +325,7 @@ void printUsage(char *argv[]) {
cerr << endl;
cerr << "options:" << endl;
cerr << " -h --help show this message and exit" << endl;
cerr << " -p PORT --port PORT port to use for the server (default: 8080)" << endl;
cerr << " -p PORT --port PORT port to use for the server (default: 8080)" << endl;
cerr << " -q --quiet disable logging" << endl;
cerr << " --debug print DEBUG messages to the console" << endl;
cerr << endl;
Expand Down Expand Up @@ -368,8 +376,12 @@ void parseArgsFromJson(const json &inputJson, RunConfig &runConfig)
// Check if model path exists
if (!filesystem::exists(runConfig.modelPath))
{
std::cout << "Model path does not exist: " << runConfig.modelPath.string() << std::endl;
throw std::runtime_error("Model path does not exist: " + runConfig.modelPath.string());
}
else {
std::cout << "Model path exists: " << runConfig.modelPath.string() << std::endl;
}

if (inputJson.contains("modelConfigPath"))
{
Expand All @@ -382,8 +394,12 @@ void parseArgsFromJson(const json &inputJson, RunConfig &runConfig)
// Verify model config path exists
if (!filesystem::exists(runConfig.modelConfigPath))
{
std::cout << "Model config path does not exist: " << runConfig.modelConfigPath.string() << std::endl;
throw std::runtime_error("Model config path does not exist: " + runConfig.modelConfigPath.string());
}
else {
std::cout << "Model config path exists: " << runConfig.modelConfigPath.string() << std::endl;
}

if (inputJson.contains("output_file"))
{
Expand Down Expand Up @@ -425,8 +441,13 @@ void parseArgsFromJson(const json &inputJson, RunConfig &runConfig)
// Check if output path exists
if (!filesystem::exists(runConfig.outputPath.value()))
{
std::cout << "Output path does not exist: " << runConfig.outputPath.value().string() << std::endl;
throw std::runtime_error("Output path does not exist: " + runConfig.outputPath.value().string());
}
else {
std::cout << "Output path exists: " << runConfig.outputPath.value().string() << std::endl;
}



if (inputJson.contains("speakerId"))
Expand Down

0 comments on commit 07eb79e

Please sign in to comment.