Skip to content

Commit 8ba9429

Browse files
committed
revamped themes to be a single hue slider
1 parent a72e8b6 commit 8ba9429

File tree

124 files changed

+3177
-25275
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

124 files changed

+3177
-25275
lines changed

OU Dictionary Editor/Assets/G2p/g2p-de-marzipan/dict.txt

Lines changed: 2723 additions & 0 deletions
Large diffs are not rendered by default.
1.7 MB
Binary file not shown.
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
a vowel
2+
o vowel
3+
au vowel
4+
ex vowel
5+
ei vowel
6+
b stop
7+
ch fricative
8+
tsh affricate
9+
d stop
10+
eh vowel
11+
e vowel
12+
er vowel
13+
f fricative
14+
g stop
15+
h fricative
16+
i vowel
17+
ih vowel
18+
dsh affricate
19+
k stop
20+
l liquid
21+
m nasal
22+
n nasal
23+
ng nasal
24+
oe vowel
25+
oeh vowel
26+
oh vowel
27+
eu vowel
28+
p stop
29+
pf affricate
30+
q stop
31+
rh liquid
32+
r liquid
33+
s fricative
34+
sh fricative
35+
t stop
36+
th1 fricative
37+
ts affricate
38+
ueh vowel
39+
e vowel
40+
u vowel
41+
uh vowel
42+
v fricative
43+
w semivowel
44+
xh fricative
45+
j semivowel
46+
ue vowel
47+
z fricative
48+
dh fricative
Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
import onnxruntime as ort
2+
import numpy as np
3+
from collections import defaultdict
4+
import traceback
5+
import sys
6+
sys.path.append('.')
7+
from pathlib import Path as P
8+
9+
class MarzipanG2p:
10+
graphemes = ["", "", "", "", "a", "b", "c", "d", "e", "f", "g", "h",
11+
"i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s",
12+
"t", "u", "v", "w", "x", "y", "z", "ä", "ë", "ö", "ü", "ß"]
13+
14+
phonemes = ["", "", "", "", "a", "er", "eh", "e", "ih", "i", "uh",
15+
"u", "oh", "o", "ueh", "ue", "oeh", "oe", "ex", "ei", "au",
16+
"eu", "w", "j", "p", "t", "k", "f", "s", "sh", "ch",
17+
"xh", "h", "pf", "ts", "tsh", "th", "m", "n", "ng", "b",
18+
"d", "g", "v", "z", "l", "r", "dsh", "zh", "rh", "rr",
19+
"rx", "dh", "q", "vf", "cl"]
20+
21+
def __init__(self):
22+
self.lock = None # Placeholder for thread safety if needed
23+
self.dict = {}
24+
self.grapheme_indexes = {}
25+
self.pred_cache = defaultdict(list)
26+
self.session = None
27+
self.phonemes = self.phonemes[4:]
28+
self.load_pack()
29+
30+
def load_pack(self):
31+
dict_path = P('./Assets/G2p/g2p-de-marzipan/dict.txt')
32+
with open(dict_path, 'r', encoding='utf-8') as f:
33+
for line in f:
34+
parts = line.strip().split(' ')
35+
if len(parts) >= 2:
36+
grapheme = parts[0].lower()
37+
phoneme_parts = parts[1:]
38+
phonemes = ''.join(phoneme_parts)
39+
self.dict[grapheme] = phonemes.split()
40+
else:
41+
print(f"Ignoring line: {line.strip()}")
42+
43+
# Create grapheme indexes (skip the first four graphemes)
44+
self.grapheme_indexes = {g: i + 4 for i, g in enumerate(self.graphemes[4:])}
45+
46+
onnx_path = P('./Assets/G2p/g2p-de-marzipan/g2p.onnx')
47+
self.session = ort.InferenceSession(onnx_path)
48+
49+
def predict(self, input_text):
50+
words = input_text.strip().split()
51+
predicted_phonemes = []
52+
for word in words:
53+
word_lower = word.lower()
54+
if word_lower in self.dict:
55+
predicted_phonemes.append(' '.join(self.dict[word_lower]))
56+
else:
57+
cached_phoneme = self.pred_cache.get(word_lower)
58+
if cached_phoneme:
59+
predicted_phonemes.append(' '.join(cached_phoneme))
60+
else:
61+
predicted_phoneme = self.predict_with_model(word)
62+
self.pred_cache[word_lower] = predicted_phoneme.split()
63+
predicted_phonemes.append(predicted_phoneme)
64+
return ' '.join(predicted_phonemes)
65+
66+
def predict_with_model(self, word):
67+
# Encode input word as indices of graphemes
68+
word_with_dash = "-" + word # funny workaround for that first skipped phoneme
69+
70+
input_ids = np.array([self.grapheme_indexes.get(c, 0) for c in word_with_dash], dtype=np.int32) # equvilant to `Tensor<int> src = EncodeWord(grapheme);`
71+
input_length = len(input_ids)
72+
73+
if len(input_ids.shape) == 1:
74+
input_ids = np.expand_dims(input_ids, axis=0)
75+
76+
t = np.ones((1,), dtype=np.int32)
77+
78+
src = input_ids
79+
tgt = np.array([2, ], dtype=np.int32)
80+
if len(tgt.shape) == 1:
81+
tgt = np.expand_dims(tgt, axis=0)
82+
print(tgt)
83+
84+
try:
85+
while t[0] < input_length and len(tgt) < 48:
86+
input_feed = {'src': src, 'tgt': tgt, 't': t}
87+
88+
outputs = self.session.run(['pred'], input_feed)
89+
pred = outputs[0].flatten().astype(int)
90+
if pred != 2:
91+
new_tgt_shape = (tgt.shape[0], tgt.shape[1] + 1)
92+
93+
new_tgt = np.zeros(new_tgt_shape, dtype=np.int32)
94+
95+
for i in range(tgt.shape[1]):
96+
new_tgt[:, i] = tgt[:, i]
97+
98+
new_tgt[:, tgt.shape[1]] = pred
99+
print(pred - 4)
100+
101+
tgt = new_tgt
102+
else:
103+
t[0] += 1
104+
105+
# these lines are equivalent to `var phonemes = DecodePhonemes(tgt.Skip(1).ToArray());`
106+
predicted_phonemes = []
107+
for id in tgt.flatten().astype(int):
108+
if id != 2: # skip the first phone (workaround) cuz of the np.array initial phoneme
109+
predicted_phonemes.append(self.phonemes[id - 4])
110+
111+
print(predicted_phonemes)
112+
113+
predicted_phonemes_str = ' '.join(predicted_phonemes)
114+
return predicted_phonemes_str
115+
except Exception as e:
116+
117+
print("Error in prediction", traceback.format_exc())

OU Dictionary Editor/Assets/modules/sv_ttk/sv.tcl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package require Tk 8.6
22

33
# Source theme files in a loop for efficiency and maintainability
4-
set themes [list light dark amaranth_dark amaranth_light amethyst_dark amethyst_light burnt-sienna_dark burnt-sienna_light dandelion_dark dandelion_light denim_dark denim_light fern_dark fern_light lemon-ginger_dark lemon-ginger_light lightning-yellow_dark lightning-yellow_light mint_dark mint_light orange_dark orange_light pear_dark pear_light persian-red_dark persian-red_light pink_dark pink_light salmon_dark salmon_light sapphire_dark sapphire_light sea-green_dark sea-green_light seance_dark seance_light sunny-yellow_light sunny-yellow_dark yellow-green_light yellow-green_dark payne's-gray_light payne's-gray_dark sky-magenta_light sky-magenta_dark l-see-green_light l-see-green_dark]
4+
set themes [list light dark mint_light mint_dark]
55
foreach theme $themes {
66
source [file join [file dirname [info script]] theme $theme.tcl]
77
}

0 commit comments

Comments
 (0)