Skip to content
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
22 changes: 22 additions & 0 deletions OpenUtau.Core/DiffSinger/Phonemizers/DiffSingerThaiPhonemizer.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
using OpenUtau.Api;
using OpenUtau.Core.G2p;

namespace OpenUtau.Core.DiffSinger
{
[Phonemizer("DiffSinger Thai Phonemizer", "DIFFS TH", language: "TH")]
public class DiffSingerThaiPhonemizer : DiffSingerG2pPhonemizer {
protected override string GetDictionaryName() => "dsdict-th.yaml";
public override string GetLangCode() => "th";
protected override IG2p LoadBaseG2p() => new ThaiG2p();
protected override string[] GetBaseG2pVowels() => new string[] {
"a", "i", "u", "e", "o", "A", "O", "E",
"Ua", "U", "ia", "ua", "I", "au"
};

protected override string[] GetBaseG2pConsonants() => new string[] {
"b", "ch", "d", "f", "h", "j", "k", "kk", "l", "m",
"n", "ng", "p", "pp", "r", "s", "t", "tt", "w", "W",
"y", "Y", "B", "D", "K"
};
}
}
10 changes: 10 additions & 0 deletions OpenUtau.Core/G2p/Data/Resources.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions OpenUtau.Core/G2p/Data/Resources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,9 @@
<data name="g2p-ru" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>g2p-ru.zip;System.Byte[], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</data>
<data name="g2p-th" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>g2p-th.zip;System.Byte[], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</data>
<data name="g2p_arpabet_plus" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>g2p-arpabet-plus.zip;System.Byte[], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</data>
Expand Down
Binary file added OpenUtau.Core/G2p/Data/g2p-th.zip
Binary file not shown.
51 changes: 51 additions & 0 deletions OpenUtau.Core/G2p/ThaiG2p.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.ML.OnnxRuntime;
using OpenUtau.Api;

namespace OpenUtau.Core.G2p {
public class ThaiG2p : G2pPack {
private static readonly string[] graphemes = new string[] {
"", "", "", "", "ก", "ข", "ฃ", "ค", "ฅ", "ฆ", "ง", "จ",
"ฉ", "ช", "ซ", "ฌ", "ญ", "ฎ", "ฏ", "ฐ", "ฑ", "ฒ", "ณ",
"ด", "ต", "ถ", "ท", "ธ", "น", "บ", "ป", "ผ", "ฝ", "พ", "ฟ",
"ภ", "ม", "ย", "ร", "ฤ", "ล", "ฦ", "ว", "ศ", "ษ", "ส", "ห",
"ฬ", "อ", "ฮ", "ฯ", "ะ", "ั", "า", "ำ", "ิ", "ี", "ึ", "ื",
"ุ", "ู", "ฺ", "฿", "เ", "แ", "โ", "ใ", "ไ", "ๅ", "ๆ", "็", "่",
"้", "๊", "๋", "์", "ํ", "๎",
};

private static readonly string[] phonemes = new string[] {
"", "", "", "", "a", "i", "u", "e", "o", "A", "O", "E",
"Ua", "U", "ia", "ua", "I", "au", "b", "ch", "d", "f", "h",
"j", "k", "kk", "l", "m", "n", "ng", "p", "pp", "r", "s", "t",
"tt", "w", "W", "y", "Y", "B", "D", "K",
};

private static object lockObj = new object();
private static Dictionary<string, int> graphemeIndexes;
private static IG2p dict;
private static InferenceSession session;
private static Dictionary<string, string[]> predCache = new Dictionary<string, string[]>();

public ThaiG2p() {
lock (lockObj) {
if (graphemeIndexes == null) {
graphemeIndexes = graphemes
.Skip(4)
.Select((g, i) => Tuple.Create(g, i))
.ToDictionary(t => t.Item1, t => t.Item2 + 4);
var tuple = LoadPack(Data.Resources.g2p_th);
dict = tuple.Item1;
session = tuple.Item2;
}
}
GraphemeIndexes = graphemeIndexes;
Phonemes = phonemes;
Dict = dict;
Session = session;
PredCache = predCache;
}
}
}
Loading