Add --version

This commit is contained in:
Michael Hansen
2023-07-10 15:09:58 -05:00
parent 42d14ef21f
commit daf6e7fcf7
6 changed files with 77 additions and 25 deletions

View File

@@ -5,6 +5,8 @@ project(piper C CXX)
find_package(PkgConfig)
pkg_check_modules(SPDLOG REQUIRED spdlog)
file(READ "${CMAKE_CURRENT_LIST_DIR}/../../VERSION" piper_version)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
@@ -35,3 +37,5 @@ target_include_directories(piper PUBLIC
target_compile_options(piper PUBLIC
${SPDLOG_CFLAGS_OTHER})
target_compile_definitions(piper PUBLIC _PIPER_VERSION=${piper_version})

View File

@@ -70,9 +70,10 @@ struct RunConfig {
// stdin input is lines of JSON instead of text with format:
// {
// "text": "...", (required)
// "text": str, (required)
// "speaker_id": int, (optional)
// "output_file": "...", (optional)
// "speaker": str, (optional)
// "output_file": str, (optional)
// }
bool jsonInput = false;
};
@@ -454,6 +455,9 @@ void parseArgs(int argc, char *argv[], RunConfig &runConfig) {
runConfig.tashkeelModelPath = filesystem::path(argv[++i]);
} else if (arg == "--json_input" || arg == "--json-input") {
runConfig.jsonInput = true;
} else if (arg == "--version") {
std::cout << piper::getVersion() << std::endl;
exit(0);
} else if (arg == "--debug") {
// Set DEBUG logging
spdlog::set_level(spdlog::level::debug);

View File

@@ -16,11 +16,24 @@
namespace piper {
#ifdef _PIPER_VERSION
// https://stackoverflow.com/questions/47346133/how-to-use-a-define-inside-a-format-string
#define _STR(x) #x
#define STR(x) _STR(x)
const std::string VERSION = STR(_PIPER_VERSION);
#else
const std::string VERSION = "";
#endif
// Maximum value for 16-bit signed WAV sample
const float MAX_WAV_VALUE = 32767.0f;
const std::string instanceName{"piper"};
std::string getVersion() {
return VERSION;
}
// True if the string is a single UTF-8 codepoint
bool isSingleCodepoint(std::string s) {
return utf8::distance(s.begin(), s.end()) == 1;

View File

@@ -89,6 +89,9 @@ struct Voice {
ModelSession session;
};
// Get version of Piper
std::string getVersion();
// Must be called before using textTo* functions
void initialize(PiperConfig &config);