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

[JA VCV] Support * あ #1149

Merged
merged 2 commits into from
Jun 9, 2024
Merged
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
7 changes: 2 additions & 5 deletions OpenUtau.Plugin.Builtin/JapaneseCVVCPhonemizer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,6 @@ static JapaneseCVVCPhonemizer() {
private bool checkOtoUntilHit(string[] input, Note note, out UOto oto) {
oto = default;
var attr = note.phonemeAttributes?.FirstOrDefault(attr => attr.index == 0) ?? default;
var attr1 = note.phonemeAttributes?.FirstOrDefault(attr => attr.index == 1) ?? default;

var otos = new List<UOto>();
foreach (string test in input) {
Expand All @@ -119,11 +118,9 @@ private bool checkOtoUntilHit(string[] input, Note note, out UOto oto) {
if (otos.Any(oto => (oto.Color ?? string.Empty) == color)) {
oto = otos.Find(oto => (oto.Color ?? string.Empty) == color);
return true;
} else if (otos.Any(oto => (color ?? string.Empty) == color)) {
oto = otos.Find(oto => (color ?? string.Empty) == color);
return true;
} else {
return false;
oto = otos.First();
return true;
}
}
return false;
Expand Down
79 changes: 43 additions & 36 deletions OpenUtau.Plugin.Builtin/JapaneseVCVPhonemizer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,40 +40,21 @@ public override Result Process(Note[] notes, Note? prev, Note? next, Note? prevN
var note = notes[0];
var currentLyric = note.lyric.Normalize(); //measures for Unicode

// Get color
string color = string.Empty;
int toneShift = 0;
int? alt = null;
if (note.phonemeAttributes != null) {
var attr = note.phonemeAttributes.FirstOrDefault(attr => attr.index == 0);
color = attr.voiceColor;
toneShift = attr.toneShift;
alt = attr.alternate;
}

if (!string.IsNullOrEmpty(note.phoneticHint)) {
// If a hint is present, returns the hint.
currentLyric = note.phoneticHint.Normalize();
if (singer.TryGetMappedOto(currentLyric + alt, note.tone + toneShift, color, out var phAlt)) {
return new Result {
phonemes = new Phoneme[] {
new Phoneme {
phoneme = phAlt.Alias,
}
},
};
} else if(singer.TryGetMappedOto(currentLyric, note.tone + toneShift, color, out var ph)){
if (CheckOtoUntilHit(new string[] { note.phoneticHint.Normalize() }, note, out var ph)) {
return new Result {
phonemes = new Phoneme[] {
new Phoneme {
phoneme = ph.Alias,
}
},
new Phoneme {
phoneme = ph.Alias,
}
},
};
}
}

// The alias for no previous neighbour note. For example, "- な" for "な".
var phoneme = $"- {currentLyric}";
string[] tests = new string[] { $"- {currentLyric}" , currentLyric};
if (prevNeighbour != null) {
// If there is a previous neighbour note, first get its hint or lyric.
var prevLyric = prevNeighbour.Value.lyric.Normalize();
Expand All @@ -85,25 +66,51 @@ public override Result Process(Note[] notes, Note? prev, Note? next, Note? prevN
// Look up the trailing vowel. For example "a" for "ゃ".
if (vowelLookup.TryGetValue(unicode.LastOrDefault() ?? string.Empty, out var vow)) {
// Now replace "- な" initially set to "a な".
phoneme = $"{vow} {currentLyric}";
tests = new string[] { $"{vow} {currentLyric}", $"* {currentLyric}", currentLyric, $"- {currentLyric}" };
}
}
if (singer.TryGetMappedOto(phoneme + alt, note.tone + toneShift, color, out var otoAlt)) {
phoneme = otoAlt.Alias;
} else if (singer.TryGetMappedOto(phoneme, note.tone + toneShift, color, out var oto)) {
phoneme = oto.Alias;
} else if (singer.TryGetMappedOto(currentLyric + alt, note.tone + toneShift, color, out oto)) {
phoneme = oto.Alias;
} else {
phoneme = currentLyric;
if (CheckOtoUntilHit(tests, note, out var oto)) {
return new Result {
phonemes = new Phoneme[] {
new Phoneme {
phoneme = oto.Alias,
}
},
};
}
return new Result {
phonemes = new Phoneme[] {
new Phoneme {
phoneme = phoneme,
phoneme = currentLyric,
}
},
};
}

private bool CheckOtoUntilHit(string[] input, Note note, out UOto oto) {
oto = default;
var attr = note.phonemeAttributes?.FirstOrDefault(attr => attr.index == 0) ?? default;
string color = attr.voiceColor ?? "";

var otos = new List<UOto>();
foreach (string test in input) {
if (singer.TryGetMappedOto(test + attr.alternate, note.tone + attr.toneShift, color, out var otoAlt)) {
otos.Add(otoAlt);
} else if (singer.TryGetMappedOto(test, note.tone + attr.toneShift, color, out var otoCandidacy)) {
otos.Add(otoCandidacy);
}
}

if (otos.Count > 0) {
if (otos.Any(oto => (oto.Color ?? string.Empty) == color)) {
oto = otos.Find(oto => (oto.Color ?? string.Empty) == color);
return true;
} else {
oto = otos.First();
return true;
}
}
return false;
}
}
}
Loading