Skip to content

Commit

Permalink
Merge pull request #710 from maiko3tattun/0515_JAphonemizer
Browse files Browse the repository at this point in the history
[JA various phoemizers] PhoneticHint support and Unicode countermeasures
  • Loading branch information
stakira authored May 28, 2023
2 parents 447cba9 + 8007bac commit f02e295
Show file tree
Hide file tree
Showing 11 changed files with 201 additions and 126 deletions.
45 changes: 28 additions & 17 deletions OpenUtau.Plugin.Builtin/JapaneseCVVCPhonemizer.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.Collections.Generic;
using System.Linq;
using OpenUtau.Api;
Expand Down Expand Up @@ -107,7 +107,9 @@ private bool checkOtoUntilHit(string[] input, Note note, out UOto oto){
var attr1 = note.phonemeAttributes?.FirstOrDefault(attr => attr.index == 1) ?? default;

foreach (string test in input){
if (singer.TryGetMappedOto(test, note.tone + attr0.toneShift, attr0.voiceColor, out oto)){
if (singer.TryGetMappedOto(test + attr0.alternate, note.tone + attr0.toneShift, attr0.voiceColor, out oto)) {
return true;
} else if (singer.TryGetMappedOto(test, note.tone + attr0.toneShift, attr0.voiceColor, out oto)){
return true;
}
}
Expand All @@ -118,24 +120,36 @@ private bool checkOtoUntilHit(string[] input, Note note, out UOto oto){
// can probably be cleaned up more but i have work in the morning. have fun.
public override Result Process(Note[] notes, Note? prev, Note? next, Note? prevNeighbour, Note? nextNeighbour, Note[] prevNeighbours) {
var note = notes[0];
var currentUnicode = ToUnicodeElements(note.lyric);
var currentLyric = note.lyric;
var currentLyric = note.lyric.Normalize();
if (!string.IsNullOrEmpty(note.phoneticHint)) {
currentLyric = note.phoneticHint.Normalize();
}
var originalCurrentLyric = currentLyric;
var cfLyric = $"* {currentLyric}";
var attr0 = note.phonemeAttributes?.FirstOrDefault(attr => attr.index == 0) ?? default;
var attr1 = note.phonemeAttributes?.FirstOrDefault(attr => attr.index == 1) ?? default;

if (prevNeighbour == null) {
if (!string.IsNullOrEmpty(note.phoneticHint)) {
string[] tests = new string[] { currentLyric };
// Not convert VCV
if (checkOtoUntilHit(tests, note, out var oto)) {
currentLyric = oto.Alias;
}
} else if (prevNeighbour == null) {
// Use "- V" or "- CV" if present in voicebank
var initial = $"- {currentLyric}";
string[] tests = new string[] {initial, currentLyric};
string[] tests = new string[] { initial, currentLyric };
// try [- XX] before trying plain lyric
if (checkOtoUntilHit(tests, note, out var oto)){
if (checkOtoUntilHit(tests, note, out var oto)) {
currentLyric = oto.Alias;
}
} else if (plainVowels.Contains(currentLyric) || nonVowels.Contains(currentLyric)) {
var prevUnicode = ToUnicodeElements(prevNeighbour?.lyric);
var prevLyric = prevNeighbour.Value.lyric.Normalize();
if (!string.IsNullOrEmpty(prevNeighbour.Value.phoneticHint)) {
prevLyric = prevNeighbour.Value.phoneticHint.Normalize();
}
// Current note is VV
if (vowelLookup.TryGetValue(prevUnicode.LastOrDefault() ?? string.Empty, out var vow)) {
if (vowelLookup.TryGetValue(prevLyric.LastOrDefault().ToString() ?? string.Empty, out var vow)) {
var vowLyric = $"{vow} {currentLyric}";
// try vowlyric before cflyric, if both fail try currentlyric
string[] tests = new string[] {vowLyric, cfLyric, currentLyric};
Expand All @@ -150,13 +164,11 @@ public override Result Process(Note[] notes, Note? prev, Note? next, Note? prevN
}
}

if (nextNeighbour != null) {

var nextUnicode = ToUnicodeElements(nextNeighbour?.lyric);
var nextLyric = string.Join("", nextUnicode);
if (nextNeighbour != null && string.IsNullOrEmpty(nextNeighbour.Value.phoneticHint)) {
var nextLyric = nextNeighbour.Value.lyric.Normalize();

// Check if next note is a vowel and does not require VC
if (nextUnicode.Count < 2 && plainVowels.Contains(nextUnicode.FirstOrDefault() ?? string.Empty)) {
if (nextLyric.Length == 1 && plainVowels.Contains(nextLyric)) {
return new Result {
phonemes = new Phoneme[] {
new Phoneme() {
Expand All @@ -169,14 +181,13 @@ public override Result Process(Note[] notes, Note? prev, Note? next, Note? prevN
// Insert VC before next neighbor
// Get vowel from current note
var vowel = "";
if (vowelLookup.TryGetValue(currentUnicode.LastOrDefault() ?? string.Empty, out var vow)) {
if (vowelLookup.TryGetValue(originalCurrentLyric.LastOrDefault().ToString() ?? string.Empty, out var vow)) {
vowel = vow;
}

// Get consonant from next note
var consonant = "";
if (consonantLookup.TryGetValue(nextUnicode.FirstOrDefault() ?? string.Empty, out var con)
|| nextUnicode.Count >= 2 && consonantLookup.TryGetValue(string.Join("", nextUnicode.Take(2)), out con)) {
if (consonantLookup.TryGetValue(nextLyric.FirstOrDefault().ToString() ?? string.Empty, out var con) || (nextLyric.Length >= 2 && consonantLookup.TryGetValue(nextLyric.Substring(0, 2), out con))) {
consonant = con;
}

Expand Down
Loading

0 comments on commit f02e295

Please sign in to comment.