A fast, local neural text to speech system
Add "speaker" to JSON input
Michael Hansen42d14ef21f43
diff --git a/VERSION b/VERSIONindex 3eefcb9..9084fa2 100644--- a/VERSION+++ b/VERSION@@ -1 +1 @@-1.0.0+1.1.0diff --git a/src/cpp/main.cpp b/src/cpp/main.cppindex 5f1bde1..892fd40 100644--- a/src/cpp/main.cpp+++ b/src/cpp/main.cpp@@ -214,6 +214,16 @@ int main(int argc, char *argv[]) {// Override speaker idvoice.synthesisConfig.speakerId =lineRoot["speaker_id"].get<piper::SpeakerId>();+ } else if (lineRoot.contains("speaker")) {+ // Resolve to id using speaker id map+ auto speakerName = lineRoot["speaker"].get<std::string>();+ if ((voice.modelConfig.speakerIdMap) &&+ (voice.modelConfig.speakerIdMap->count(speakerName) > 0)) {+ voice.synthesisConfig.speakerId =+ (*voice.modelConfig.speakerIdMap)[speakerName];+ } else {+ spdlog::warn("No speaker named: {}", speakerName);+ }}}diff --git a/src/cpp/piper.cpp b/src/cpp/piper.cppindex 633e95c..ccc2c1a 100644--- a/src/cpp/piper.cpp+++ b/src/cpp/piper.cpp@@ -163,6 +163,19 @@ void parseModelConfig(json &configRoot, ModelConfig &modelConfig) {modelConfig.numSpeakers = configRoot["num_speakers"].get<SpeakerId>();+ if (configRoot.contains("speaker_id_map")) {+ if (!modelConfig.speakerIdMap) {+ modelConfig.speakerIdMap.emplace();+ }++ auto speakerIdMapValue = configRoot["speaker_id_map"];+ for (auto &speakerItem : speakerIdMapValue.items()) {+ std::string speakerName = speakerItem.key();+ (*modelConfig.speakerIdMap)[speakerName] =+ speakerItem.value().get<SpeakerId>();+ }+ }+} /* parseModelConfig */void initialize(PiperConfig &config) {diff --git a/src/cpp/piper.hpp b/src/cpp/piper.hppindex 29a8bcf..0c3175b 100644--- a/src/cpp/piper.hpp+++ b/src/cpp/piper.hpp@@ -61,6 +61,9 @@ struct SynthesisConfig {struct ModelConfig {int numSpeakers;++ // speaker name -> id+ std::optional<std::map<std::string, SpeakerId>> speakerIdMap;};struct ModelSession {