-
Notifications
You must be signed in to change notification settings - Fork 317
/
Copy pathPortugueseG2p.cs
48 lines (44 loc) · 1.85 KB
/
PortugueseG2p.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.ML.OnnxRuntime;
using OpenUtau.Api;
namespace OpenUtau.Core.G2p {
public class PortugueseG2p : G2pPack {
private static readonly string[] graphemes = new string[] {
"", "", "", "", "-", "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[] {
"", "", "", "", "E", "J", "L", "O", "R", "S", "X", "Z",
"a", "a~", "b", "d", "dZ", "e", "e~", "f", "g",
"i", "i~", "j", "j~", "k", "l", "m", "n", "o", "o~",
"p", "r", "s", "t", "tS", "u", "u~", "v", "w", "w~", "z",
};
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 PortugueseG2p() {
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_pt);
dict = tuple.Item1;
session = tuple.Item2;
}
}
GraphemeIndexes = graphemeIndexes;
Phonemes = phonemes;
Dict = dict;
Session = session;
PredCache = predCache;
}
}
}