diff --git a/OpenUtau.Core/DiffSinger/Phonemizers/DiffSingerJapanesePhonemizer.cs b/OpenUtau.Core/DiffSinger/Phonemizers/DiffSingerJapanesePhonemizer.cs index 72291c1c9..eadfe377a 100644 --- a/OpenUtau.Core/DiffSinger/Phonemizers/DiffSingerJapanesePhonemizer.cs +++ b/OpenUtau.Core/DiffSinger/Phonemizers/DiffSingerJapanesePhonemizer.cs @@ -1,41 +1,31 @@ -using System; -using System.Collections.Generic; +using System.Collections.Generic; using System.Linq; using OpenUtau.Api; -using OpenUtau.Core.G2p; namespace OpenUtau.Core.DiffSinger { [Phonemizer("DiffSinger Japanese Phonemizer", "DIFFS JA", language: "JA")] - public class DiffSingerJapanesePhonemizer : DiffSingerG2pPhonemizer { - protected override string GetDictionaryName()=>"dsdict-ja.yaml"; - protected override string GetLangCode()=>"ja"; - protected override IG2p LoadBaseG2p() => new JapaneseMonophoneG2p(); - protected override string[] GetBaseG2pVowels() => new string[] { - "A", "AP", "E", "I", "N", "O", "SP", "U", - "a", "e", "i", "o", "u" - }; + public class DiffSingerJapanesePhonemizer : DiffSingerBasePhonemizer { + protected override string GetDictionaryName() => "dsdict-ja.yaml"; - protected override string[] GetBaseG2pConsonants() => new string[] { - "b", "by", "ch", "cl", "d", "dy", "f", "g", "gw", "gy", "h", "hy", - "j", "k", "kw", "ky", "m", "my", "n", "ng", "ngy", "ny", "p", "py", - "r", "ry", "s", "sh", "t", "ts", "ty", "v", "w", "y", "z" - }; + protected override string GetLangCode() => "ja"; - public override Result Process(Note[] notes, Note? prev, Note? next, Note? prevNeighbour, Note? nextNeighbour, Note[] prevs) { - if (notes[0].lyric == "-") { - return MakeSimpleResult("SP"); + protected override string[] Romanize(IEnumerable lyrics) { + var lyricsArray = lyrics.ToArray(); + var kanaLyrics = lyricsArray + .Where(Kana.Kana.IsKana) + .ToList(); + var kanaResult = Kana.Kana.KanaToRomaji(kanaLyrics.ToList(), Kana.Error.Default, false).ToStrList(); + if (kanaResult == null) { + return lyricsArray; } - if (!partResult.TryGetValue(notes[0].position, out var phonemes)) { - throw new Exception("Part result not found"); + var kanaIndex = 0; + for (int i = 0; i < lyricsArray.Length; i++) { + if (Kana.Kana.IsKana(lyricsArray[i])) { + lyricsArray[i] = kanaResult[kanaIndex]; + kanaIndex++; + } } - return new Result { - phonemes = phonemes - .Select((tu) => new Phoneme() { - phoneme = tu.Item1, - position = tu.Item2, - }) - .ToArray(), - }; + return lyricsArray; } } } diff --git a/OpenUtau.Core/OpenUtau.Core.csproj b/OpenUtau.Core/OpenUtau.Core.csproj index 1df8a039b..13591fd51 100644 --- a/OpenUtau.Core/OpenUtau.Core.csproj +++ b/OpenUtau.Core/OpenUtau.Core.csproj @@ -10,6 +10,7 @@ +