Skip to content
This repository has been archived by the owner on Sep 2, 2024. It is now read-only.

Commit

Permalink
Merge branch 'xunmengshe:master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
atonyxu authored Jan 26, 2024
2 parents f811339 + 0be693c commit 6b82cc9
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 @@ public bool IsVowel(string symbol) {
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 @@ string[] QueryTrie(TrieNode node, string word, int index) {
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 Builder Load(TextReader textReader) {
}

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 bool IsVowel(string symbol) {
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 bool IsVowel(string symbol) {
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 bool IsVowel(string symbol) {
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 @@ static USinger AdjustSingerType(Voicebank v) {
}
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 IEnumerable<Voicebank> SearchAll() {
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 static OtoSet ParseOtoSet(Stream stream, string filePath, Encoding encodi
};
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 PartRenderedNotification(UVoicePart part) {
}

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 6b82cc9

Please sign in to comment.