Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid repeated dictionary and model loading in DiffSingerBasePhonemizer #1255

Merged
merged 1 commit into from
Sep 1, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading