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

Diffsinger Ja phonemizer: support kana #1281

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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
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="csharp-pinyin" Version="1.0.0" />
<PackageReference Include="Ignore" Version="0.1.50" />
<PackageReference Include="K4os.Hash.xxHash" Version="1.0.8" />
Expand Down
Loading