Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Thai VCCV Phonemizer] Fix phoneme parser for Thai VCCV #1297

Merged
merged 3 commits into from
Nov 11, 2024
Merged
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
39 changes: 22 additions & 17 deletions OpenUtau.Plugin.Builtin/ThaiVCCVPhonemizer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -211,52 +211,57 @@ public override Result Process(Note[] notes, Note? prev, Note? next, Note? prevN
}

(string Consonant, string Dipthong, string Vowel, string EndingConsonant) ParseInput(string input) {

input = WordToPhonemes(input);

string consonant = null;
string dipthong = null;
string diphthong = null;
string vowel = null;
string endingConsonant = null;

if (input == null) {
return (null, null, null, null);
}

if (input.Length >= 3) {
foreach (var dip in diphthongs) {
if (input[1].ToString().Equals(dip) || input[2].ToString().Equals(dip)) {
dipthong = dip;
}
}
}

foreach (var con in consonants) {
if (input.StartsWith(con)) {
if (consonant == null || consonant.Length < con.Length) {
consonant = con;
}
}
if (input.EndsWith(con)) {
if (endingConsonant == null || endingConsonant.Length < con.Length) {
endingConsonant = con;
}

int startIdx = consonant?.Length ?? 0;
foreach (var dip in diphthongs) {
if (input.Substring(startIdx).StartsWith(dip)) {
if (diphthong == null || diphthong.Length < dip.Length) {
diphthong = dip;
}
}
}

startIdx += diphthong?.Length ?? 0;
foreach (var vow in vowels) {
if (input.Contains(vow)) {
if (input.Substring(startIdx).StartsWith(vow)) {
if (vowel == null || vowel.Length < vow.Length) {
vowel = vow;
}
}
}

return (consonant, dipthong, vowel, endingConsonant);
foreach (var con in endingConsonants) {
if (input.EndsWith(con)) {
if (endingConsonant == null || endingConsonant.Length < con.Length) {
endingConsonant = con;
}
}
}

return (consonant, diphthong, vowel, endingConsonant);
}


public string WordToPhonemes(string input) {
input.Replace(" ", "");
input = input.Replace(" ", "");
input = RemoveInvalidLetters(input);
if (!Regex.IsMatch(input, "[ก-ฮ]")) {
return input;
Expand Down Expand Up @@ -295,7 +300,7 @@ public string WordToPhonemes(string input) {
return ConvertC(input.Substring(0, 2).ToString()) + "o" + ConvertX(input[1].ToString());
}
} else if (input.Length == 4) {
if (input[21] == 'ว') {
if (input[2] == 'ว') {
return ConvertC(input.Substring(0, 2).ToString()) + "ua" + ConvertX(input[3].ToString());
}
}
Expand Down
Loading