Skip to content

Commit

Permalink
Diffsinger Ja phonemizer: support kana
Browse files Browse the repository at this point in the history
  • Loading branch information
wolfgitpr committed Sep 10, 2024
1 parent d541154 commit 2304b6d
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 29 deletions.
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;
}
}
}
1 change: 1 addition & 0 deletions OpenUtau.Core/OpenUtau.Core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
<ItemGroup>
<PackageReference Include="BunLabs.NAudio.Flac" Version="2.0.1" />
<PackageReference Include="Concentus.OggFile" Version="1.0.4" />
<PackageReference Include="csharp-kana" Version="1.0.1" />
<PackageReference Include="Ignore" Version="0.1.50" />
<PackageReference Include="IkG2p" Version="1.0.6" />
<PackageReference Include="K4os.Hash.xxHash" Version="1.0.8" />
Expand Down

0 comments on commit 2304b6d

Please sign in to comment.