Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
152 changes: 27 additions & 125 deletions OpenUtau.Plugin.Builtin/ArpasingPlusPhonemizer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1196,7 +1196,6 @@ protected override List<string> ProcessEnding(Ending ending) {
}
private string AliasFormat(string alias, string type, int tone, string prevV) {
var aliasFormats = new Dictionary<string, string[]> {
// Define alias formats for different types
{ "dynStart", new string[] { "" } },
{ "dynMid", new string[] { "" } },
{ "dynMid_vv", new string[] { "" } },
Expand All @@ -1217,12 +1216,10 @@ private string AliasFormat(string alias, string type, int tone, string prevV) {
{ "cc1_mix", new string[] { "", " -", "-", " R", "_", "- ", "-" } },
};

// Check if the given type exists in the aliasFormats dictionary
if (!aliasFormats.ContainsKey(type) && !type.Contains("dynamic")) {
return alias;
}

// Handle dynamic variations when type contains "dynamic"
if (type.Contains("dynStart")) {
string consonant = "";
string vowel = "";
Expand All @@ -1234,29 +1231,28 @@ private string AliasFormat(string alias, string type, int tone, string prevV) {
} else {
consonant = alias;
}

// Handle the alias with space and without space
var dynamicVariations = new List<string> {
// Variations with space, dash, and underscore
$"- {consonant}{vowel}", // "- CV"
$"- {consonant} {vowel}", // "- C V"
$"-{consonant} {vowel}", // "-C V"
$"-{consonant}{vowel}", // "-CV"
$"-{consonant}_{vowel}", // "-C_V"
$"- {consonant}_{vowel}", // "- C_V"
};
// Check each dynamically generated format

foreach (var variation in dynamicVariations) {
if (HasOto(variation, tone) || HasOto(ValidateAlias(variation), tone)) {
if (HasOto(variation, tone)) {
return variation;
} else if (HasOto(ValidateAlias(variation), tone)) {
return ValidateAlias(variation);
}
}
}

if (type.Contains("dynMid")) {
string consonant = "";
string vowel = "";
// If the alias contains a space, split it into consonant and vowel

if (alias.Contains(" ")) {
var parts = alias.Split(' ');
consonant = parts[0];
Expand All @@ -1269,18 +1265,20 @@ private string AliasFormat(string alias, string type, int tone, string prevV) {
$"{consonant} {vowel}", // "C V"
$"{consonant}_{vowel}", // "C_V"
};
// Check each dynamically generated format

foreach (var variation1 in dynamicVariations1) {
if (HasOto(variation1, tone) || HasOto(ValidateAlias(variation1), tone)) {
if (HasOto(variation1, tone)) {
return variation1;
} else if (HasOto(ValidateAlias(variation1), tone)) {
return ValidateAlias(variation1);
}
}
}

if (type.Contains("dynEnd")) {
string consonant = "";
string vowel = "";
// If the alias contains a space, split it into consonant and vowel

if (alias.Contains(" ")) {
var parts = alias.Split(' ');
consonant = parts[1];
Expand All @@ -1294,10 +1292,12 @@ private string AliasFormat(string alias, string type, int tone, string prevV) {
$"{vowel}{consonant}-", // "VC-"
$"{vowel} {consonant} -", // "V C -"
};
// Check each dynamically generated format

foreach (var variation1 in dynamicVariations1) {
if (HasOto(variation1, tone) || HasOto(ValidateAlias(variation1), tone)) {
if (HasOto(variation1, tone)) {
return variation1;
} else if (HasOto(ValidateAlias(variation1), tone)) {
return ValidateAlias(variation1);
}
}
}
Expand All @@ -1315,9 +1315,11 @@ private string AliasFormat(string alias, string type, int tone, string prevV) {
} else {
aliasFormat = $"{format}{alias}";
}
// Check if the formatted alias exists
if (HasOto(aliasFormat, tone) || HasOto(ValidateAlias(aliasFormat), tone)) {

if (HasOto(aliasFormat, tone)) {
return aliasFormat;
} else if (HasOto(ValidateAlias(aliasFormat), tone)) {
return ValidateAlias(aliasFormat);
}
}
return alias;
Expand Down Expand Up @@ -2034,123 +2036,23 @@ protected override string ValidateAlias(string alias) {
return base.ValidateAlias(alias);
}

bool PhonemeIsPresent(string alias, string phoneme) {
if (string.IsNullOrEmpty(alias) || string.IsNullOrEmpty(phoneme))
return false;

// Exact token match
if (alias == phoneme)
return true;

return alias.EndsWith(phoneme);
}

private bool PhonemeHasEndingSuffix(string alias, string phoneme) {
var escapedPhoneme = Regex.Escape(phoneme);
if (Regex.IsMatch(alias, $@"\b{escapedPhoneme}\b\s*-") ||
Regex.IsMatch(alias, $@"\b{escapedPhoneme}\b-")) {
return true;
}
if (Regex.IsMatch(alias, $@"\b{escapedPhoneme}\b R")) {
return true;
}
return false;
}

protected override double GetTransitionBasicLengthMs(string alias = "") {
//I wish these were automated instead :')
double transitionMultiplier = 1.0; // Default multiplier

var fricative_def = 2.3;
var aspirate_def = 1.3;
var semivowel_def = 1.2;
var liquid_def = 1.5;
var nasal_def = 1.5;
var stop_def = 1.8;
var tap_def = 0.5;
var affricate_def = 1.5;

var allConsonants = fricative.Concat(aspirate)
.Concat(semivowel)
.Concat(liquid)
.Concat(nasal)
.Concat(stop)
.Concat(tap)
.Concat(affricate)
.Distinct(); // Ensure no duplicates

foreach (var c in allConsonants) {
if (PhonemeHasEndingSuffix(alias, c)) {
return base.GetTransitionBasicLengthMs() * 0.5;
}
}

foreach (var v in vowels) {
if (alias.EndsWith("-")) {
return base.GetTransitionBasicLengthMs() * 0.5;
}
}
// Endings has 50 ticks gap
protected override bool NoGap => true;

// consonant timings
protected override double GetTransitionBasicLengthMs(string alias, int tone, PhonemeAttributes attr) {
double otoLength = GetTransitionBasicLengthMsByOto(alias, tone, attr);

var sortedOverrides = PhonemeOverrides.OrderByDescending(kv => kv.Key.Length);
foreach (var kvp in sortedOverrides) {
var overridePhoneme = kvp.Key;
var overrideValue = kvp.Value;
if (PhonemeIsPresent(alias, overridePhoneme)) {
return base.GetTransitionBasicLengthMs() * overrideValue;
}
}

foreach (var c in fricative) {
if (PhonemeIsPresent(alias, c)) {
return base.GetTransitionBasicLengthMs() * fricative_def;
}
}

foreach (var c in aspirate) {
if (PhonemeIsPresent(alias, c)) {
return base.GetTransitionBasicLengthMs() * aspirate_def;
}
}

foreach (var c in semivowel) {
if (PhonemeIsPresent(alias, c)) {
return base.GetTransitionBasicLengthMs() * semivowel_def;
}
}

foreach (var c in liquid) {
if (PhonemeIsPresent(alias, c)) {
return base.GetTransitionBasicLengthMs() * liquid_def;
}
}

foreach (var c in nasal) {
if (PhonemeIsPresent(alias, c)) {
return base.GetTransitionBasicLengthMs() * nasal_def;
}
}

foreach (var c in stop) {
if (PhonemeIsPresent(alias, c)) {
return base.GetTransitionBasicLengthMs() * stop_def;
}
}

foreach (var c in tap) {
if (PhonemeIsPresent(alias, c)) {
return base.GetTransitionBasicLengthMs() * tap_def;
}
}
var symbol = kvp.Key;
var value = kvp.Value;

foreach (var c in affricate) {
if (PhonemeIsPresent(alias, c)) {
return base.GetTransitionBasicLengthMs() * affricate_def;
if (alias.Contains(symbol)) {
return GetTransitionBasicLengthMsByConstant() * value;
}
}

return base.GetTransitionBasicLengthMs() * transitionMultiplier;
return otoLength;
}
}
}
8 changes: 8 additions & 0 deletions OpenUtau.Plugin.Builtin/ENtoJAPhonemizer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -460,5 +460,13 @@ private string ToHiragana(string romaji) {
hiragana = hiragana.Replace("ゔ", "ヴ");
return hiragana;
}

// Endings has 50 ticks gap
protected override bool NoGap => true;

protected override double GetTransitionBasicLengthMs(string alias, int tone, PhonemeAttributes attr) {
double otoLength = GetTransitionBasicLengthMsByOto(alias, tone, attr);
return otoLength;
}
}
}
9 changes: 9 additions & 0 deletions OpenUtau.Plugin.Builtin/EStoJAPhonemizer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -669,5 +669,14 @@ private string ToHiragana(string romaji) {
hiragana = hiragana.Replace("ゔ", "ヴ");
return hiragana;
}

// Endings has 50 ticks gap
protected override bool NoGap => true;

protected override double GetTransitionBasicLengthMs(string alias, int tone, PhonemeAttributes attr) {
double otoLength = GetTransitionBasicLengthMsByOto(alias, tone, attr);

return otoLength;
}
}
}
Loading
Loading