From 8a16329a33b3b92d97ae55847fe8f36ceab2c9bf Mon Sep 17 00:00:00 2001 From: Lotte V Date: Fri, 4 Aug 2023 23:45:05 +0200 Subject: [PATCH 01/11] Fix ValidateAlias bugs + restore proper VCC connections --- OpenUtau.Plugin.Builtin/ENDeltaPhonemizer.cs | 68 ++++++++------------ 1 file changed, 27 insertions(+), 41 deletions(-) diff --git a/OpenUtau.Plugin.Builtin/ENDeltaPhonemizer.cs b/OpenUtau.Plugin.Builtin/ENDeltaPhonemizer.cs index a69dee48f..9c78f4930 100644 --- a/OpenUtau.Plugin.Builtin/ENDeltaPhonemizer.cs +++ b/OpenUtau.Plugin.Builtin/ENDeltaPhonemizer.cs @@ -8,7 +8,7 @@ using Serilog; namespace OpenUtau.Plugin.Builtin { - [Phonemizer("Delta English Phonemizer", "EN DELTA", "Lotte V", language:"EN")] + [Phonemizer("Delta English Phonemizer", "EN DELTA", "Lotte V", language: "EN")] public class ENDeltaPhonemizer : SyllableBasedPhonemizer { /// /// General English phonemizer for Delta list (X-SAMPA) voicebanks. @@ -224,8 +224,8 @@ protected override List ProcessSyllable(Syllable syllable) { // try vcc for (var i = lastC + 1; i >= 0; i--) { var vr = $"{prevV} -"; - var vcc = $"{prevV} {string.Join("", cc.Take(i))}"; - var vcc2 = $"{prevV}{string.Join(" ", cc.Take(i))}"; + var vcc = $"{prevV} {string.Join("", cc.Take(2))}"; + var vcc2 = $"{prevV}{string.Join(" ", cc.Take(2))}"; var vc = $"{prevV} {cc[0]}"; if (i == 0) { if (HasOto(vr, syllable.tone)) { @@ -236,21 +236,17 @@ protected override List ProcessSyllable(Syllable syllable) { } } else if (HasOto(vcc, syllable.tone)) { phonemes.Add(vcc); - firstC = i - 1; break; } else if (!HasOto(vcc, syllable.tone) && HasOto(ValidateAlias(vcc), syllable.tone)) { vcc = ValidateAlias(vcc); phonemes.Add(vcc); - firstC = i - 1; break; } else if (!HasOto(ValidateAlias(vcc), syllable.tone) && HasOto(vcc2, syllable.tone)) { phonemes.Add(vcc2); - firstC = i - 1; break; } else if (!HasOto(vcc2, syllable.tone) && HasOto(ValidateAlias(vcc2), syllable.tone)) { vcc2 = ValidateAlias(vcc2); phonemes.Add(vcc2); - firstC = i - 1; break; } else if (!HasOto(ValidateAlias(vcc), syllable.tone) && HasOto(vc, syllable.tone)) { phonemes.Add(vc); @@ -271,8 +267,10 @@ protected override List ProcessSyllable(Syllable syllable) { var rccv = $"- {string.Join("", cc)}{v}"; var cc1 = $"{string.Join("", cc.Skip(i))}"; var ccv = string.Join("", cc.Skip(i)) + v; + var vcc = $"{prevV} {string.Join("", cc.Take(2))}"; + var vcc2 = $"{prevV}{string.Join(" ", cc.Take(2))}"; var ucv = $"_{cc.Last()}{v}"; - if (!HasOto(rccv, syllable.vowelTone)) { + if (!HasOto(rccv, syllable.vowelTone) && !vcc.Contains(cc1) && !vcc2.Contains(cc1) && !ValidateAlias(vcc).Contains(cc1) && !ValidateAlias(vcc2).Contains(cc1)) { if (!HasOto(cc1, syllable.tone)) { cc1 = ValidateAlias(cc1); } @@ -307,8 +305,8 @@ protected override List ProcessSyllable(Syllable syllable) { basePhoneme = ucv; } } - if (i + 1 < lastC) { - var cc2 = $"{string.Join("", cc.Skip(i))}"; + var cc2 = $"{string.Join("", cc.Skip(i))}"; + if (i + 1 < lastC && !vcc.Contains(cc2) && !vcc2.Contains(cc2) && !ValidateAlias(vcc).Contains(cc2) && !ValidateAlias(vcc2).Contains(cc2)) { if (!HasOto(cc2, syllable.tone)) { cc2 = ValidateAlias(cc2); } @@ -343,7 +341,10 @@ protected override List ProcessSyllable(Syllable syllable) { basePhoneme = ucv; } } - if (HasOto(cc1, syllable.tone) && HasOto(cc2, syllable.tone) && !cc1.Contains($"{string.Join("", cc.Skip(i))}")) { + if (TryAddPhoneme(phonemes, syllable.tone, $"{cc[i]} {cc[i + 1]}{cc[i + 2]}-", ValidateAlias($"{cc[i]} {cc[i + 1]}{cc[i + 2]}-"))) { + // like [V C1] [C1 C2C3-] ... + i++; + } else if (HasOto(cc1, syllable.tone) && HasOto(cc2, syllable.tone) && !cc1.Contains($"{string.Join("", cc.Skip(i))}")) { // like [V C1] [C1 C2] [C2 C3] [C3 ..] phonemes.Add(cc1); } else if (TryAddPhoneme(phonemes, syllable.tone, cc1)) { @@ -356,17 +357,19 @@ protected override List ProcessSyllable(Syllable syllable) { if (affricates.Contains(cc[i + 1])) { i++; } else { - // continue as usual + // // continue as usual } - } else if (affricates.Contains(cc[i])) { + } else { // like [V C1] [C1] [C2 ..] - TryAddPhoneme(phonemes, syllable.tone, cc[i], $"{cc[i]} -"); + if (!vcc.Contains(cc[i + 1]) && !vcc2.Contains(cc[i + 1])) { + TryAddPhoneme(phonemes, syllable.tone, cc[i + 1], ValidateAlias(cc[i + 1]), $"{cc[i + 1]} -", ValidateAlias($"{cc[i + 1]} -")); + } } } else { // like [V C1] [C1 C2] [C2 ..] or like [V C1] [C1 -] [C3 ..] TryAddPhoneme(phonemes, syllable.tone, cc1); if (affricates.Contains(cc[i]) && !HasOto(cc1, syllable.tone)) { - TryAddPhoneme(phonemes, syllable.tone, cc[i], $"{cc[i]} -"); + TryAddPhoneme(phonemes, syllable.tone, cc[i], ValidateAlias(cc[i]), $"{cc[i]} -", ValidateAlias($"{cc[i]} -")); } } } @@ -550,12 +553,12 @@ protected override string ValidateAlias(string alias) { alias = alias.Replace(vowel, "Q"); } foreach (var consonant in new[] { "b" }) { - foreach (var vowel in new[] { "V" } ) { + foreach (var vowel in new[] { "V" }) { alias = alias.Replace(consonant + vowel, consonant + "@"); } } foreach (var vowel in new[] { "@ " }) { - foreach (var consonant in new[] { "b" } ) { + foreach (var consonant in new[] { "b" }) { alias = alias.Replace("@ " + consonant, "@ " + consonant); } } @@ -612,35 +615,18 @@ protected override string ValidateAlias(string alias) { alias = alias.Replace(VV, "I O"); } foreach (var CC in new[] { "N k", "N g", "N k-", "N g-" }) { - alias = alias.Replace("N", "n"); + alias = alias.Replace("N ", "n "); } - foreach (var consonant in new[] { "r " }) { - alias = alias.Replace(consonant, "3 "); + foreach (var consonant1 in new[] { "r " }) { + foreach (var consonant2 in GetConsonants()) { + foreach (var dash in new[] { "-" }) { + alias = alias.Replace(consonant1 + consonant2 + dash, "3 " + consonant2 + dash); + } + } } foreach (var vowel in new[] { "V" }) { alias = alias.Replace(vowel, "@"); } - foreach (var CC in new[] { "T " }) { - alias = alias.Replace(CC, "f "); - } - foreach (var CC in new[] { " T" }) { - alias = alias.Replace(CC, " s"); - } - foreach (var CC in new[] { "D d" }) { - alias = alias.Replace(CC, "z d"); - } - foreach (var CC in new[] { "D " }) { - alias = alias.Replace(CC, "d "); - } - foreach (var CC in new[] { " D" }) { - alias = alias.Replace(CC, " z"); - } - foreach (var CC in new[] { "Z d" }) { - alias = alias.Replace(CC, "S t"); - } - foreach (var CC in new[] { " n-" }) { - alias = alias.Replace(CC, " m-"); - } return alias; } From 6752763bed3431af5373c73decd2fd0975d98eff Mon Sep 17 00:00:00 2001 From: Lotte V Date: Sat, 5 Aug 2023 00:10:23 +0200 Subject: [PATCH 02/11] Add alternate VCR ending + more consonant fixes --- OpenUtau.Plugin.Builtin/ENDeltaPhonemizer.cs | 24 ++++++++++---------- 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/OpenUtau.Plugin.Builtin/ENDeltaPhonemizer.cs b/OpenUtau.Plugin.Builtin/ENDeltaPhonemizer.cs index 9c78f4930..c1cd5451b 100644 --- a/OpenUtau.Plugin.Builtin/ENDeltaPhonemizer.cs +++ b/OpenUtau.Plugin.Builtin/ENDeltaPhonemizer.cs @@ -267,10 +267,8 @@ protected override List ProcessSyllable(Syllable syllable) { var rccv = $"- {string.Join("", cc)}{v}"; var cc1 = $"{string.Join("", cc.Skip(i))}"; var ccv = string.Join("", cc.Skip(i)) + v; - var vcc = $"{prevV} {string.Join("", cc.Take(2))}"; - var vcc2 = $"{prevV}{string.Join(" ", cc.Take(2))}"; var ucv = $"_{cc.Last()}{v}"; - if (!HasOto(rccv, syllable.vowelTone) && !vcc.Contains(cc1) && !vcc2.Contains(cc1) && !ValidateAlias(vcc).Contains(cc1) && !ValidateAlias(vcc2).Contains(cc1)) { + if (!HasOto(rccv, syllable.vowelTone)) { if (!HasOto(cc1, syllable.tone)) { cc1 = ValidateAlias(cc1); } @@ -306,7 +304,7 @@ protected override List ProcessSyllable(Syllable syllable) { } } var cc2 = $"{string.Join("", cc.Skip(i))}"; - if (i + 1 < lastC && !vcc.Contains(cc2) && !vcc2.Contains(cc2) && !ValidateAlias(vcc).Contains(cc2) && !ValidateAlias(vcc2).Contains(cc2)) { + if (i + 1 < lastC) { if (!HasOto(cc2, syllable.tone)) { cc2 = ValidateAlias(cc2); } @@ -357,20 +355,15 @@ protected override List ProcessSyllable(Syllable syllable) { if (affricates.Contains(cc[i + 1])) { i++; } else { - // // continue as usual + // continue as usual } } else { // like [V C1] [C1] [C2 ..] - if (!vcc.Contains(cc[i + 1]) && !vcc2.Contains(cc[i + 1])) { - TryAddPhoneme(phonemes, syllable.tone, cc[i + 1], ValidateAlias(cc[i + 1]), $"{cc[i + 1]} -", ValidateAlias($"{cc[i + 1]} -")); - } + TryAddPhoneme(phonemes, syllable.tone, cc[i], ValidateAlias(cc[i])); } } else { // like [V C1] [C1 C2] [C2 ..] or like [V C1] [C1 -] [C3 ..] - TryAddPhoneme(phonemes, syllable.tone, cc1); - if (affricates.Contains(cc[i]) && !HasOto(cc1, syllable.tone)) { - TryAddPhoneme(phonemes, syllable.tone, cc[i], ValidateAlias(cc[i]), $"{cc[i]} -", ValidateAlias($"{cc[i]} -")); - } + TryAddPhoneme(phonemes, syllable.tone, cc1, ValidateAlias(cc1), cc[i], ValidateAlias(cc[i])); } } } @@ -390,11 +383,18 @@ protected override List ProcessEnding(Ending ending) { } else if (ending.IsEndingVCWithOneConsonant) { var vc = $"{v} {cc[0]}"; var vcr = $"{v} {cc[0]}-"; + var vcr2 = $"{v}{cc[0]} -"; if (HasOto(vcr, ending.tone)) { phonemes.Add(vcr); } else if (!HasOto(vcr, ending.tone) && HasOto(ValidateAlias(vcr), ending.tone)) { vcr = ValidateAlias(vcr); phonemes.Add(vcr); + } else if (HasOto(vcr, ending.tone)) { + phonemes.Add(vcr); + } else if (!HasOto(ValidateAlias(vcr), ending.tone) && HasOto(vcr2, ending.tone)) { + phonemes.Add(vcr2); + } else if (!HasOto(vcr2, ending.tone) && HasOto(ValidateAlias(vcr2), ending.tone)) { + phonemes.Add(ValidateAlias(vcr2)); } else { if (HasOto(vc, ending.tone)) { phonemes.Add(vc); From 4160acba653dc4bab7787983e1b50b51e1e27562 Mon Sep 17 00:00:00 2001 From: Lotte V Date: Sun, 6 Aug 2023 04:42:42 +0200 Subject: [PATCH 03/11] Huge refactor + added some more functions --- OpenUtau.Plugin.Builtin/ENDeltaPhonemizer.cs | 362 ++++++++----------- 1 file changed, 160 insertions(+), 202 deletions(-) diff --git a/OpenUtau.Plugin.Builtin/ENDeltaPhonemizer.cs b/OpenUtau.Plugin.Builtin/ENDeltaPhonemizer.cs index c1cd5451b..c3b849c8d 100644 --- a/OpenUtau.Plugin.Builtin/ENDeltaPhonemizer.cs +++ b/OpenUtau.Plugin.Builtin/ENDeltaPhonemizer.cs @@ -1,7 +1,9 @@ using System; using System.Collections.Generic; +using System.ComponentModel.Design; using System.IO; using System.Linq; +using NAudio.Dmo; using OpenUtau.Api; using OpenUtau.Core.G2p; using OpenUtau.Core.Util; @@ -33,6 +35,53 @@ public class ENDeltaPhonemizer : SyllableBasedPhonemizer { .Where(parts => parts.Length == 2) .Where(parts => parts[0] != parts[1]) .ToDictionary(parts => parts[0], parts => parts[1]); + + // For banks aliased with VOCALOID-style phonemes + private readonly Dictionary vocaSampa = "A=Q;E=e;i=i:;u=u:;O=O:;3=@r".Split(';') + .Select(entry => entry.Split('=')) + .Where(parts => parts.Length == 2) + .Where(parts => parts[0] != parts[1]) + .ToDictionary(parts => parts[0], parts => parts[1]); + + private bool isVocaSampa = false; + + // For banks with slightly fewer vowels + private readonly Dictionary simpleDelta = "E=e;V=@;o=O".Split(';') + .Select(entry => entry.Split('=')) + .Where(parts => parts.Length == 2) + .Where(parts => parts[0] != parts[1]) + .ToDictionary(parts => parts[0], parts => parts[1]); + + private bool isSimpleDelta = false; + + // For banks with only minimal vowels + private readonly Dictionary miniDelta = "I=i;U=u".Split(';') + .Select(entry => entry.Split('=')) + .Where(parts => parts.Length == 2) + .Where(parts => parts[0] != parts[1]) + .ToDictionary(parts => parts[0], parts => parts[1]); + + private bool isMiniDelta = false; + + // For Japanese-English combined banks. + // NOTE: Rather rudimentary by default; a custom dictionary is recommended. + private readonly Dictionary enPlusJa = "j=y;dZ=j;r=r\\;tS=ch".Split(';') + .Select(entry => entry.Split('=')) + .Where(parts => parts.Length == 2) + .Where(parts => parts[0] != parts[1]) + .ToDictionary(parts => parts[0], parts => parts[1]); + + private bool isEnPlusJa = false; + + // For banks encoded in "true"/more accurate X-SAMPA. + private readonly Dictionary trueXSampa = "r=r\\;3=@`".Split(';') + .Select(entry => entry.Split('=')) + .Where(parts => parts.Length == 2) + .Where(parts => parts[0] != parts[1]) + .ToDictionary(parts => parts[0], parts => parts[1]); + + private bool isTrueXSampa = false; + protected override string[] GetVowels() => vowels; protected override string[] GetConsonants() => consonants; protected override string GetDictionaryName() => "cmudict-0_7b.txt"; @@ -70,6 +119,7 @@ protected override string[] GetSymbols(Note note) { return null; } List modified = new List(); + // Splits diphthongs and affricates if not present in the bank string[] diphthongs = new[] { "aI", "eI", "OI", "aU", "oU", "VI", "VU", "@U" }; string[] affricates = new[] { "dZ", "tS" }; foreach (string s in original) { @@ -94,11 +144,30 @@ protected override List ProcessSyllable(Syllable syllable) { var lastC = cc.Length - 1; var firstC = 0; var rv = $"- {v}"; + + // Switch between phonetic systems, depending on certain aliases in the bank + if (HasOto("i: b", syllable.tone)) { + isVocaSampa = true; + } + + if (!HasOto($"bV", syllable.vowelTone)) { + isSimpleDelta = true; + } + + if (!HasOto($"bI", syllable.vowelTone)) { + isMiniDelta = true; + } + + if (HasOto("か", syllable.vowelTone)) { + isEnPlusJa = true; + } + + if (HasOto("@` r\\", syllable.tone)) { + isTrueXSampa = true; + } + if (syllable.IsStartingV) { - if (HasOto(rv, syllable.vowelTone)) { - basePhoneme = rv; - } else if (!HasOto(rv, syllable.vowelTone) && HasOto(ValidateAlias(rv), syllable.vowelTone)) { - rv = ValidateAlias(rv); + if (HasOto(rv, syllable.vowelTone) || HasOto(ValidateAlias(rv), syllable.vowelTone)) { basePhoneme = rv; } else { basePhoneme = v; @@ -106,11 +175,9 @@ protected override List ProcessSyllable(Syllable syllable) { } else if (syllable.IsVV) { var vv = $"{prevV} {v}"; if (!CanMakeAliasExtension(syllable)) { - basePhoneme = vv; - if (!HasOto(vv, syllable.vowelTone) && HasOto(ValidateAlias(vv), syllable.vowelTone)) { - vv = ValidateAlias(vv); + if (HasOto(vv, syllable.vowelTone) || HasOto(ValidateAlias(vv), syllable.vowelTone)) { basePhoneme = vv; - } else if (!HasOto(vv, syllable.vowelTone) && !HasOto(ValidateAlias(vv), syllable.vowelTone)) { + } else { basePhoneme = v; } } else { @@ -120,12 +187,13 @@ protected override List ProcessSyllable(Syllable syllable) { } else if (syllable.IsStartingCVWithOneConsonant) { // TODO: move to config -CV or -C CV var rcv = $"- {cc[0]}{v}"; + var crv = $"{cc[0]} {v}"; var cv = $"{cc[0]}{v}"; - if (HasOto(rcv, syllable.vowelTone)) { - basePhoneme = rcv; - } else if (!HasOto(rcv, syllable.vowelTone) && HasOto(ValidateAlias(rcv), syllable.vowelTone)) { - rcv = ValidateAlias(rcv); + if (HasOto(rcv, syllable.vowelTone) || HasOto(ValidateAlias(rcv), syllable.vowelTone)) { basePhoneme = rcv; + } else if ((!HasOto(rcv, syllable.vowelTone) || !HasOto(ValidateAlias(rcv), syllable.vowelTone)) && (HasOto(crv, syllable.vowelTone) || HasOto(ValidateAlias(crv), syllable.vowelTone))) { + basePhoneme = crv; + TryAddPhoneme(phonemes, syllable.tone, $"- {cc[0]}", ValidateAlias($"- {cc[0]}")); } else { basePhoneme = cv; TryAddPhoneme(phonemes, syllable.tone, $"- {cc[0]}", ValidateAlias($"- {cc[0]}")); @@ -133,49 +201,40 @@ protected override List ProcessSyllable(Syllable syllable) { } else if (syllable.IsStartingCVWithMoreThanOneConsonant) { // try RCCV var rccv = $"- {string.Join("", cc)}{v}"; + var crv = $"{cc.Last()} {v}"; var ucv = $"_{cc.Last()}{v}"; - if (HasOto(rccv, syllable.vowelTone)) { - basePhoneme = rccv; - } else if (!HasOto(rccv, syllable.vowelTone) && HasOto(ValidateAlias(rccv), syllable.vowelTone)) { - rccv = ValidateAlias(rccv); + if (HasOto(rccv, syllable.vowelTone) || HasOto(ValidateAlias(rccv), syllable.vowelTone)) { basePhoneme = rccv; + } else if ((!HasOto(rccv, syllable.vowelTone) || !HasOto(ValidateAlias(rccv), syllable.vowelTone)) && (HasOto(crv, syllable.vowelTone) || HasOto(ValidateAlias(crv), syllable.vowelTone))) { + basePhoneme = crv; } else { basePhoneme = $"{cc.Last()}{v}"; - if (HasOto(ucv, syllable.vowelTone)) { - basePhoneme = ucv; - } else if (!HasOto(ucv, syllable.vowelTone) && HasOto(ValidateAlias(ucv), syllable.vowelTone)) { - ucv = ValidateAlias(ucv); + if (HasOto(ucv, syllable.vowelTone) || HasOto(ValidateAlias(ucv), syllable.vowelTone)) { basePhoneme = ucv; } // try RCC for (var i = cc.Length; i > 1; i--) { - if (TryAddPhoneme(phonemes, syllable.tone, $"- {string.Join("", cc.Take(i))}")) { + if (TryAddPhoneme(phonemes, syllable.tone, $"- {string.Join("", cc.Take(i))}", ValidateAlias($"- {string.Join("", cc.Take(i))}"))) { firstC = i - 1; break; } } if (phonemes.Count == 0) { - TryAddPhoneme(phonemes, syllable.tone, $"- {cc[0]}"); + TryAddPhoneme(phonemes, syllable.tone, $"- {cc[0]}", ValidateAlias($"- {cc[0]}")); } // try CCV for (var i = firstC; i < cc.Length - 1; i++) { var ccv = string.Join("", cc.Skip(i)) + v; - if (HasOto(ccv, syllable.vowelTone)) { + if (HasOto(ccv, syllable.vowelTone) || HasOto(ValidateAlias(ccv), syllable.vowelTone)) { basePhoneme = ccv; lastC = i; break; - } else if (!HasOto(ccv, syllable.vowelTone) && HasOto(ValidateAlias(ccv), syllable.vowelTone)) { - ccv = ValidateAlias(ccv); - basePhoneme = ccv; - lastC = i; + } else if (!HasOto(ccv, syllable.vowelTone) || !HasOto(ValidateAlias(ccv), syllable.vowelTone) && (HasOto(crv, syllable.vowelTone) || HasOto(ValidateAlias(crv), syllable.vowelTone))) { + basePhoneme = crv; break; } else { basePhoneme = $"{cc.Last()}{v}"; - if (HasOto(ucv, syllable.vowelTone)) { - basePhoneme = ucv; - break; - } else if (!HasOto(ucv, syllable.vowelTone) && HasOto(ValidateAlias(ucv), syllable.vowelTone)) { - ucv = ValidateAlias(ucv); + if (HasOto(ucv, syllable.vowelTone) || HasOto(ValidateAlias(ucv), syllable.vowelTone)) { basePhoneme = ucv; break; } @@ -185,39 +244,29 @@ protected override List ProcessSyllable(Syllable syllable) { } else { // VCV var vcv = $"{prevV} {cc[0]}{v}"; var vccv = $"{prevV} {string.Join("", cc)}{v}"; - if (syllable.IsVCVWithOneConsonant && HasOto(vcv, syllable.vowelTone)) { + var crv = $"{cc.Last()} {v}"; + if (syllable.IsVCVWithOneConsonant && (HasOto(vcv, syllable.vowelTone) || HasOto(ValidateAlias(vcv), syllable.vowelTone))) { basePhoneme = vcv; - } else if (syllable.IsVCVWithOneConsonant && !HasOto(vcv, syllable.vowelTone) && HasOto(ValidateAlias(vcv), syllable.vowelTone)) { - vcv = ValidateAlias(vcv); - basePhoneme = vcv; - } else if (syllable.IsVCVWithMoreThanOneConsonant && HasOto(vccv, syllable.vowelTone)) { - basePhoneme = vccv; - } else if (syllable.IsVCVWithMoreThanOneConsonant && !HasOto(vccv, syllable.vowelTone) && HasOto(ValidateAlias(vccv), syllable.vowelTone)) { - vccv = ValidateAlias(vccv); + } else if (syllable.IsVCVWithMoreThanOneConsonant && (HasOto(vccv, syllable.vowelTone) || HasOto(ValidateAlias(vccv), syllable.vowelTone))) { basePhoneme = vccv; } else { basePhoneme = cc.Last() + v; + if (!HasOto(cc.Last() + v, syllable.vowelTone) && (HasOto(crv, syllable.vowelTone) || HasOto(ValidateAlias(crv), syllable.vowelTone))) { + basePhoneme = crv; + } // try CCV if (cc.Length - firstC > 1) { for (var i = firstC; i < cc.Length; i++) { var ccv = $"{string.Join("", cc.Skip(i))}{v}"; var rccv = $"- {string.Join("", cc.Skip(i))}{v}"; - if (HasOto(ccv, syllable.vowelTone)) { + if (HasOto(ccv, syllable.vowelTone) || HasOto(ValidateAlias(ccv), syllable.vowelTone)) { lastC = i; basePhoneme = ccv; break; - } else if (!HasOto(ccv, syllable.vowelTone) && HasOto(ValidateAlias(ccv), syllable.vowelTone)) { - lastC = i; - basePhoneme = ValidateAlias(ccv); - break; - } else if (HasOto(rccv, syllable.vowelTone) && (!HasOto(ccv, syllable.vowelTone) && HasOto(ValidateAlias(ccv), syllable.vowelTone))) { + } else if ((HasOto(rccv, syllable.vowelTone) || HasOto(ValidateAlias(rccv), syllable.vowelTone)) && (!HasOto(ccv, syllable.vowelTone) || !HasOto(ValidateAlias(ccv), syllable.vowelTone))) { lastC = i; basePhoneme = rccv; break; - } else if (!HasOto(rccv, syllable.vowelTone) && (!HasOto(ccv, syllable.vowelTone) && HasOto(ValidateAlias(ccv), syllable.vowelTone))) { - lastC = i; - basePhoneme = ValidateAlias(rccv); - break; } } } @@ -228,31 +277,16 @@ protected override List ProcessSyllable(Syllable syllable) { var vcc2 = $"{prevV}{string.Join(" ", cc.Take(2))}"; var vc = $"{prevV} {cc[0]}"; if (i == 0) { - if (HasOto(vr, syllable.tone)) { - phonemes.Add(vr); - } else if (!HasOto(vr, syllable.tone) && HasOto(ValidateAlias(vr), syllable.tone)) { - vr = ValidateAlias(vr); + if (HasOto(vr, syllable.tone) || HasOto(ValidateAlias(vr), syllable.tone)) { phonemes.Add(vr); } - } else if (HasOto(vcc, syllable.tone)) { - phonemes.Add(vcc); - break; - } else if (!HasOto(vcc, syllable.tone) && HasOto(ValidateAlias(vcc), syllable.tone)) { - vcc = ValidateAlias(vcc); + } else if (HasOto(vcc, syllable.tone) || HasOto(ValidateAlias(vcc), syllable.tone)) { phonemes.Add(vcc); break; - } else if (!HasOto(ValidateAlias(vcc), syllable.tone) && HasOto(vcc2, syllable.tone)) { + } else if ((!HasOto(vcc, syllable.tone) || !HasOto(ValidateAlias(vcc), syllable.tone)) && (HasOto(vcc2, syllable.tone) || HasOto(ValidateAlias(vcc2), syllable.tone))) { phonemes.Add(vcc2); break; - } else if (!HasOto(vcc2, syllable.tone) && HasOto(ValidateAlias(vcc2), syllable.tone)) { - vcc2 = ValidateAlias(vcc2); - phonemes.Add(vcc2); - break; - } else if (!HasOto(ValidateAlias(vcc), syllable.tone) && HasOto(vc, syllable.tone)) { - phonemes.Add(vc); - break; - } else if (!HasOto(vc, syllable.tone) && HasOto(ValidateAlias(vc), syllable.tone)) { - vc = ValidateAlias(vc); + } else if ((!HasOto(vcc2, syllable.tone) || !HasOto(ValidateAlias(vcc2), syllable.tone)) && (HasOto(vc, syllable.tone) || HasOto(ValidateAlias(vc), syllable.tone))) { phonemes.Add(vc); break; } else { @@ -290,21 +324,16 @@ protected override List ProcessSyllable(Syllable syllable) { if (!HasOto(cc1, syllable.tone)) { cc1 = ValidateAlias(cc1); } - if (HasOto(ccv, syllable.vowelTone)) { + if (HasOto(ccv, syllable.vowelTone) || HasOto(ValidateAlias(ccv), syllable.vowelTone)) { basePhoneme = ccv; - if (!HasOto(ccv, syllable.vowelTone)) { - ccv = ValidateAlias(ccv); - basePhoneme = ccv; - } - } else if (HasOto(ucv, syllable.vowelTone) && HasOto(cc1, syllable.vowelTone) && !cc1.Contains($"{cc[i]} {cc[i + 1]}")) { + } else if ((HasOto(ucv, syllable.vowelTone) || HasOto(ValidateAlias(ucv), syllable.vowelTone)) && HasOto(cc1, syllable.vowelTone) && !cc1.Contains($"{cc[i]} {cc[i + 1]}")) { basePhoneme = ucv; - if (!HasOto(ucv, syllable.vowelTone)) { - ucv = ValidateAlias(ucv); - basePhoneme = ucv; - } } - var cc2 = $"{string.Join("", cc.Skip(i))}"; if (i + 1 < lastC) { + var cc2 = $"{string.Join("", cc.Skip(i))}"; + if (!HasOto(cc2, syllable.tone)) { + cc2 = ValidateAlias(cc2); + } if (!HasOto(cc2, syllable.tone)) { cc2 = ValidateAlias(cc2); } @@ -326,18 +355,10 @@ protected override List ProcessSyllable(Syllable syllable) { if (!HasOto(cc2, syllable.tone)) { cc2 = ValidateAlias(cc2); } - if (HasOto(ccv, syllable.vowelTone)) { + if (HasOto(ccv, syllable.vowelTone) || HasOto(ValidateAlias(ccv), syllable.vowelTone)) { basePhoneme = ccv; - if (!HasOto(ccv, syllable.vowelTone)) { - ccv = ValidateAlias(ccv); - basePhoneme = ccv; - } - } else if (HasOto(ucv, syllable.vowelTone) && HasOto(cc2, syllable.vowelTone) && !cc2.Contains($"{cc[i + 1]} {cc[i + 2]}")) { + } else if ((HasOto(ucv, syllable.vowelTone) || HasOto(ValidateAlias(ucv), syllable.vowelTone)) && (HasOto(cc2, syllable.vowelTone) || HasOto(ValidateAlias(cc2), syllable.vowelTone)) && !cc2.Contains($"{cc[i + 1]} {cc[i + 2]}")) { basePhoneme = ucv; - if (!HasOto(ucv, syllable.vowelTone)) { - ucv = ValidateAlias(ucv); - basePhoneme = ucv; - } } if (TryAddPhoneme(phonemes, syllable.tone, $"{cc[i]} {cc[i + 1]}{cc[i + 2]}-", ValidateAlias($"{cc[i]} {cc[i + 1]}{cc[i + 2]}-"))) { // like [V C1] [C1 C2C3-] ... @@ -345,7 +366,7 @@ protected override List ProcessSyllable(Syllable syllable) { } else if (HasOto(cc1, syllable.tone) && HasOto(cc2, syllable.tone) && !cc1.Contains($"{string.Join("", cc.Skip(i))}")) { // like [V C1] [C1 C2] [C2 C3] [C3 ..] phonemes.Add(cc1); - } else if (TryAddPhoneme(phonemes, syllable.tone, cc1)) { + } else if (TryAddPhoneme(phonemes, syllable.tone, cc1, ValidateAlias(cc1))) { // like [V C1] [C1 C2] [C2 ..] if (cc1.Contains($"{string.Join("", cc.Skip(i))}")) { i++; @@ -384,28 +405,16 @@ protected override List ProcessEnding(Ending ending) { var vc = $"{v} {cc[0]}"; var vcr = $"{v} {cc[0]}-"; var vcr2 = $"{v}{cc[0]} -"; - if (HasOto(vcr, ending.tone)) { - phonemes.Add(vcr); - } else if (!HasOto(vcr, ending.tone) && HasOto(ValidateAlias(vcr), ending.tone)) { - vcr = ValidateAlias(vcr); + if (HasOto(vcr, ending.tone) || HasOto(ValidateAlias(vcr), ending.tone)) { phonemes.Add(vcr); - } else if (HasOto(vcr, ending.tone)) { - phonemes.Add(vcr); - } else if (!HasOto(ValidateAlias(vcr), ending.tone) && HasOto(vcr2, ending.tone)) { + } else if ((!HasOto(vcr, ending.tone) || !HasOto(ValidateAlias(vcr), ending.tone)) && (HasOto(vcr2, ending.tone) || HasOto(ValidateAlias(vcr2), ending.tone))) { phonemes.Add(vcr2); - } else if (!HasOto(vcr2, ending.tone) && HasOto(ValidateAlias(vcr2), ending.tone)) { - phonemes.Add(ValidateAlias(vcr2)); } else { - if (HasOto(vc, ending.tone)) { - phonemes.Add(vc); - } else { - vc = ValidateAlias(vc); - phonemes.Add(vc); - } + phonemes.Add(vc); if (affricates.Contains(cc[0])) { TryAddPhoneme(phonemes, ending.tone, $"{cc[0]} -", cc[0]); } else { - TryAddPhoneme(phonemes, ending.tone, $"{cc[0]} -"); + TryAddPhoneme(phonemes, ending.tone, $"{cc[0]} -", ValidateAlias($"{cc[0]} -")); } } } else { @@ -414,31 +423,16 @@ protected override List ProcessEnding(Ending ending) { var vcc3 = $"{v}{cc[0]} {cc[0 + 1]}-"; var vcc4 = $"{v}{cc[0]} {cc[0 + 1]}"; var vc = $"{v} {cc[0]}"; - if (HasOto(vcc1, ending.tone)) { + if (HasOto(vcc1, ending.tone) || HasOto(ValidateAlias(vcc1), ending.tone)) { phonemes.Add(vcc1); - } else if (!HasOto(vcc1, ending.tone) && HasOto(ValidateAlias(vcc1), ending.tone)) { - vcc1 = ValidateAlias(vcc1); - phonemes.Add(vcc1); - } else if (HasOto(vcc2, ending.tone)) { - phonemes.Add(vcc2); - } else if (!HasOto(vcc2, ending.tone) && HasOto(ValidateAlias(vcc2), ending.tone)) { - vcc2 = ValidateAlias(vcc2); + } else if (HasOto(vcc2, ending.tone) || HasOto(ValidateAlias(vcc2), ending.tone)) { phonemes.Add(vcc2); - } else if (HasOto(vcc3, ending.tone)) { - phonemes.Add(vcc3); - } else if (!HasOto(vcc3, ending.tone) && HasOto(ValidateAlias(vcc3), ending.tone)) { - vcc3 = ValidateAlias(vcc3); + } else if (HasOto(vcc3, ending.tone) || HasOto(ValidateAlias(vcc3), ending.tone)) { phonemes.Add(vcc3); } else { - if (HasOto(vcc4, ending.tone)) { - phonemes.Add(vcc4); - } else if (!HasOto(vcc4, ending.tone) && HasOto(ValidateAlias(vcc4), ending.tone)) { - vcc4 = ValidateAlias(vcc4); + if (HasOto(vcc4, ending.tone) || HasOto(ValidateAlias(vcc4), ending.tone)) { phonemes.Add(vcc4); - } else if (HasOto(vc, ending.tone)) { - phonemes.Add(vc); } else { - vc = ValidateAlias(vc); phonemes.Add(vc); } // all CCs except the first one are /C1C2/, the last one is /C1 C2-/ @@ -463,15 +457,15 @@ protected override List ProcessEnding(Ending ending) { if (i < cc.Length - 2) { var cc2 = $"{cc[i]} {string.Join("", cc.Skip(i))}-"; var cc3 = $"{cc[i]} {cc[i + 1]}{cc[i + 2]}-"; - if (HasOto(cc2, ending.tone)) { + if (HasOto(cc2, ending.tone) || HasOto(ValidateAlias(cc2), ending.tone)) { phonemes.Add(cc2); i++; - } else if (HasOto(cc3, ending.tone)) { + } else if (HasOto(cc3, ending.tone) || HasOto(ValidateAlias(cc3), ending.tone)) { // like [C1 C2][C2 ...] phonemes.Add(cc3); i++; } else { - if (HasOto(cc1, ending.tone) && (!HasOto(vcc4, ending.tone))) { + if (HasOto(cc1, ending.tone) && (!HasOto(vcc4, ending.tone) || !HasOto(ValidateAlias(vcc4), ending.tone))) { // like [C1 C2][C2 ...] phonemes.Add(cc1); } else if (TryAddPhoneme(phonemes, ending.tone, $"{cc[i + 1]} {cc[i + 2]}-", ValidateAlias($"{cc[i + 1]} {cc[i + 2]}-"))) { @@ -480,24 +474,24 @@ protected override List ProcessEnding(Ending ending) { } else if (TryAddPhoneme(phonemes, ending.tone, $"{cc[i + 1]} {cc[i + 2]}", ValidateAlias($"{cc[i + 1]} {cc[i + 2]}"))) { // like [C1 C2][C3 ...] if (cc[i + 2] == cc.Last()) { - TryAddPhoneme(phonemes, ending.tone, $"{cc[i + 2]} -"); + TryAddPhoneme(phonemes, ending.tone, $"{cc[i + 2]} -", ValidateAlias($"{cc[i + 2]} -")); i++; } else { continue; } - } else if (TryAddPhoneme(phonemes, ending.tone, $"{cc[i + 1]}{cc[i + 2]}")) { + } else if (TryAddPhoneme(phonemes, ending.tone, $"{cc[i + 1]}{cc[i + 2]}", ValidateAlias($"{cc[i + 1]}{cc[i + 2]}"))) { // like [C1C2][C3 ...] } else if (!cc.First().Contains(cc[i + 1]) || !cc.First().Contains(cc[i + 2])) { // like [C1][C2 ...] - if (affricates.Contains(cc[i]) && (!HasOto(vcc4, ending.tone))) { - TryAddPhoneme(phonemes, ending.tone, cc[i], $"{cc[i]} -"); + if (affricates.Contains(cc[i]) && (!HasOto(vcc4, ending.tone) || !HasOto(ValidateAlias(vcc4), ending.tone))) { + TryAddPhoneme(phonemes, ending.tone, cc[i], ValidateAlias(cc[i]), $"{cc[i]} -", ValidateAlias($"{cc[i]} -")); } - TryAddPhoneme(phonemes, ending.tone, cc[i + 1], $"{cc[i + 1]} -"); - TryAddPhoneme(phonemes, ending.tone, $"{cc[i + 2]} -", cc[i + 2]); + TryAddPhoneme(phonemes, ending.tone, cc[i + 1], ValidateAlias(cc[i + 1]), $"{cc[i + 1]} -", ValidateAlias($"{cc[i + 1]} -")); + TryAddPhoneme(phonemes, ending.tone, $"{cc[i + 2]} -", ValidateAlias($"{cc[i + 2]} -"), cc[i + 2], ValidateAlias(cc[i + 2])); i++; } else if (!cc.First().Contains(cc[i])) { // like [C1][C2 ...] - TryAddPhoneme(phonemes, ending.tone, cc[i], $"{cc[i]} -"); + TryAddPhoneme(phonemes, ending.tone, cc[i], ValidateAlias(cc[i]), $"{cc[i]} -", ValidateAlias($"{cc[i]} -")); i++; } } @@ -511,7 +505,7 @@ protected override List ProcessEnding(Ending ending) { if (affricates.Contains(cc[i + 1])) { TryAddPhoneme(phonemes, ending.tone, $"{cc[i + 1]} -", cc[i + 1]); } else { - TryAddPhoneme(phonemes, ending.tone, $"{cc[i + 1]} -"); + TryAddPhoneme(phonemes, ending.tone, $"{cc[i + 1]} -", ValidateAlias($"{cc[i + 1]} -")); } i++; } else if (TryAddPhoneme(phonemes, ending.tone, cc1)) { @@ -519,17 +513,17 @@ protected override List ProcessEnding(Ending ending) { if (affricates.Contains(cc[i + 1])) { TryAddPhoneme(phonemes, ending.tone, $"{cc[i + 1]} -", cc[i + 1]); } else { - TryAddPhoneme(phonemes, ending.tone, $"{cc[i + 1]} -"); + TryAddPhoneme(phonemes, ending.tone, $"{cc[i + 1]} -", ValidateAlias($"{cc[i + 1]} -")); } i++; } else { // like [C1][C2 -] if (!HasOto(vcc4, ending.tone)) { - TryAddPhoneme(phonemes, ending.tone, cc[i], $"{cc[i]} -"); + TryAddPhoneme(phonemes, ending.tone, cc[i], ValidateAlias(cc[i]), $"{cc[i]} -", ValidateAlias($"{cc[i]} -")); if (!affricates.Contains(cc[0])) { phonemes.Remove(cc[0]); } - TryAddPhoneme(phonemes, ending.tone, $"{cc[i + 1]} -", cc[i + 1]); + TryAddPhoneme(phonemes, ending.tone, $"{cc[i + 1]} -", ValidateAlias($"{cc[i + 1]} -"), cc[i + 1], ValidateAlias(cc[i + 1])); i++; } } @@ -537,7 +531,7 @@ protected override List ProcessEnding(Ending ending) { if (affricates.Contains(cc[0 + 1])) { TryAddPhoneme(phonemes, ending.tone, $"{cc[0 + 1]} -", $"{cc[0 + 1]}"); } else { - TryAddPhoneme(phonemes, ending.tone, $"{cc[0 + 1]} -"); + TryAddPhoneme(phonemes, ending.tone, $"{cc[0 + 1]} -", ValidateAlias($"{cc[0 + 1]} -")); } i++; } @@ -549,84 +543,48 @@ protected override List ProcessEnding(Ending ending) { } protected override string ValidateAlias(string alias) { - foreach (var vowel in new[] { "A" }) { - alias = alias.Replace(vowel, "Q"); - } - foreach (var consonant in new[] { "b" }) { - foreach (var vowel in new[] { "V" }) { - alias = alias.Replace(consonant + vowel, consonant + "@"); + // Validate alias depending on method + if (isVocaSampa) { + foreach (var syllable in vocaSampa) { + alias = alias.Replace(syllable.Key, syllable.Value); } } - foreach (var vowel in new[] { "@ " }) { - foreach (var consonant in new[] { "b" }) { - alias = alias.Replace("@ " + consonant, "@ " + consonant); + + if (isSimpleDelta) { + foreach (var syllable in simpleDelta) { + alias = alias.Replace(syllable.Key, syllable.Value); } } - foreach (var vowel in new[] { "a" }) { - foreach (var vowel2 in new[] { " I" }) { - alias = alias.Replace(vowel + vowel2, "V" + vowel2); + + if (isMiniDelta) { + foreach (var syllable in miniDelta) { + alias = alias.Replace(syllable.Key, syllable.Value); } } - foreach (var vowel in new[] { "a" }) { - foreach (var vowel2 in new[] { " U" }) { - alias = alias.Replace(vowel + vowel2, "V" + vowel2); + + if (isEnPlusJa) { + foreach (var syllable in enPlusJa) { + alias = alias.Replace(syllable.Key, syllable.Value); } } - foreach (var vowel in new[] { "O" }) { - alias = alias.Replace(vowel, "O:"); - } - foreach (var vowel in new[] { "i" }) { - alias = alias.Replace(vowel, "i:"); - } - foreach (var vowel in new[] { "u" }) { - alias = alias.Replace(vowel, "u:"); - } - foreach (var vowel in new[] { "@r" }) { - alias = alias.Replace(vowel, "@`"); - } - foreach (var vowel in new[] { "3" }) { - alias = alias.Replace(vowel, "@r"); - } - foreach (var vowel in new[] { "aI" }) { - alias = alias.Replace(vowel, "VI"); - } - foreach (var vowel in new[] { "aU" }) { - alias = alias.Replace(vowel, "VU"); - } - foreach (var vowel in new[] { "oU" }) { - alias = alias.Replace(vowel, "@U"); - } - foreach (var vowel in new[] { "E" }) { - alias = alias.Replace(vowel, "e"); - } - foreach (var vowel in new[] { "I" }) { - alias = alias.Replace(vowel, "i"); - } - foreach (var vowel in new[] { "o" }) { - alias = alias.Replace(vowel, "O"); - } - foreach (var vowel in new[] { "U" }) { - alias = alias.Replace(vowel, "u"); - } - foreach (var VV in new[] { "O u" }) { - alias = alias.Replace(VV, "O U"); - } - foreach (var VV in new[] { "i O" }) { - alias = alias.Replace(VV, "I O"); + + if (isTrueXSampa) { + foreach (var syllable in trueXSampa) { + alias = alias.Replace(syllable.Key, syllable.Value); + } } + + // Other validations foreach (var CC in new[] { "N k", "N g", "N k-", "N g-" }) { alias = alias.Replace("N ", "n "); } - foreach (var consonant1 in new[] { "r " }) { - foreach (var consonant2 in GetConsonants()) { + foreach (var consonant1 in new[] { "r ", "r\\ " }) { + foreach (var consonant2 in consonants) { foreach (var dash in new[] { "-" }) { alias = alias.Replace(consonant1 + consonant2 + dash, "3 " + consonant2 + dash); } } } - foreach (var vowel in new[] { "V" }) { - alias = alias.Replace(vowel, "@"); - } return alias; } From a661f7077a76bc93582e25e2bfcb2b463314fb9a Mon Sep 17 00:00:00 2001 From: Lotte V Date: Sun, 6 Aug 2023 04:56:27 +0200 Subject: [PATCH 04/11] Small fix --- OpenUtau.Plugin.Builtin/ENDeltaPhonemizer.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/OpenUtau.Plugin.Builtin/ENDeltaPhonemizer.cs b/OpenUtau.Plugin.Builtin/ENDeltaPhonemizer.cs index c3b849c8d..73d552830 100644 --- a/OpenUtau.Plugin.Builtin/ENDeltaPhonemizer.cs +++ b/OpenUtau.Plugin.Builtin/ENDeltaPhonemizer.cs @@ -125,7 +125,7 @@ protected override string[] GetSymbols(Note note) { foreach (string s in original) { if (diphthongs.Contains(s) && !HasOto($"b{s}", note.tone)) { modified.AddRange(new string[] { s[0].ToString(), s[1].ToString() }); - } else if (affricates.Contains(s) && !HasOto($"i {s}", note.tone)) { + } else if (affricates.Contains(s) && (!HasOto($"i {s}", note.tone) || !HasOto($"i: {s}", note.tone))) { modified.AddRange(new string[] { s[0].ToString(), s[1].ToString() }); } else { modified.Add(s); From 845ff78f6081cde65603a50ab7ec8f3961887c4f Mon Sep 17 00:00:00 2001 From: Lotte V Date: Sun, 6 Aug 2023 05:23:57 +0200 Subject: [PATCH 05/11] Small fixes --- OpenUtau.Plugin.Builtin/ENDeltaPhonemizer.cs | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/OpenUtau.Plugin.Builtin/ENDeltaPhonemizer.cs b/OpenUtau.Plugin.Builtin/ENDeltaPhonemizer.cs index 73d552830..72f96fc32 100644 --- a/OpenUtau.Plugin.Builtin/ENDeltaPhonemizer.cs +++ b/OpenUtau.Plugin.Builtin/ENDeltaPhonemizer.cs @@ -205,12 +205,13 @@ protected override List ProcessSyllable(Syllable syllable) { var ucv = $"_{cc.Last()}{v}"; if (HasOto(rccv, syllable.vowelTone) || HasOto(ValidateAlias(rccv), syllable.vowelTone)) { basePhoneme = rccv; - } else if ((!HasOto(rccv, syllable.vowelTone) || !HasOto(ValidateAlias(rccv), syllable.vowelTone)) && (HasOto(crv, syllable.vowelTone) || HasOto(ValidateAlias(crv), syllable.vowelTone))) { - basePhoneme = crv; } else { - basePhoneme = $"{cc.Last()}{v}"; if (HasOto(ucv, syllable.vowelTone) || HasOto(ValidateAlias(ucv), syllable.vowelTone)) { basePhoneme = ucv; + } else if (HasOto(crv, syllable.vowelTone) || HasOto(ValidateAlias(crv), syllable.vowelTone)) { + basePhoneme = crv; + } else { + basePhoneme = $"{cc.Last()}{v}"; } // try RCC for (var i = cc.Length; i > 1; i--) { @@ -229,14 +230,16 @@ protected override List ProcessSyllable(Syllable syllable) { basePhoneme = ccv; lastC = i; break; - } else if (!HasOto(ccv, syllable.vowelTone) || !HasOto(ValidateAlias(ccv), syllable.vowelTone) && (HasOto(crv, syllable.vowelTone) || HasOto(ValidateAlias(crv), syllable.vowelTone))) { - basePhoneme = crv; - break; } else { - basePhoneme = $"{cc.Last()}{v}"; if (HasOto(ucv, syllable.vowelTone) || HasOto(ValidateAlias(ucv), syllable.vowelTone)) { basePhoneme = ucv; break; + } else if (HasOto(crv, syllable.vowelTone) || HasOto(ValidateAlias(crv), syllable.vowelTone)) { + basePhoneme = crv; + break; + } else { + basePhoneme = $"{cc.Last()}{v}"; + break; } } } From a886a22f5d39fec5c360686a8122856a1b8a2686 Mon Sep 17 00:00:00 2001 From: Lotte V Date: Sun, 6 Aug 2023 05:36:31 +0200 Subject: [PATCH 06/11] More optimizations --- OpenUtau.Plugin.Builtin/ENDeltaPhonemizer.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/OpenUtau.Plugin.Builtin/ENDeltaPhonemizer.cs b/OpenUtau.Plugin.Builtin/ENDeltaPhonemizer.cs index 72f96fc32..8f3202419 100644 --- a/OpenUtau.Plugin.Builtin/ENDeltaPhonemizer.cs +++ b/OpenUtau.Plugin.Builtin/ENDeltaPhonemizer.cs @@ -286,10 +286,10 @@ protected override List ProcessSyllable(Syllable syllable) { } else if (HasOto(vcc, syllable.tone) || HasOto(ValidateAlias(vcc), syllable.tone)) { phonemes.Add(vcc); break; - } else if ((!HasOto(vcc, syllable.tone) || !HasOto(ValidateAlias(vcc), syllable.tone)) && (HasOto(vcc2, syllable.tone) || HasOto(ValidateAlias(vcc2), syllable.tone))) { + } else if (HasOto(vcc2, syllable.tone) || HasOto(ValidateAlias(vcc2), syllable.tone)) { phonemes.Add(vcc2); break; - } else if ((!HasOto(vcc2, syllable.tone) || !HasOto(ValidateAlias(vcc2), syllable.tone)) && (HasOto(vc, syllable.tone) || HasOto(ValidateAlias(vc), syllable.tone))) { + } else if (HasOto(vc, syllable.tone) || HasOto(ValidateAlias(vc), syllable.tone)) { phonemes.Add(vc); break; } else { From 7ef007270eb4ab666ea32d9ff38b751707dc3f53 Mon Sep 17 00:00:00 2001 From: Lotte V Date: Sun, 6 Aug 2023 16:36:26 +0200 Subject: [PATCH 07/11] Proper VCC fix --- OpenUtau.Plugin.Builtin/ENDeltaPhonemizer.cs | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/OpenUtau.Plugin.Builtin/ENDeltaPhonemizer.cs b/OpenUtau.Plugin.Builtin/ENDeltaPhonemizer.cs index 8f3202419..b063f8e58 100644 --- a/OpenUtau.Plugin.Builtin/ENDeltaPhonemizer.cs +++ b/OpenUtau.Plugin.Builtin/ENDeltaPhonemizer.cs @@ -125,7 +125,7 @@ protected override string[] GetSymbols(Note note) { foreach (string s in original) { if (diphthongs.Contains(s) && !HasOto($"b{s}", note.tone)) { modified.AddRange(new string[] { s[0].ToString(), s[1].ToString() }); - } else if (affricates.Contains(s) && (!HasOto($"i {s}", note.tone) || !HasOto($"i: {s}", note.tone))) { + } else if (affricates.Contains(s) && (!HasOto($"i {s}", note.tone) && !HasOto($"i: {s}", note.tone))) { modified.AddRange(new string[] { s[0].ToString(), s[1].ToString() }); } else { modified.Add(s); @@ -285,9 +285,11 @@ protected override List ProcessSyllable(Syllable syllable) { } } else if (HasOto(vcc, syllable.tone) || HasOto(ValidateAlias(vcc), syllable.tone)) { phonemes.Add(vcc); + firstC = 1; break; } else if (HasOto(vcc2, syllable.tone) || HasOto(ValidateAlias(vcc2), syllable.tone)) { phonemes.Add(vcc2); + firstC = 1; break; } else if (HasOto(vc, syllable.tone) || HasOto(ValidateAlias(vc), syllable.tone)) { phonemes.Add(vc); @@ -304,8 +306,8 @@ protected override List ProcessSyllable(Syllable syllable) { var rccv = $"- {string.Join("", cc)}{v}"; var cc1 = $"{string.Join("", cc.Skip(i))}"; var ccv = string.Join("", cc.Skip(i)) + v; - var ucv = $"_{cc.Last()}{v}"; - if (!HasOto(rccv, syllable.vowelTone)) { + var ucv = $"_{cc.Last()}{v}"; ; + if (!HasOto(rccv, syllable.vowelTone) || !HasOto(ValidateAlias(rccv), syllable.vowelTone)) { if (!HasOto(cc1, syllable.tone)) { cc1 = ValidateAlias(cc1); } @@ -369,7 +371,7 @@ protected override List ProcessSyllable(Syllable syllable) { } else if (HasOto(cc1, syllable.tone) && HasOto(cc2, syllable.tone) && !cc1.Contains($"{string.Join("", cc.Skip(i))}")) { // like [V C1] [C1 C2] [C2 C3] [C3 ..] phonemes.Add(cc1); - } else if (TryAddPhoneme(phonemes, syllable.tone, cc1, ValidateAlias(cc1))) { + } else if (TryAddPhoneme(phonemes, syllable.tone, cc1)) { // like [V C1] [C1 C2] [C2 ..] if (cc1.Contains($"{string.Join("", cc.Skip(i))}")) { i++; @@ -387,7 +389,7 @@ protected override List ProcessSyllable(Syllable syllable) { } } else { // like [V C1] [C1 C2] [C2 ..] or like [V C1] [C1 -] [C3 ..] - TryAddPhoneme(phonemes, syllable.tone, cc1, ValidateAlias(cc1), cc[i], ValidateAlias(cc[i])); + TryAddPhoneme(phonemes, syllable.tone, cc1, cc[i], ValidateAlias(cc[i])); } } } @@ -583,9 +585,7 @@ protected override string ValidateAlias(string alias) { } foreach (var consonant1 in new[] { "r ", "r\\ " }) { foreach (var consonant2 in consonants) { - foreach (var dash in new[] { "-" }) { - alias = alias.Replace(consonant1 + consonant2 + dash, "3 " + consonant2 + dash); - } + alias = alias.Replace(consonant1 + consonant2, "3 " + consonant2); } } return alias; From 204c146a99bd8673b84b5576ba03c3df7aa64dc6 Mon Sep 17 00:00:00 2001 From: Lotte V Date: Sun, 6 Aug 2023 23:49:30 +0200 Subject: [PATCH 08/11] Remove unused references --- OpenUtau.Plugin.Builtin/ENDeltaPhonemizer.cs | 3 --- 1 file changed, 3 deletions(-) diff --git a/OpenUtau.Plugin.Builtin/ENDeltaPhonemizer.cs b/OpenUtau.Plugin.Builtin/ENDeltaPhonemizer.cs index b063f8e58..7b70eae23 100644 --- a/OpenUtau.Plugin.Builtin/ENDeltaPhonemizer.cs +++ b/OpenUtau.Plugin.Builtin/ENDeltaPhonemizer.cs @@ -1,12 +1,9 @@ using System; using System.Collections.Generic; -using System.ComponentModel.Design; using System.IO; using System.Linq; -using NAudio.Dmo; using OpenUtau.Api; using OpenUtau.Core.G2p; -using OpenUtau.Core.Util; using Serilog; namespace OpenUtau.Plugin.Builtin { From 31b714f8dceb7a833b9647037317b465b8e732fb Mon Sep 17 00:00:00 2001 From: Lotte V Date: Sun, 6 Aug 2023 23:51:45 +0200 Subject: [PATCH 09/11] Oops, forgot a conversion --- OpenUtau.Plugin.Builtin/ENDeltaPhonemizer.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/OpenUtau.Plugin.Builtin/ENDeltaPhonemizer.cs b/OpenUtau.Plugin.Builtin/ENDeltaPhonemizer.cs index 7b70eae23..84f66663d 100644 --- a/OpenUtau.Plugin.Builtin/ENDeltaPhonemizer.cs +++ b/OpenUtau.Plugin.Builtin/ENDeltaPhonemizer.cs @@ -34,7 +34,7 @@ public class ENDeltaPhonemizer : SyllableBasedPhonemizer { .ToDictionary(parts => parts[0], parts => parts[1]); // For banks aliased with VOCALOID-style phonemes - private readonly Dictionary vocaSampa = "A=Q;E=e;i=i:;u=u:;O=O:;3=@r".Split(';') + private readonly Dictionary vocaSampa = "A=Q;E=e;i=i:;u=u:;O=O:;3=@r;oU=@U".Split(';') .Select(entry => entry.Split('=')) .Where(parts => parts.Length == 2) .Where(parts => parts[0] != parts[1]) From 280a2a48c747a2c0817323a0fd644c1d3c9de48b Mon Sep 17 00:00:00 2001 From: Lotte V <61566058+lottev1991@users.noreply.github.com> Date: Mon, 7 Aug 2023 02:53:24 +0200 Subject: [PATCH 10/11] Base diphthong split on VC instead --- OpenUtau.Plugin.Builtin/ENDeltaPhonemizer.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/OpenUtau.Plugin.Builtin/ENDeltaPhonemizer.cs b/OpenUtau.Plugin.Builtin/ENDeltaPhonemizer.cs index 84f66663d..a555281f3 100644 --- a/OpenUtau.Plugin.Builtin/ENDeltaPhonemizer.cs +++ b/OpenUtau.Plugin.Builtin/ENDeltaPhonemizer.cs @@ -120,7 +120,7 @@ protected override string[] GetSymbols(Note note) { string[] diphthongs = new[] { "aI", "eI", "OI", "aU", "oU", "VI", "VU", "@U" }; string[] affricates = new[] { "dZ", "tS" }; foreach (string s in original) { - if (diphthongs.Contains(s) && !HasOto($"b{s}", note.tone)) { + if (diphthongs.Contains(s) && !HasOto($"{s} b", note.tone)) { modified.AddRange(new string[] { s[0].ToString(), s[1].ToString() }); } else if (affricates.Contains(s) && (!HasOto($"i {s}", note.tone) && !HasOto($"i: {s}", note.tone))) { modified.AddRange(new string[] { s[0].ToString(), s[1].ToString() }); From b8e46528455d37efec769fd32e6e9b21d9b0d327 Mon Sep 17 00:00:00 2001 From: Lotte V Date: Thu, 10 Aug 2023 19:46:45 +0200 Subject: [PATCH 11/11] Small fix --- OpenUtau.Plugin.Builtin/ENDeltaPhonemizer.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/OpenUtau.Plugin.Builtin/ENDeltaPhonemizer.cs b/OpenUtau.Plugin.Builtin/ENDeltaPhonemizer.cs index a555281f3..c8c8aba54 100644 --- a/OpenUtau.Plugin.Builtin/ENDeltaPhonemizer.cs +++ b/OpenUtau.Plugin.Builtin/ENDeltaPhonemizer.cs @@ -122,7 +122,7 @@ protected override string[] GetSymbols(Note note) { foreach (string s in original) { if (diphthongs.Contains(s) && !HasOto($"{s} b", note.tone)) { modified.AddRange(new string[] { s[0].ToString(), s[1].ToString() }); - } else if (affricates.Contains(s) && (!HasOto($"i {s}", note.tone) && !HasOto($"i: {s}", note.tone))) { + } else if (affricates.Contains(s) && !HasOto($"i {s}", note.tone) && !HasOto($"i: {s}", note.tone)) { modified.AddRange(new string[] { s[0].ToString(), s[1].ToString() }); } else { modified.Add(s);