-
Notifications
You must be signed in to change notification settings - Fork 311
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Diffsinger Ja phonemizer: support kana
- Loading branch information
Showing
2 changed files
with
20 additions
and
29 deletions.
There are no files selected for viewing
48 changes: 19 additions & 29 deletions
48
OpenUtau.Core/DiffSinger/Phonemizers/DiffSingerJapanesePhonemizer.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<string> 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; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters