mirror of
https://github.com/pstrueb/piper.git
synced 2026-05-13 09:38:01 +00:00
Add "speaker" to JSON input
This commit is contained in:
@@ -214,6 +214,16 @@ int main(int argc, char *argv[]) {
|
||||
// Override speaker id
|
||||
voice.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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -61,6 +61,9 @@ struct SynthesisConfig {
|
||||
|
||||
struct ModelConfig {
|
||||
int numSpeakers;
|
||||
|
||||
// speaker name -> id
|
||||
std::optional<std::map<std::string, SpeakerId>> speakerIdMap;
|
||||
};
|
||||
|
||||
struct ModelSession {
|
||||
|
||||
Reference in New Issue
Block a user