This commit is contained in:
Michael Hansen
2023-09-09 14:57:55 -05:00
parent 73574de76d
commit 9b10e3d110
4 changed files with 218 additions and 28 deletions

View File

@@ -283,7 +283,16 @@ void loadModel(std::string modelPath, ModelSession &session) {
session.options.DisableProfiling();
auto startTime = std::chrono::steady_clock::now();
session.onnx = Ort::Session(session.env, modelPath.c_str(), session.options);
#ifdef _WIN32
auto modelPathW = std::wstring(modelPath.begin(), modelPath.end());
auto modelPathStr = modelPathW.c_str();
#else
auto modelPathStr = modelPath.c_str();
#endif
session.onnx = Ort::Session(session.env, modelPathStr, session.options);
auto endTime = std::chrono::steady_clock::now();
spdlog::debug("Loaded onnx model in {} second(s)",
std::chrono::duration<double>(endTime - startTime).count());
@@ -473,7 +482,7 @@ void textToAudio(PiperConfig &config, Voice &voice, std::string text,
// DEBUG log for phonemes
std::string phonemesStr;
for (auto phoneme : sentencePhonemes) {
utf8::append(phoneme, phonemesStr);
utf8::append(phoneme, &phonemesStr);
}
spdlog::debug("Converting {} phoneme(s) to ids: {}",
@@ -587,7 +596,7 @@ void textToAudio(PiperConfig &config, Voice &voice, std::string text,
for (auto phonemeCount : missingPhonemes) {
std::string phonemeStr;
utf8::append(phonemeCount.first, phonemeStr);
utf8::append(phonemeCount.first, &phonemeStr);
spdlog::warn("Missing \"{}\" (\\u{:04X}): {} time(s)", phonemeStr,
(uint32_t)phonemeCount.first, phonemeCount.second);
}

View File

@@ -9,9 +9,9 @@
#include <vector>
#include <onnxruntime_cxx_api.h>
#include <phoneme_ids.hpp>
#include <phonemize.hpp>
#include <tashkeel.hpp>
#include <piper-phonemize/phoneme_ids.hpp>
#include <piper-phonemize/phonemize.hpp>
#include <piper-phonemize/tashkeel.hpp>
#include "json.hpp"

58
src/cpp/test.cpp Normal file
View File

@@ -0,0 +1,58 @@
#include <fstream>
#include <functional>
#include <iostream>
#include <optional>
#include <stdexcept>
#include <string>
#include <vector>
#include "json.hpp"
#include "piper.hpp"
using namespace std;
using json = nlohmann::json;
int main(int argc, char *argv[]) {
piper::PiperConfig piperConfig;
piper::Voice voice;
if (argc < 2) {
std::cerr << "Need voice model path" << std::endl;
return 1;
}
if (argc < 3) {
std::cerr << "Need espeak-ng-data path" << std::endl;
return 1;
}
if (argc < 4) {
std::cerr << "Need output WAV path" << std::endl;
return 1;
}
auto modelPath = std::string(argv[1]);
piperConfig.eSpeakDataPath = std::string(argv[2]);
auto outputPath = std::string(argv[3]);
optional<piper::SpeakerId> speakerId;
loadVoice(piperConfig, modelPath, modelPath + ".json", voice, speakerId);
piper::initialize(piperConfig);
// Output audio to WAV file
ofstream audioFile(outputPath, ios::binary);
piper::SynthesisResult result;
piper::textToWavFile(piperConfig, voice, "This is a test.", audioFile, result);
piper::terminate(piperConfig);
// Verify that file has some data
if (audioFile.tellp() < 10000) {
std::cerr << "ERROR: Output file is smaller than expected!" << std::endl;
return EXIT_FAILURE;
}
std::cout << "OK" << std::endl;
return EXIT_SUCCESS;
}