Skip to content

Commit

Permalink
Merge pull request #789 from lottev1991/German-for-OU
Browse files Browse the repository at this point in the history
[German for OU] Add German G2P, phonemizers, tests, custom dicts
  • Loading branch information
stakira authored Jul 28, 2023
2 parents 809d147 + d58f8dc commit 6f2ea1f
Show file tree
Hide file tree
Showing 29 changed files with 16,424 additions and 3 deletions.
12 changes: 11 additions & 1 deletion OpenUtau.Core/G2p/Data/Resources.Designer.cs

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

5 changes: 4 additions & 1 deletion OpenUtau.Core/G2p/Data/Resources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,9 @@
<data name="g2p-arpabet" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>g2p-arpabet.zip;System.Byte[], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</data>
<data name="g2p-de" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>g2p-de.zip;System.Byte[], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</data>
<data name="g2p-es" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>g2p-es.zip;System.Byte[], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</data>
Expand All @@ -136,4 +139,4 @@
<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>
</root>
</root>
Binary file added OpenUtau.Core/G2p/Data/g2p-de.zip
Binary file not shown.
51 changes: 51 additions & 0 deletions OpenUtau.Core/G2p/GermanG2p.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 GermanG2p : G2pPack {
private static readonly string[] graphemes = new string[] {
"", "", "", "", "2", "3", "/", "a", "b", "c", "d", "e",
"f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p",
"q", "r", "s", "t", "u", "v", "w", "x", "y", "z",
"ä", "ë", "ö", "ü", "ß", "ê", "î", "ô", "á", "é",
"í", "ú", "à", "è", "ù", "ę",
};

private static readonly string[] phonemes = new string[] {
"", "", "", "", "aa", "ae", "ah", "ao", "aw", "ax", "ay",
"b", "cc", "ch", "d", "dh", "ee", "eh", "er", "ex", "f",
"g", "hh", "ih", "iy", "jh", "k", "l", "m", "n", "ng",
"oe", "ohh", "ooh", "oy", "p", "pf", "q", "r", "rr", "s",
"sh", "t", "th", "ts", "ue", "uh", "uw", "v", "w", "x",
"y", "yy", "z", "zh",
};

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 GermanG2p() {
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_de);
dict = tuple.Item1;
session = tuple.Item2;
}
}
GraphemeIndexes = graphemeIndexes;
Phonemes = phonemes;
Dict = dict;
Session = session;
PredCache = predCache;
}
}
}
20 changes: 20 additions & 0 deletions OpenUtau.Plugin.Builtin/Data/Resources.Designer.cs

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

8 changes: 7 additions & 1 deletion OpenUtau.Plugin.Builtin/Data/Resources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -121,10 +121,16 @@
<data name="arpasing_template" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>arpasing.template.yaml;System.Byte[], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</data>
<data name="de_vccv_template" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>de_vccv.template.yaml;System.Byte[], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</data>
<data name="envccv_template" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>envccv.template.yaml;System.Byte[], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</data>
<data name="german_template" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>german.template.yaml;System.Byte[], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</data>
<data name="xsampa_template" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>xsampa.template.yaml;System.Byte[], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</data>
</root>
</root>
91 changes: 91 additions & 0 deletions OpenUtau.Plugin.Builtin/Data/de_vccv.template.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
%YAML 1.2
---
symbols:
#VCCV-style (X-SAMPA) symbols
- {symbol: a, type: vowel}
- {symbol: 6, type: vowel}
- {symbol: e, type: vowel}
- {symbol: E, type: vowel}
- {symbol: 2, type: vowel}
- {symbol: i, type: vowel}
- {symbol: I, type: vowel}
- {symbol: y, type: vowel}
- {symbol: Y, type: vowel}
- {symbol: u, type: vowel}
- {symbol: U, type: vowel}
- {symbol: o, type: vowel}
- {symbol: O, type: vowel}
- {symbol: '@', type: vowel}
- {symbol: aU, type: vowel}
- {symbol: OY, type: vowel}
- {symbol: aI, type: vowel}
- {symbol: C, type: fricative}
- {symbol: h, type: aspirate}
- {symbol: j, type: semivowel}
- {symbol: kh, type: stop}
- {symbol: N, type: nasal}
- {symbol: ph, type: stop}
- {symbol: R;, type: liquid}
- {symbol: S, type: fricative}
- {symbol: th, type: stop}
- {symbol: Z, type: fricative}
- {symbol: dZ, type: affricate}
- {symbol: ks, type: affricate}
- {symbol: st, type: fricative}
- {symbol: St, type: fricative}
- {symbol: tS, type: affricate}
#CMUSphinx symbols
- {symbol: aa, type: vowel}
- {symbol: ae, type: vowel}
- {symbol: ah, type: vowel}
- {symbol: ao, type: vowel}
- {symbol: aw, type: vowel}
- {symbol: ax, type: vowel}
- {symbol: ay, type: vowel}
- {symbol: b, type: stop}
- {symbol: cc, type: fricative}
- {symbol: ch, type: affricate}
- {symbol: d, type: stop}
- {symbol: dh, type: fricative}
- {symbol: ee, type: vowel}
- {symbol: eh, type: vowel}
- {symbol: er, type: vowel}
- {symbol: ex, type: vowel}
- {symbol: f, type: fricative}
- {symbol: g, type: stop}
- {symbol: hh, type: aspirate}
- {symbol: ih, type: vowel}
- {symbol: iy, type: vowel}
- {symbol: jh, type: affricate}
- {symbol: k, type: stop}
- {symbol: l, type: liquid}
- {symbol: m, type: nasal}
- {symbol: n, type: nasal}
- {symbol: ng, type: nasal}
- {symbol: oe, type: vowel}
- {symbol: ohh, type: vowel}
- {symbol: ooh, type: vowel}
- {symbol: oy, type: vowel}
- {symbol: p, type: stop}
- {symbol: pf, type: affricate}
- {symbol: q, type: glottal}
- {symbol: r, type: liquid}
- {symbol: rr, type: liquid}
- {symbol: s, type: fricative}
- {symbol: sh, type: fricative}
- {symbol: t, type: stop}
- {symbol: th, type: fricative}
- {symbol: ts, type: affricate}
- {symbol: ue, type: vowel}
- {symbol: uh, type: vowel}
- {symbol: uw, type: vowel}
- {symbol: v, type: fricative}
- {symbol: w, type: semivowel}
- {symbol: x, type: fricative}
- {symbol: y, type: semivowel}
- {symbol: yy, type: vowel}
- {symbol: z, type: fricative}
- {symbol: zh, type: fricative}
entries:
- grapheme: "openutau"
phonemes: [q, ooh, p, ax, n, q, uw, t, aw]
57 changes: 57 additions & 0 deletions OpenUtau.Plugin.Builtin/Data/german.template.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
%YAML 1.2
---
symbols:
- {symbol: aa, type: vowel}
- {symbol: ae, type: vowel}
- {symbol: ah, type: vowel}
- {symbol: ao, type: vowel}
- {symbol: aw, type: vowel}
- {symbol: ax, type: vowel}
- {symbol: ay, type: vowel}
- {symbol: b, type: stop}
- {symbol: cc, type: fricative}
- {symbol: ch, type: affricate}
- {symbol: d, type: stop}
- {symbol: dh, type: fricative}
- {symbol: ee, type: vowel}
- {symbol: eh, type: vowel}
- {symbol: er, type: vowel}
- {symbol: ex, type: vowel}
- {symbol: f, type: fricative}
- {symbol: g, type: stop}
- {symbol: hh, type: aspirate}
- {symbol: ih, type: vowel}
- {symbol: iy, type: vowel}
- {symbol: jh, type: affricate}
- {symbol: k, type: stop}
- {symbol: l, type: liquid}
- {symbol: m, type: nasal}
- {symbol: n, type: nasal}
- {symbol: ng, type: nasal}
- {symbol: oe, type: vowel}
- {symbol: ohh, type: vowel}
- {symbol: ooh, type: vowel}
- {symbol: oy, type: vowel}
- {symbol: p, type: stop}
- {symbol: pf, type: affricate}
- {symbol: q, type: glottal}
- {symbol: r, type: liquid}
- {symbol: rr, type: liquid}
- {symbol: s, type: fricative}
- {symbol: sh, type: fricative}
- {symbol: t, type: stop}
- {symbol: th, type: fricative}
- {symbol: ts, type: affricate}
- {symbol: ue, type: vowel}
- {symbol: uh, type: vowel}
- {symbol: uw, type: vowel}
- {symbol: v, type: fricative}
- {symbol: w, type: semivowel}
- {symbol: x, type: fricative}
- {symbol: y, type: semivowel}
- {symbol: yy, type: vowel}
- {symbol: z, type: fricative}
- {symbol: zh, type: fricative}
entries:
- grapheme: "openutau"
phonemes: [q, ooh, p, ax, n, q, uw, t, aw]
61 changes: 61 additions & 0 deletions OpenUtau.Plugin.Builtin/GermanDiphonePhonemizer.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using OpenUtau.Api;
using OpenUtau.Core.G2p;
using Serilog;

namespace OpenUtau.Plugin.Builtin {
/// <summary>
/// Simple German diphone phonemizer. Works similar to Arpasing.
/// You could make a combined English-German diphonic bank, and it will work.
/// Based on the German CMUSphinx dictionary, with some adjustments: https://sourceforge.net/projects/cmusphinx/files/Acoustic%20and%20Language%20Models/German/
/// </summary>
[Phonemizer("German Diphone Phonemizer", "DE DIPHONE", "Lotte V", language: "DE")]
public class GermanDiphonePhonemizer : LatinDiphonePhonemizer {

public GermanDiphonePhonemizer() {
try {
Initialize();
} catch (Exception e) {
Log.Error(e, "Failed to initialize.");
}
}

protected override IG2p LoadG2p() {
var g2ps = new List<IG2p>();

// Load dictionary from plugin folder.
string path = Path.Combine(PluginDir, "german.yaml");
if (!File.Exists(path)) {
Directory.CreateDirectory(PluginDir);
File.WriteAllBytes(path, Data.Resources.german_template);
}
g2ps.Add(G2pDictionary.NewBuilder().Load(File.ReadAllText(path)).Build());

// Load dictionary from singer folder.
if (singer != null && singer.Found && singer.Loaded) {
string file = Path.Combine(singer.Location, "german.yaml");
if (File.Exists(file)) {
try {
g2ps.Add(G2pDictionary.NewBuilder().Load(File.ReadAllText(file)).Build());
} catch (Exception e) {
Log.Error(e, $"Failed to load {file}");
}
}
}

// Load base g2p.
g2ps.Add(new GermanG2p());

return new G2pFallbacks(g2ps.ToArray());
}

protected override Dictionary<string, string[]> LoadVowelFallbacks() {
return "aa=ex;ex=aa;ah=ax,aa;ae=eh;eh=ae,ee;ee=eh;ao=ooh;ooh=ao;er=ex,ax;ih=iy;iy=ih;uh=uw;uw=uh;yy=ue;ue=yy;ohh=oe;oe=ohh;ax=eh;cc=x;x=cc;dh=z;jh=ch;r=rr;th=s;w=v;zh=sh".Split(';')
.Select(entry => entry.Split('='))
.ToDictionary(parts => parts[0], parts => parts[1].Split(','));
}
}
}
Loading

0 comments on commit 6f2ea1f

Please sign in to comment.