Skip to content

Commit

Permalink
Avoid repeated dictionary and model loading in DiffSingerBasePhonemizer
Browse files Browse the repository at this point in the history
  • Loading branch information
yqzhishen committed Aug 26, 2024
1 parent 6d36d9c commit cc6b440
Showing 1 changed file with 19 additions and 6 deletions.
25 changes: 19 additions & 6 deletions OpenUtau.Core/DiffSinger/DiffSingerBasePhonemizer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,26 @@ public abstract class DiffSingerBasePhonemizer : MachineLearningPhonemizer
string defaultPause = "SP";
protected virtual string GetDictionaryName()=>"dsdict.yaml";

private bool _singerLoaded;

public override void SetSinger(USinger singer) {
if (_singerLoaded && singer == this.singer) return;
try {
_singerLoaded = _executeSetSinger(singer);
} catch {
_singerLoaded = false;
throw;
}
}

private bool _executeSetSinger(USinger singer) {
this.singer = singer;
if(singer==null){
return;
if (singer == null) {
return false;
}
if(singer.Location == null){
Log.Error("Singer location is null");
return;
return false;
}
if (File.Exists(Path.Join(singer.Location, "dsdur", "dsconfig.yaml"))) {
rootPath = Path.Combine(singer.Location, "dsdur");
Expand All @@ -51,7 +63,7 @@ public override void SetSinger(USinger singer) {
dsConfig = Yaml.DefaultDeserializer.Deserialize<DsConfig>(configTxt);
} catch(Exception e) {
Log.Error(e, $"failed to load dsconfig from {configPath}");
return;
return false;
}
this.frameMs = dsConfig.frameMs();
//Load g2p
Expand All @@ -67,7 +79,7 @@ public override void SetSinger(USinger singer) {
linguisticModel = new InferenceSession(linguisticModelBytes);
} catch (Exception e) {
Log.Error(e, $"failed to load linguistic model from {linguisticModelPath}");
return;
return false;
}
var durationModelPath = Path.Join(rootPath, dsConfig.dur);
try {
Expand All @@ -76,8 +88,9 @@ public override void SetSinger(USinger singer) {
durationModel = new InferenceSession(durationModelBytes);
} catch (Exception e) {
Log.Error(e, $"failed to load duration model from {durationModelPath}");
return;
return false;
}
return true;
}

protected virtual IG2p LoadG2p(string rootPath) {
Expand Down

0 comments on commit cc6b440

Please sign in to comment.