Skip to content

Commit

Permalink
Merge branch 'stakira:master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
oxygen-dioxide committed Jan 25, 2024
2 parents 96ed9cf + 3e38321 commit 0be693c
Show file tree
Hide file tree
Showing 48 changed files with 4,612 additions and 1,720 deletions.
22 changes: 20 additions & 2 deletions OpenUtau.Core/Api/G2pDictionary.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,12 @@ class TrieNode {

TrieNode root;
Dictionary<string, bool> phonemeSymbols; // (phoneme, isVowel)
HashSet<string> glideSymbols;

G2pDictionary(TrieNode root, Dictionary<string, bool> phonemeSymbols) {
G2pDictionary(TrieNode root, Dictionary<string, bool> phonemeSymbols, HashSet<string> glideSymbols) {
this.root = root;
this.phonemeSymbols = phonemeSymbols;
this.glideSymbols = glideSymbols;
}

public bool IsValidSymbol(string symbol) {
Expand All @@ -30,6 +32,10 @@ class TrieNode {
return phonemeSymbols.TryGetValue(symbol, out var isVowel) && isVowel;
}

public bool IsGlide(string symbol) {
return glideSymbols.Contains(symbol);
}

public string[] Query(string grapheme) {
return QueryTrie(root, grapheme, 0);
}
Expand All @@ -56,23 +62,35 @@ class TrieNode {
public class Builder {
TrieNode root;
Dictionary<string, bool> phonemeSymbols; // (phoneme, isVowel)
HashSet<string> glideSymbols;

internal Builder() {
root = new TrieNode();
phonemeSymbols = new Dictionary<string, bool>();
glideSymbols = new HashSet<string>();
}

/// <summary>
/// Add valid symbols of dictionary.
/// </summary>
public Builder AddSymbol(string symbol, string type) {
phonemeSymbols[symbol] = type == "vowel";
if(type == "semivowel" || type == "liquid") {
glideSymbols.Add(symbol);
}
return this;
}
public Builder AddSymbol(string symbol, bool isVowel) {
phonemeSymbols[symbol] = isVowel;
return this;
}
public Builder AddSymbol(string symbol, bool isVowel, bool isGlide) {
phonemeSymbols[symbol] = isVowel;
if (isGlide && !isVowel) {
glideSymbols.Add(symbol);
}
return this;
}

/// <summary>
/// Must finish adding symbols before adding entries, otherwise symbols get ignored.
Expand Down Expand Up @@ -123,7 +141,7 @@ public class Builder {
}

public G2pDictionary Build() {
return new G2pDictionary(root, phonemeSymbols);
return new G2pDictionary(root, phonemeSymbols, glideSymbols);
}
}

Expand Down
9 changes: 9 additions & 0 deletions OpenUtau.Core/Api/G2pFallbacks.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,15 @@ public class G2pFallbacks : IG2p {
return false;
}

public bool IsGlide(string symbol) {
foreach (var dict in dictionaries) {
if (dict.IsValidSymbol(symbol)) {
return dict.IsGlide(symbol);
}
}
return false;
}

public string[] Query(string grapheme) {
foreach (var dict in dictionaries) {
var result = dict.Query(grapheme);
Expand Down
4 changes: 4 additions & 0 deletions OpenUtau.Core/Api/G2pPack.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,10 @@ public abstract class G2pPack : IG2p {
return Dict.IsVowel(symbol);
}

public bool IsGlide(string symbol) {
return Dict.IsGlide(symbol);
}

public string[] Query(string grapheme) {
if (grapheme.Length == 0 || kAllPunct.IsMatch(grapheme)) {
return null;
Expand Down
9 changes: 8 additions & 1 deletion OpenUtau.Core/Api/G2pRemapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,17 @@ namespace OpenUtau.Api {
public class G2pRemapper : IG2p {
private IG2p mapped;
private Dictionary<string, bool> phonemeSymbols; // (phoneme, isVowel)
private HashSet<string> glideSymbols;
private Dictionary<string, string> replacements;

public G2pRemapper(IG2p mapped,
Dictionary<string, bool> phonemeSymbols,
Dictionary<string, string> replacements) {
Dictionary<string, string> replacements,
HashSet<string> glideSymbols = null) {
this.mapped = mapped;
this.phonemeSymbols = phonemeSymbols;
this.replacements = replacements;
this.glideSymbols = glideSymbols ?? new HashSet<string>();
}

public bool IsValidSymbol(string symbol) {
Expand All @@ -23,6 +26,10 @@ public class G2pRemapper : IG2p {
return phonemeSymbols.TryGetValue(symbol, out var isVowel) && isVowel;
}

public bool IsGlide(string symbol) {
return glideSymbols.Contains(symbol);
}

public string[] Query(string grapheme) {
var phonemes = mapped.Query(grapheme);
if (phonemes == null) {
Expand Down
5 changes: 5 additions & 0 deletions OpenUtau.Core/Api/IG2p.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@ public interface IG2p {
bool IsValidSymbol(string symbol);
bool IsVowel(string symbol);

/// <summary>
/// Returns true if the symbol is a semivowel or liquid phoneme, like y, w, l, r in English.
/// </summary>
bool IsGlide(string symbol);

/// <summary>
/// Produces a list of phonemes from grapheme.
/// </summary>
Expand Down
6 changes: 1 addition & 5 deletions OpenUtau.Core/Classic/ClassicSingerLoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,7 @@ public static class ClassicSingerLoader {
}
public static IEnumerable<USinger> FindAllSingers() {
List<USinger> singers = new List<USinger>();
foreach (var path in new string[] {
PathManager.Inst.SingersPathOld,
PathManager.Inst.SingersPath,
PathManager.Inst.AdditionalSingersPath,
}) {
foreach (var path in PathManager.Inst.SingersPaths) {
var loader = new VoicebankLoader(path);
singers.AddRange(loader.SearchAll()
.Select(AdjustSingerType));
Expand Down
20 changes: 19 additions & 1 deletion OpenUtau.Core/Classic/VoicebankLoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using System.Text;
using OpenUtau.Core;
using OpenUtau.Core.Ustx;
using OpenUtau.Core.Util;
using Serilog;

namespace OpenUtau.Classic {
Expand Down Expand Up @@ -45,7 +46,15 @@ public class VoicebankLoader {
if (!Directory.Exists(basePath)) {
return result;
}
result.AddRange(Directory.EnumerateFiles(basePath, kCharTxt, SearchOption.AllDirectories)
IEnumerable<string> files;
if (Preferences.Default.LoadDeepFolderSinger) {
files = Directory.EnumerateFiles(basePath, kCharTxt, SearchOption.AllDirectories);
} else {
// TopDirectoryOnly
files = Directory.GetDirectories(basePath)
.SelectMany(path => Directory.EnumerateFiles(path, kCharTxt));
}
result.AddRange(files
.Select(filePath => {
try {
var voicebank = new Voicebank();
Expand Down Expand Up @@ -341,6 +350,15 @@ public class VoicebankLoader {
};
while (!reader.EndOfStream) {
var line = reader.ReadLine().Trim();
if (line.StartsWith("#Charaset:")) {
try {
var charaset = Encoding.GetEncoding(line.Replace("#Charaset:", ""));
if (encoding != charaset) {
stream.Position = 0;
return ParseOtoSet(stream, filePath, charaset);
}
} catch { }
}
trace.line = line;
try {
Oto oto = ParseOto(line, trace);
Expand Down
6 changes: 3 additions & 3 deletions OpenUtau.Core/Commands/Notifications.cs
Original file line number Diff line number Diff line change
Expand Up @@ -211,9 +211,9 @@ public class PartRenderedNotification : UNotification {
}

public class GotoOtoNotification : UNotification {
public readonly USinger singer;
public readonly UOto oto;
public GotoOtoNotification(USinger singer, UOto oto) {
public readonly USinger? singer;
public readonly UOto? oto;
public GotoOtoNotification(USinger? singer, UOto? oto) {
this.singer = singer;
this.oto = oto;
}
Expand Down
18 changes: 18 additions & 0 deletions OpenUtau.Core/DiffSinger/DiffSingerItalianPhonemizer.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
using OpenUtau.Api;
using OpenUtau.Core.G2p;

namespace OpenUtau.Core.DiffSinger {
[Phonemizer("DiffSinger Italian Phonemizer", "DIFFS IT", language: "IT")]
public class DiffSingerItalianPhonemizer : DiffSingerG2pPhonemizer {
protected override string GetDictionaryName() => "dsdict-it.yaml";
protected override IG2p LoadBaseG2p() => new ItalianG2p();
protected override string[] GetBaseG2pVowels() => new string[] {
"a", "a1", "e", "e1", "EE", "i", "i1", "o", "o1", "OO", "u", "u1"
};

protected override string[] GetBaseG2pConsonants() => new string[] {
"b", "d", "dz", "dZZ", "f", "g", "JJ", "k", "l", "LL", "m", "n",
"nf", "ng", "p", "r", "rr", "s", "SS", "t", "ts", "tSS", "v", "w", "y", "z"
};
}
}
2 changes: 1 addition & 1 deletion OpenUtau.Core/DiffSinger/DiffSingerJyutpingPhonemizer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
using System.Linq;

namespace OpenUtau.Core.DiffSinger {
[Phonemizer("DiffSinger Jyutping Phonemizer", "DIFFS ZH-YUE", language: "ZH")]
[Phonemizer("DiffSinger Jyutping Phonemizer", "DIFFS ZH-YUE", language: "ZH-YUE")]
public class DiffSingerJyutpingPhonemizer : DiffSingerBasePhonemizer {
protected override string[] Romanize(IEnumerable<string> lyrics) {
return ZhG2p.CantoneseInstance.Convert(lyrics.ToList(), false, true).Split(" ");
Expand Down
Loading

0 comments on commit 0be693c

Please sign in to comment.