Skip to content

Commit

Permalink
Merge pull request #882 from oxygen-dioxide/diffsinger
Browse files Browse the repository at this point in the history
Add DiffSinger Support
  • Loading branch information
stakira authored Oct 20, 2023
2 parents 0eac6f4 + 1906668 commit 17a15be
Show file tree
Hide file tree
Showing 42 changed files with 4,368 additions and 9 deletions.
14 changes: 11 additions & 3 deletions OpenUtau.Core/Classic/ClassicSingerLoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,16 @@

namespace OpenUtau.Classic {
public static class ClassicSingerLoader {
static USinger AdjustSingerType(Voicebank v) {
switch (v.SingerType) {
case USingerType.Enunu:
return new Core.Enunu.EnunuSinger(v) as USinger;
case USingerType.DiffSinger:
return new Core.DiffSinger.DiffSingerSinger(v) as USinger;
default:
return new ClassicSinger(v) as USinger;
}
}
public static IEnumerable<USinger> FindAllSingers() {
List<USinger> singers = new List<USinger>();
foreach (var path in new string[] {
Expand All @@ -14,9 +24,7 @@ public static IEnumerable<USinger> FindAllSingers() {
}) {
var loader = new VoicebankLoader(path);
singers.AddRange(loader.SearchAll()
.Select(v => v.SingerType == USingerType.Enunu
? new Core.Enunu.EnunuSinger(v) as USinger
: new ClassicSinger(v) as USinger));
.Select(AdjustSingerType));
}
return singers;
}
Expand Down
7 changes: 7 additions & 0 deletions OpenUtau.Core/Classic/VoicebankLoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ public class VoicebankLoader {
public const string kCharTxt = "character.txt";
public const string kCharYaml = "character.yaml";
public const string kEnuconfigYaml = "enuconfig.yaml";
public const string kDsconfigYaml = "dsconfig.yaml";
public const string kConfigYaml = "config.yaml";
public const string kOtoIni = "oto.ini";

Expand Down Expand Up @@ -99,11 +100,17 @@ public static void LoadInfo(Voicebank voicebank, string filePath, string basePat
case "enunu":
voicebank.SingerType = USingerType.Enunu;
break;
case "diffsinger":
voicebank.SingerType = USingerType.DiffSinger;
break;
default:
// Legacy detection code. Do not add more here.
var enuconfigFile = Path.Combine(dir, kEnuconfigYaml);
var dsconfigFile = Path.Combine(dir, kDsconfigYaml);
if (File.Exists(enuconfigFile)) {
voicebank.SingerType = USingerType.Enunu;
} else if(File.Exists(dsconfigFile)){
voicebank.SingerType = USingerType.DiffSinger;
} else if (voicebank.SingerType != USingerType.Enunu) {
voicebank.SingerType = USingerType.Classic;
}
Expand Down
48 changes: 48 additions & 0 deletions OpenUtau.Core/DependencyInstaller.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
using System;
using System.IO;
using System.Linq;
using System.Text;
using SharpCompress.Archives;

namespace OpenUtau.Core {
//Installation of dependencies (primarilly for diffsinger), including vocoder and phoneme timing model
[Serializable]
public class DependencyConfig {
public string name;
}

public class DependencyInstaller {
public static string FileExt = ".oudep";
public static void Install(string archivePath) {
DependencyConfig dependencyConfig;
using (var archive = ArchiveFactory.Open(archivePath)) {
DocManager.Inst.ExecuteCmd(new ProgressBarNotification(0, "Installing dependency"));
var configEntry = archive.Entries.First(e => e.Key == "oudep.yaml");
if (configEntry == null) {
throw new ArgumentException("missing oudep.yaml");
}
using (var stream = configEntry.OpenEntryStream()) {
using var reader = new StreamReader(stream, Encoding.UTF8);
dependencyConfig = Core.Yaml.DefaultDeserializer.Deserialize<DependencyConfig>(reader);
}
string name = dependencyConfig.name;
if(string.IsNullOrEmpty(name)){
throw new ArgumentException("missing name in oudep.yaml");
}
var basePath = Path.Combine(PathManager.Inst.DependencyPath, name);
foreach (var entry in archive.Entries) {
if (entry.Key.Contains("..")) {
// Prevent zipSlip attack
continue;
}
var filePath = Path.Combine(basePath, entry.Key);
Directory.CreateDirectory(Path.GetDirectoryName(filePath));
if (!entry.IsDirectory) {
entry.WriteToFile(Path.Combine(basePath, entry.Key));
}
}
DocManager.Inst.ExecuteCmd(new ProgressBarNotification(0, $"Installed dependency \"{name}\""));
}
}
}
}
Loading

0 comments on commit 17a15be

Please sign in to comment.