-
Notifications
You must be signed in to change notification settings - Fork 288
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #789 from lottev1991/German-for-OU
[German for OU] Add German G2P, phonemizers, tests, custom dicts
- Loading branch information
Showing
29 changed files
with
16,424 additions
and
3 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(',')); | ||
} | ||
} | ||
} |
Oops, something went wrong.