Skip to content

Commit 17a15be

Browse files
authored
Merge pull request #882 from oxygen-dioxide/diffsinger
Add DiffSinger Support
2 parents 0eac6f4 + 1906668 commit 17a15be

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+4368
-9
lines changed

OpenUtau.Core/Classic/ClassicSingerLoader.cs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,16 @@
55

66
namespace OpenUtau.Classic {
77
public static class ClassicSingerLoader {
8+
static USinger AdjustSingerType(Voicebank v) {
9+
switch (v.SingerType) {
10+
case USingerType.Enunu:
11+
return new Core.Enunu.EnunuSinger(v) as USinger;
12+
case USingerType.DiffSinger:
13+
return new Core.DiffSinger.DiffSingerSinger(v) as USinger;
14+
default:
15+
return new ClassicSinger(v) as USinger;
16+
}
17+
}
818
public static IEnumerable<USinger> FindAllSingers() {
919
List<USinger> singers = new List<USinger>();
1020
foreach (var path in new string[] {
@@ -14,9 +24,7 @@ public static IEnumerable<USinger> FindAllSingers() {
1424
}) {
1525
var loader = new VoicebankLoader(path);
1626
singers.AddRange(loader.SearchAll()
17-
.Select(v => v.SingerType == USingerType.Enunu
18-
? new Core.Enunu.EnunuSinger(v) as USinger
19-
: new ClassicSinger(v) as USinger));
27+
.Select(AdjustSingerType));
2028
}
2129
return singers;
2230
}

OpenUtau.Core/Classic/VoicebankLoader.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ public class VoicebankLoader {
2828
public const string kCharTxt = "character.txt";
2929
public const string kCharYaml = "character.yaml";
3030
public const string kEnuconfigYaml = "enuconfig.yaml";
31+
public const string kDsconfigYaml = "dsconfig.yaml";
3132
public const string kConfigYaml = "config.yaml";
3233
public const string kOtoIni = "oto.ini";
3334

@@ -99,11 +100,17 @@ public static void LoadInfo(Voicebank voicebank, string filePath, string basePat
99100
case "enunu":
100101
voicebank.SingerType = USingerType.Enunu;
101102
break;
103+
case "diffsinger":
104+
voicebank.SingerType = USingerType.DiffSinger;
105+
break;
102106
default:
103107
// Legacy detection code. Do not add more here.
104108
var enuconfigFile = Path.Combine(dir, kEnuconfigYaml);
109+
var dsconfigFile = Path.Combine(dir, kDsconfigYaml);
105110
if (File.Exists(enuconfigFile)) {
106111
voicebank.SingerType = USingerType.Enunu;
112+
} else if(File.Exists(dsconfigFile)){
113+
voicebank.SingerType = USingerType.DiffSinger;
107114
} else if (voicebank.SingerType != USingerType.Enunu) {
108115
voicebank.SingerType = USingerType.Classic;
109116
}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
using System;
2+
using System.IO;
3+
using System.Linq;
4+
using System.Text;
5+
using SharpCompress.Archives;
6+
7+
namespace OpenUtau.Core {
8+
//Installation of dependencies (primarilly for diffsinger), including vocoder and phoneme timing model
9+
[Serializable]
10+
public class DependencyConfig {
11+
public string name;
12+
}
13+
14+
public class DependencyInstaller {
15+
public static string FileExt = ".oudep";
16+
public static void Install(string archivePath) {
17+
DependencyConfig dependencyConfig;
18+
using (var archive = ArchiveFactory.Open(archivePath)) {
19+
DocManager.Inst.ExecuteCmd(new ProgressBarNotification(0, "Installing dependency"));
20+
var configEntry = archive.Entries.First(e => e.Key == "oudep.yaml");
21+
if (configEntry == null) {
22+
throw new ArgumentException("missing oudep.yaml");
23+
}
24+
using (var stream = configEntry.OpenEntryStream()) {
25+
using var reader = new StreamReader(stream, Encoding.UTF8);
26+
dependencyConfig = Core.Yaml.DefaultDeserializer.Deserialize<DependencyConfig>(reader);
27+
}
28+
string name = dependencyConfig.name;
29+
if(string.IsNullOrEmpty(name)){
30+
throw new ArgumentException("missing name in oudep.yaml");
31+
}
32+
var basePath = Path.Combine(PathManager.Inst.DependencyPath, name);
33+
foreach (var entry in archive.Entries) {
34+
if (entry.Key.Contains("..")) {
35+
// Prevent zipSlip attack
36+
continue;
37+
}
38+
var filePath = Path.Combine(basePath, entry.Key);
39+
Directory.CreateDirectory(Path.GetDirectoryName(filePath));
40+
if (!entry.IsDirectory) {
41+
entry.WriteToFile(Path.Combine(basePath, entry.Key));
42+
}
43+
}
44+
DocManager.Inst.ExecuteCmd(new ProgressBarNotification(0, $"Installed dependency \"{name}\""));
45+
}
46+
}
47+
}
48+
}

0 commit comments

Comments
 (0)