Skip to content

Commit 04ef670

Browse files
yqzhishenlottev1991
authored andcommitted
Check null keys to make errors more friendly (stakira#1572)
1 parent 20381b0 commit 04ef670

File tree

3 files changed

+18
-7
lines changed

3 files changed

+18
-7
lines changed

OpenUtau.Core/DiffSinger/DiffSingerPitch.cs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,8 @@ public DsPitch(string rootPath)
4040
}
4141
//Load language id if needed
4242
if(dsConfig.use_lang_id){
43-
if(dsConfig.languages == null){
44-
Log.Error("\"languages\" field is not specified in dsconfig.yaml");
45-
return;
43+
if(dsConfig.languages == null) {
44+
throw new Exception("\"languages\" field is not specified in dsconfig.yaml");
4645
}
4746
var langIdPath = Path.Join(rootPath, dsConfig.languages);
4847
try {
@@ -53,9 +52,15 @@ public DsPitch(string rootPath)
5352
}
5453
}
5554
//Load phonemes list
55+
if (dsConfig.phonemes == null) {
56+
throw new Exception("Configuration key \"phonemes\" is null.");
57+
}
5658
string phonemesPath = Path.Combine(rootPath, dsConfig.phonemes);
5759
phonemeTokens = DiffSingerUtils.LoadPhonemes(phonemesPath);
5860
//Load models
61+
if (dsConfig.linguistic == null) {
62+
throw new Exception("Configuration key \"linguistic\" is null.");
63+
}
5964
var linguisticModelPath = Path.Join(rootPath, dsConfig.linguistic);
6065
var linguisticModelBytes = File.ReadAllBytes(linguisticModelPath);
6166
linguisticHash = XXH64.DigestOf(linguisticModelBytes);

OpenUtau.Core/DiffSinger/DiffSingerSinger.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,6 @@ public DsVocoder getVocoder() {
186186
if(pitchPredictor is null) {
187187
if(HasPitchPredictor){
188188
pitchPredictor = new DsPitch(Path.Join(Location, "dspitch"));
189-
return pitchPredictor;
190189
}
191190
}
192191
return pitchPredictor;
@@ -203,7 +202,6 @@ public DiffSingerSpeakerEmbedManager getSpeakerEmbedManager(){
203202
if(variancePredictor is null) {
204203
if(HasVariancePredictor){
205204
variancePredictor = new DsVariance(Path.Join(Location, "dsvariance"));
206-
return variancePredictor;
207205
}
208206
}
209207
return variancePredictor;

OpenUtau.Core/DiffSinger/DiffSingerVariance.cs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,13 @@ public DsVariance(string rootPath)
4242
dsConfig = Yaml.DefaultDeserializer.Deserialize<DsConfig>(
4343
File.ReadAllText(Path.Combine(rootPath, "dsconfig.yaml"),
4444
Encoding.UTF8));
45+
if(dsConfig.variance == null){
46+
throw new Exception("This voicebank doesn't contain a variance model");
47+
}
4548
//Load language id if needed
4649
if(dsConfig.use_lang_id){
4750
if(dsConfig.languages == null){
48-
Log.Error("\"languages\" field is not specified in dsconfig.yaml");
49-
return;
51+
throw new Exception("\"languages\" field is not specified in dsconfig.yaml");
5052
}
5153
var langIdPath = Path.Join(rootPath, dsConfig.languages);
5254
try {
@@ -57,9 +59,15 @@ public DsVariance(string rootPath)
5759
}
5860
}
5961
//Load phonemes list
62+
if (dsConfig.phonemes == null) {
63+
throw new Exception("Configuration key \"phonemes\" is null.");
64+
}
6065
string phonemesPath = Path.Combine(rootPath, dsConfig.phonemes);
6166
phonemeTokens = DiffSingerUtils.LoadPhonemes(phonemesPath);
6267
//Load models
68+
if (dsConfig.linguistic == null) {
69+
throw new Exception("Configuration key \"linguistic\" is null.");
70+
}
6371
var linguisticModelPath = Path.Join(rootPath, dsConfig.linguistic);
6472
var linguisticModelBytes = File.ReadAllBytes(linguisticModelPath);
6573
linguisticHash = XXH64.DigestOf(linguisticModelBytes);

0 commit comments

Comments
 (0)