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

update chinese g2p #1276

Merged
merged 1 commit into from
Oct 27, 2024
Merged
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
9 changes: 4 additions & 5 deletions OpenUtau.Core/BaseChinesePhonemizer.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
using System.Collections.Generic;
using System.Linq;
using IKg2p;
using OpenUtau.Api;
using OpenUtau.Core.Ustx;
using Pinyin;

namespace OpenUtau.Core {
public abstract class BaseChinesePhonemizer : Phonemizer {
Expand All @@ -22,16 +22,15 @@ public static Note[] ChangeLyric(Note[] group, string lyric) {
public static string[] Romanize(IEnumerable<string> lyrics) {
var lyricsArray = lyrics.ToArray();
var hanziLyrics = lyricsArray
.Where(ZhG2p.MandarinInstance.IsHanzi)
.Where(Pinyin.Pinyin.Instance.IsHanzi)
.ToList();
List<G2pRes> g2pResults = ZhG2p.MandarinInstance.Convert(hanziLyrics.ToList(), false, false);
var pinyinResult = g2pResults.Select(res => res.syllable).ToArray();
var pinyinResult = Pinyin.Pinyin.Instance.HanziToPinyin(hanziLyrics, ManTone.Style.NORMAL, Pinyin.Error.Default, false, false, false).ToStrList();
if (pinyinResult == null) {
return lyricsArray;
}
var pinyinIndex = 0;
for (int i = 0; i < lyricsArray.Length; i++) {
if (lyricsArray[i].Length == 1 && ZhG2p.MandarinInstance.IsHanzi(lyricsArray[i])) {
if (lyricsArray[i].Length == 1 && Pinyin.Pinyin.Instance.IsHanzi(lyricsArray[i])) {
lyricsArray[i] = pinyinResult[pinyinIndex];
pinyinIndex++;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
using System.Collections.Generic;
using System.Linq;
using IKg2p;
using OpenUtau.Api;
using Pinyin;

namespace OpenUtau.Core.DiffSinger {
[Phonemizer("DiffSinger Jyutping Phonemizer", "DIFFS ZH-YUE", language: "ZH-YUE")]
public class DiffSingerJyutpingPhonemizer : DiffSingerBasePhonemizer {
protected override string GetDictionaryName() => "dsdict-zh-yue.yaml";
protected override string GetLangCode()=>"yue";
protected override string GetLangCode() => "yue";
protected override string[] Romanize(IEnumerable<string> lyrics) {
List<G2pRes> g2pResults = ZhG2p.CantoneseInstance.Convert(lyrics.ToList(), false, false);
return g2pResults.Select(res => res.syllable).ToArray();
return Pinyin.Jyutping.Instance.HanziToPinyin(lyrics.ToList(), CanTone.Style.NORMAL, Pinyin.Error.Default).Select(res => res.pinyin).ToArray();
}
}
}
2 changes: 1 addition & 1 deletion OpenUtau.Core/OpenUtau.Core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
<ItemGroup>
<PackageReference Include="BunLabs.NAudio.Flac" Version="2.0.1" />
<PackageReference Include="Concentus.OggFile" Version="1.0.4" />
<PackageReference Include="csharp-pinyin" Version="1.0.0" />
<PackageReference Include="Ignore" Version="0.1.50" />
<PackageReference Include="IkG2p" Version="1.0.6" />
<PackageReference Include="K4os.Hash.xxHash" Version="1.0.8" />
<PackageReference Include="Melanchall.DryWetMidi" Version="7.0.2" />
<PackageReference Include="NAudio.Core" Version="2.2.1" />
Expand Down
8 changes: 3 additions & 5 deletions OpenUtau.Core/Util/LyricsHelper.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
using System;
using System.Collections.Generic;
using System.Linq;
using IKg2p;
using OpenUtau.Api;
using OpenUtau.Core.G2p;
using Pinyin;

namespace OpenUtau.Core.Util {
public interface ILyricsHelper {
Expand Down Expand Up @@ -58,16 +58,14 @@ public string Convert(string text) {
public class PinyinLyricsHelper : ILyricsHelper {
public string Source => "汉->han";
public string Convert(string lyric) {
List<G2pRes> g2pResults = ZhG2p.MandarinInstance.Convert(lyric, false, true);
return g2pResults.Select(res => res.syllable).ToArray()[0];
return Pinyin.Pinyin.Instance.GetDefaultPinyin(lyric, ManTone.Style.NORMAL, false, false).ToArray()[0];
}
}

public class JyutpingLyricsHelper : ILyricsHelper {
public string Source => "粤->jyut";
public string Convert(string lyric) {
List<G2pRes> g2pResults = ZhG2p.CantoneseInstance.Convert(lyric, false, true);
return g2pResults.Select(res => res.syllable).ToArray()[0];
return Pinyin.Jyutping.Instance.GetDefaultPinyin(lyric, CanTone.Style.NORMAL).ToArray()[0];
}
}

Expand Down
5 changes: 2 additions & 3 deletions OpenUtau.Plugin.Builtin/CantoneseCVVCPhonemizer.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using System.Collections.Generic;
using System.Linq;
using IKg2p;
using OpenUtau.Api;
using Pinyin;

namespace OpenUtau.Plugin.Builtin {
/// <summary>
Expand All @@ -12,8 +12,7 @@ namespace OpenUtau.Plugin.Builtin {
[Phonemizer("Cantonese CVVC Phonemizer", "ZH-YUE CVVC", "Lotte V", language: "ZH-YUE")]
public class CantoneseCVVCPhonemizer : ChineseCVVCPhonemizer {
protected override string[] Romanize(IEnumerable<string> lyrics) {
List<G2pRes> g2pResults = ZhG2p.CantoneseInstance.Convert(lyrics.ToList(), false, false);
return g2pResults.Select(res => res.syllable).ToArray();
return Pinyin.Jyutping.Instance.HanziToPinyin(lyrics.ToList(), CanTone.Style.NORMAL, Pinyin.Error.Default).Select(res => res.pinyin).ToArray();
}
}
}
9 changes: 4 additions & 5 deletions OpenUtau.Plugin.Builtin/CantoneseSyoPhonemizer.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
using System.Collections.Generic;
using System.Linq;
using IKg2p;
using OpenUtau.Api;
using OpenUtau.Core.Ustx;
using Pinyin;

namespace OpenUtau.Plugin.Builtin {
/// <summary>
Expand Down Expand Up @@ -286,16 +286,15 @@ public static Note[] ChangeLyric(Note[] group, string lyric) {
public static string[] Romanize(IEnumerable<string> lyrics) {
var lyricsArray = lyrics.ToArray();
var hanziLyrics = lyricsArray
.Where(ZhG2p.CantoneseInstance.IsHanzi)
.Where(Pinyin.Jyutping.Instance.IsHanzi)
.ToList();
List<G2pRes> g2pResults = ZhG2p.CantoneseInstance.Convert(hanziLyrics.ToList(), false, false);
var jyutpingResult = g2pResults.Select(res => res.syllable).ToArray();
var jyutpingResult = Pinyin.Jyutping.Instance.HanziToPinyin(hanziLyrics, CanTone.Style.NORMAL, Pinyin.Error.Default).ToStrList();
if (jyutpingResult == null) {
return lyricsArray;
}
var jyutpingIndex = 0;
for (int i = 0; i < lyricsArray.Length; i++) {
if (lyricsArray[i].Length == 1 && ZhG2p.CantoneseInstance.IsHanzi(lyricsArray[i])) {
if (lyricsArray[i].Length == 1 && Pinyin.Jyutping.Instance.IsHanzi(lyricsArray[i])) {
lyricsArray[i] = jyutpingResult[jyutpingIndex];
jyutpingIndex++;
}
Expand Down
Loading