diff --git a/VERSION b/VERSION index 3eefcb9..9084fa2 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -1.0.0 +1.1.0 diff --git a/src/cpp/main.cpp b/src/cpp/main.cpp index 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 id voice.synthesisConfig.speakerId = lineRoot["speaker_id"].get(); + } else if (lineRoot.contains("speaker")) { + // Resolve to id using speaker id map + auto speakerName = lineRoot["speaker"].get(); + 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.cpp index 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(); + 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(); + } + } + } /* parseModelConfig */ void initialize(PiperConfig &config) { diff --git a/src/cpp/piper.hpp b/src/cpp/piper.hpp index 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> speakerIdMap; }; struct ModelSession {