gapiring 0.1.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (39) hide show
  1. gapiring/__init__.py +100 -0
  2. gapiring/__main__.py +3 -0
  3. gapiring/cli.py +41 -0
  4. gapiring/engine.py +199 -0
  5. gapiring/frontend/__init__.py +0 -0
  6. gapiring/frontend/common.py +16 -0
  7. gapiring/frontend/lexicon_extra.tsv +6 -0
  8. gapiring/frontend/tashkent_dialect.py +222 -0
  9. gapiring/frontend/terms.py +58 -0
  10. gapiring/frontend/terms_reviewed.json +4618 -0
  11. gapiring/frontend/terms_uz.py +71 -0
  12. gapiring/frontend/text_to_phoneme/__init__.py +0 -0
  13. gapiring/frontend/text_to_phoneme/phoneme_converter.py +329 -0
  14. gapiring/frontend/text_to_phoneme/pipelene_text_to_phoneme.py +55 -0
  15. gapiring/frontend/text_to_phoneme/text_normalization_for_tts.py +208 -0
  16. gapiring/frontend/text_to_phoneme/tools/__init__.py +0 -0
  17. gapiring/frontend/text_to_phoneme/tools/convert_currency_to_text.py +76 -0
  18. gapiring/frontend/text_to_phoneme/tools/convert_date_time_to_text.py +371 -0
  19. gapiring/frontend/text_to_phoneme/tools/convert_non_roman_numbers_to_text.py +609 -0
  20. gapiring/frontend/text_to_phoneme/tools/convert_phone_numbers_to_text.py +268 -0
  21. gapiring/frontend/text_to_phoneme/tools/convert_roman_numerals_to_text.py +235 -0
  22. gapiring/frontend/text_to_phoneme/tools/convert_symbols_to_uzbek_text.py +258 -0
  23. gapiring/frontend/text_to_phoneme/tools/expand_uzbek_abbreviations.py +293 -0
  24. gapiring/frontend/text_to_phoneme/tools/full_normalize.py +257 -0
  25. gapiring/frontend/text_to_phoneme/tools/pronounce_links_and_emails.py +99 -0
  26. gapiring/frontend/text_to_phoneme/tools/split_text_numbers.py +36 -0
  27. gapiring/frontend/text_to_phoneme/tools/spoken_lexicon.py +40 -0
  28. gapiring/frontend/text_to_phoneme/tools/spoken_prepass.py +116 -0
  29. gapiring/frontend/text_to_phoneme/uzbek_orthography.py +24 -0
  30. gapiring/frontend/textnorm.py +172 -0
  31. gapiring/frontend/tts_frontend.py +344 -0
  32. gapiring/lexicon.py +188 -0
  33. gapiring/text_front.py +77 -0
  34. gapiring-0.1.0.dist-info/METADATA +69 -0
  35. gapiring-0.1.0.dist-info/RECORD +39 -0
  36. gapiring-0.1.0.dist-info/WHEEL +5 -0
  37. gapiring-0.1.0.dist-info/entry_points.txt +2 -0
  38. gapiring-0.1.0.dist-info/licenses/LICENSE +4 -0
  39. gapiring-0.1.0.dist-info/top_level.txt +1 -0
@@ -0,0 +1,71 @@
1
+
2
+ from __future__ import annotations
3
+
4
+ import json
5
+ import re
6
+ import sys
7
+ import threading
8
+ from pathlib import Path
9
+
10
+ from gapiring.frontend.terms import LEXICON as BASE_LEXICON
11
+
12
+ REVIEWED_LEXICON = Path(__file__).resolve().parent / "terms_reviewed.json"
13
+ BRACE = re.compile(r"\{([^{}]{1,40})\}")
14
+ LIST_TERMS = {
15
+ "Bluetooth": "Blutuz", "USB": "yu-es-bi", "GPS": "ji-pi-es", "VPN": "vi-pi-en", "PIN": "pin", "IP": "ay-pi",
16
+ "URL": "yu-ar-el", "API": "ey-pi-ay", "ChatGPT": "Chat-ji-pi-ti", "GPT": "ji-pi-ti", "Telegram": "Telegram",
17
+ "Instagram": "Instagram", "Facebook": "Feysbuk", "TikTok": "Tik-tok", "Android": "Android", "iOS": "ay-o-es",
18
+ "Windows": "Vindovs", "Excel": "Eksel", "Word": "Vord", "PowerPoint": "Pauerpoint", "Gmail": "Jimeyl",
19
+ "email": "imeyl", "e-mail": "imeyl", "Yandex": "Yandeks", "Yandex Go": "Yandeks Go", "Uzum": "Uzum",
20
+ "Humo": "Humo", "Uzcard": "Uzkard", "Visa": "Viza", "Mastercard": "Masterkard", "SIM": "sim", "4G": "to'rt-ji",
21
+ "5G": "besh-ji", "LTE": "el-te-e", "HDMI": "eych-di-em-ay", "SSD": "es-es-di", "RAM": "ram", "CPU": "si-pi-yu",
22
+ "TV": "ti-vi", "Smart TV": "Smart ti-vi", "Netflix": "Netfliks", "Spotify": "Spotifay", "Python": "Payton",
23
+ "HTML": "eych-ti-em-el", "JavaScript": "Javaskript", "Samsung": "Samsung", "Xiaomi": "Shaomi", "Apple": "Epl",
24
+ "MacBook": "Makbuk", "AirPods": "Eyrpods", "Duolingo": "Duolingo", "Canva": "Kanva", "Google Drive": "Gugl Drayv",
25
+ "Google Maps": "Gugl Meps", "iCloud": "Ayklaud", "OTP": "o-ti-pi", "SMS-kod": "es-em-es kod", "Wi-Fi": "vay-fay",
26
+ "QR": "kyu-ar", "PDF": "pe-de-ef", "ID": "ay-di",
27
+ }
28
+ _LOCK = threading.Lock()
29
+
30
+
31
+ def lexicon() -> dict[str, str]:
32
+ table = {k: v[0] for k, v in BASE_LEXICON.items()}
33
+ table.update(LIST_TERMS)
34
+ return table
35
+
36
+
37
+ def _llm_table() -> dict:
38
+ return json.loads(REVIEWED_LEXICON.read_text()) if REVIEWED_LEXICON.exists() else {}
39
+
40
+
41
+ def spoken(text: str, proposed: dict[str, str], context: str = "") -> tuple[str, list[dict]]:
42
+ known = lexicon()
43
+ folded = {k.lower(): v for k, v in known.items()}
44
+ found = []
45
+
46
+ def sub(m):
47
+ term = m.group(1).strip()
48
+ if term.lower() in folded:
49
+ reading, source = folded[term.lower()], "lexicon"
50
+ else:
51
+ reading = (proposed.get(term) or proposed.get(term.lower()) or "").strip()
52
+ if not reading or re.search(r"[^A-Za-z' \-]", reading):
53
+ raise ValueError(f"no usable reading for term {term!r}: {reading!r}")
54
+ source = "llm"
55
+ key = term.lower()
56
+ with _LOCK:
57
+ table = _llm_table()
58
+ if key not in table:
59
+ table[key] = {"term": term, "reading": reading, "first_context": context[:160], "count": 0}
60
+ table[key]["count"] += 1
61
+ REVIEWED_LEXICON.parent.mkdir(parents=True, exist_ok=True)
62
+ REVIEWED_LEXICON.write_text(json.dumps(table, ensure_ascii=False, indent=1) + "\n")
63
+ reading = table[key]["reading"]
64
+ found.append({"term": term, "reading": reading, "source": source})
65
+ return reading
66
+
67
+ return BRACE.sub(sub, text), found
68
+
69
+
70
+ def original(text: str) -> str:
71
+ return BRACE.sub(lambda m: m.group(1), text)
File without changes
@@ -0,0 +1,329 @@
1
+ import re
2
+
3
+ from gapiring.frontend.text_to_phoneme.uzbek_orthography import normalize_uzbek_apostrophes
4
+
5
+ IPA_VOWELS_SET = {"a", "ɔ", "e", "i", "u", "ɵ", "ɨ", "ɪ", "ʊ"}
6
+ IPA_VOICELESS_CONSONANTS_SET = {"p", "t", "k", "q", "χ", "f", "s", "ʃ", "t͡ʃ", "h", "ʔ"}
7
+ IPA_VOICED_CONSONANTS_SET = {"b", "d", "ɡ", "ʁ", "v", "z", "ʒ", "d͡ʒ"}
8
+ IPA_SONORANTS_SET = {"m", "n", "ŋ", "ɱ", "l", "r", "j"}
9
+ IPA_ALL_CONSONANTS_SET = IPA_VOICELESS_CONSONANTS_SET.union(IPA_VOICED_CONSONANTS_SET).union(IPA_SONORANTS_SET)
10
+ IPA_VOICELESS_STOPS_SET = {"p", "t", "k", "q"}
11
+ IPA_BACK_CONSONANTS_SET = {"q", "ʁ", "χ"}
12
+ IPA_THROAT_CONSONANTS_SET = {"ʔ", "h"}
13
+ IPA_DEEP_BACK_OR_THROAT_CONSONANTS_SET = IPA_BACK_CONSONANTS_SET.union(IPA_THROAT_CONSONANTS_SET)
14
+
15
+ CMU_VOWELS_SET = {
16
+ "AA", "AE", "AH", "AO", "AW", "AY", "EH", "ER", "EY",
17
+ "IH", "IY", "OW", "OY", "UH", "UW",
18
+ }
19
+ UZBEK_CMU_VOWELS_SET = CMU_VOWELS_SET.union({"IX", "OE"})
20
+
21
+ IPA_TO_STRICT_CMU_MAP = {
22
+ "a": ("AA",),
23
+ "ɔ": ("AO",),
24
+ "e": ("EH",),
25
+ "i": ("IY",),
26
+ "u": ("UW",),
27
+ "ɵ": ("AH",),
28
+ "ɨ": ("IH",),
29
+ "ɪ": ("IH",),
30
+ "ʊ": ("UH",),
31
+ "p": ("P",),
32
+ "b": ("B",),
33
+ "t": ("T",),
34
+ "d": ("D",),
35
+ "k": ("K",),
36
+ "ɡ": ("G",),
37
+ "q": ("K",),
38
+ "χ": ("HH",),
39
+ "ʁ": ("G",),
40
+ "f": ("F",),
41
+ "v": ("V",),
42
+ "s": ("S",),
43
+ "z": ("Z",),
44
+ "ʃ": ("SH",),
45
+ "ʒ": ("ZH",),
46
+ "h": ("HH",),
47
+ "t͡ʃ": ("CH",),
48
+ "d͡ʒ": ("JH",),
49
+ "m": ("M",),
50
+ "n": ("N",),
51
+ "ŋ": ("NG",),
52
+ "ŋɡ": ("NG", "G"),
53
+ "ɱ": ("M",),
54
+ "l": ("L",),
55
+ "r": ("R",),
56
+ "j": ("Y",),
57
+ "ʔ": (),
58
+ }
59
+
60
+ IPA_TO_UZBEK_CMU_MAP = {
61
+ **IPA_TO_STRICT_CMU_MAP,
62
+ "ɵ": ("OE",),
63
+ "ɨ": ("IX",),
64
+ "q": ("Q",),
65
+ "χ": ("X",),
66
+ "ʁ": ("GH",),
67
+ "ʔ": ("GL",),
68
+ }
69
+
70
+
71
+ def parse_ipa_string(ipa_str: str) -> list[str]:
72
+ known_multichar_ipa_units = sorted(
73
+ ["ɵ", "t͡ʃ", "d͡ʒ", "ŋɡ", "ʒ", "ʃ", "χ", "ʁ", "ʔ", "ŋ", "ɱ", "ɪ"],
74
+ key=len, reverse=True
75
+ )
76
+ temp_str = ipa_str
77
+ parsed_list = []
78
+ idx = 0
79
+ while idx < len(temp_str):
80
+ if temp_str[idx] == 'ˈ':
81
+ parsed_list.append('ˈ')
82
+ idx += 1
83
+ continue
84
+ found_multi = False
85
+ for mc_unit in known_multichar_ipa_units:
86
+ if temp_str.startswith(mc_unit, idx):
87
+ parsed_list.append(mc_unit)
88
+ idx += len(mc_unit)
89
+ found_multi = True
90
+ break
91
+ if not found_multi:
92
+ parsed_list.append(temp_str[idx])
93
+ idx += 1
94
+ return parsed_list
95
+
96
+
97
+ def ipa_to_cmu(ipa_str: str, include_stress: bool = True, strict: bool = False) -> str:
98
+ ipa_symbols = parse_ipa_string(ipa_str)
99
+ ipa_to_cmu_map = IPA_TO_STRICT_CMU_MAP if strict else IPA_TO_UZBEK_CMU_MAP
100
+ cmu_vowels = CMU_VOWELS_SET if strict else UZBEK_CMU_VOWELS_SET
101
+ cmu_symbols = []
102
+ stress_next_vowel = False
103
+
104
+ for ipa_sym in ipa_symbols:
105
+ if ipa_sym == "ˈ":
106
+ stress_next_vowel = True
107
+ continue
108
+
109
+ if ipa_sym in {" ", "\t", "\n"}:
110
+ continue
111
+
112
+ cmu_phones = ipa_to_cmu_map.get(ipa_sym)
113
+ if cmu_phones is None:
114
+ raise ValueError(f"Unsupported IPA symbol for CMU export: {ipa_sym!r}")
115
+
116
+ for cmu_phone in cmu_phones:
117
+ if include_stress and cmu_phone in cmu_vowels:
118
+ stress = "1" if stress_next_vowel else "0"
119
+ cmu_symbols.append(f"{cmu_phone}{stress}")
120
+ stress_next_vowel = False
121
+ else:
122
+ cmu_symbols.append(cmu_phone)
123
+
124
+ return " ".join(cmu_symbols)
125
+
126
+
127
+ def uzbek_to_cmu_final(text: str, include_stress: bool = True, strict: bool = False) -> str:
128
+ return ipa_to_cmu(uzbek_to_ipa_final(text), include_stress=include_stress, strict=strict)
129
+
130
+
131
+ def uzbek_to_cmu_strict_final(text: str, include_stress: bool = True) -> str:
132
+ return uzbek_to_cmu_final(text, include_stress=include_stress, strict=True)
133
+
134
+
135
+ def uzbek_to_ipa_final(text: str) -> str:
136
+ text_lower = normalize_uzbek_apostrophes(text).lower()
137
+
138
+ processed_text = text_lower.replace("o'", "ɵ")
139
+ processed_text = processed_text.replace("g'", "ʁ")
140
+
141
+ processed_text = re.sub(r"ng(?=[aeiouɵaɔeiɨʊɪ])", "ŋɡ", processed_text)
142
+ processed_text = processed_text.replace("ng", "ŋ")
143
+ processed_text = processed_text.replace("s'h", "s\x00h")
144
+ processed_text = processed_text.replace("sh", "ʃ")
145
+ processed_text = processed_text.replace("ch", "t͡ʃ")
146
+ processed_text = processed_text.replace("zh", "ʒ")
147
+ processed_text = processed_text.replace("\x00", "")
148
+ processed_text = processed_text.replace("ck", "k")
149
+ processed_text = re.sub(r"c(?=[eiy])", "s", processed_text)
150
+ processed_text = processed_text.replace("c", "k").replace("w", "v")
151
+ processed_text = processed_text.replace("'", "ʔ")
152
+
153
+ char_map = {
154
+ 'a': "a", 'b': "b", 'd': "d", 'e': "e", 'f': "f", 'g': "ɡ",
155
+ 'h': "h", 'i': "i", 'j': "d͡ʒ", 'k': "k", 'l': "l", 'm': "m",
156
+ 'n': "n", 'o': "ɔ", 'p': "p", 'q': "q", 'r': "r", 's': "s",
157
+ 't': "t", 'u': "u", 'v': "v", 'x': "χ", 'y': "j", 'z': "z",
158
+ }
159
+ ipa_result_chars = [char_map.get(char_uzb, char_uzb) for char_uzb in processed_text]
160
+ current_ipa_str = "".join(ipa_result_chars)
161
+
162
+ ipa_symbols = parse_ipa_string(current_ipa_str)
163
+
164
+ vowel_indices_in_symbols = [
165
+ idx for idx, sym in enumerate(ipa_symbols) if sym in IPA_VOWELS_SET and sym != 'ˈ'
166
+ ]
167
+ stressed_vowel_symbol_index = -1
168
+
169
+ no_stress_suffixes_approx = [
170
+ "mi", "chi", "ku", "cha", "mas", "dir", "oq", "yoq",
171
+ "gina", "kina", "qina", "u", "yu", "la",
172
+ "ga", "da", "dan", "ning", "ni"
173
+ ]
174
+ original_text_for_stress_check = text_lower
175
+
176
+ if vowel_indices_in_symbols:
177
+ can_shift_stress = False
178
+ for suf in sorted(no_stress_suffixes_approx, key=len, reverse=True):
179
+ if original_text_for_stress_check.endswith(suf) and len(original_text_for_stress_check) > len(suf):
180
+ can_shift_stress = True
181
+ break
182
+
183
+ if can_shift_stress and len(vowel_indices_in_symbols) >= 2:
184
+ stressed_vowel_symbol_index = vowel_indices_in_symbols[-2]
185
+ else:
186
+ stressed_vowel_symbol_index = vowel_indices_in_symbols[-1]
187
+
188
+ assimilated_symbols_voicing = []
189
+ i = 0
190
+ while i < len(ipa_symbols):
191
+ curr_sym = ipa_symbols[i]
192
+ action_taken = False
193
+ if i + 1 < len(ipa_symbols):
194
+ next_sym = ipa_symbols[i + 1]
195
+ if curr_sym in IPA_VOICED_CONSONANTS_SET and next_sym in IPA_VOICELESS_CONSONANTS_SET:
196
+ devoiced_curr = curr_sym
197
+ if curr_sym == "b":
198
+ devoiced_curr = "p"
199
+ elif curr_sym == "d":
200
+ devoiced_curr = "t"
201
+ elif curr_sym == "ɡ":
202
+ devoiced_curr = "k"
203
+ elif curr_sym == "ʁ":
204
+ devoiced_curr = "χ"
205
+ elif curr_sym == "v":
206
+ devoiced_curr = "f"
207
+ elif curr_sym == "z":
208
+ devoiced_curr = "s"
209
+ elif curr_sym == "d͡ʒ":
210
+ devoiced_curr = "t͡ʃ"
211
+ elif curr_sym == "ʒ":
212
+ devoiced_curr = "ʃ"
213
+ assimilated_symbols_voicing.append(devoiced_curr)
214
+ i += 1
215
+ action_taken = True
216
+ if not action_taken:
217
+ assimilated_symbols_voicing.append(curr_sym)
218
+ i += 1
219
+ ipa_symbols = assimilated_symbols_voicing
220
+
221
+ assimilated_symbols_nasal = []
222
+ i = 0
223
+ while i < len(ipa_symbols):
224
+ curr_sym = ipa_symbols[i]
225
+ if curr_sym == "n":
226
+ if i + 1 < len(ipa_symbols):
227
+ next_sym = ipa_symbols[i + 1]
228
+ if next_sym in {"k", "ɡ", "q", "χ", "ŋɡ"}:
229
+ assimilated_symbols_nasal.append("ŋ")
230
+ elif next_sym in {"f", "v"}:
231
+ assimilated_symbols_nasal.append("ɱ")
232
+ else:
233
+ assimilated_symbols_nasal.append("n")
234
+ else:
235
+ assimilated_symbols_nasal.append("n")
236
+ else:
237
+ assimilated_symbols_nasal.append(curr_sym)
238
+ i += 1
239
+ ipa_symbols = assimilated_symbols_nasal
240
+
241
+ processed_symbols_vowels = []
242
+ for idx, current_sym in enumerate(ipa_symbols):
243
+ prev_sym_phonetic = ipa_symbols[idx - 1] if idx > 0 else None
244
+ next_sym_phonetic = ipa_symbols[idx + 1] if idx + 1 < len(ipa_symbols) else None
245
+
246
+ is_stressed_vowel = (idx == stressed_vowel_symbol_index)
247
+
248
+ if current_sym == 'i':
249
+ is_near_deep_back_or_throat = False
250
+ if (prev_sym_phonetic in IPA_DEEP_BACK_OR_THROAT_CONSONANTS_SET) or \
251
+ (next_sym_phonetic in IPA_DEEP_BACK_OR_THROAT_CONSONANTS_SET):
252
+ is_near_deep_back_or_throat = True
253
+
254
+ if is_near_deep_back_or_throat:
255
+ processed_symbols_vowels.append("ɨ")
256
+ elif not is_stressed_vowel:
257
+ processed_symbols_vowels.append("ɪ")
258
+ else:
259
+ processed_symbols_vowels.append("i")
260
+
261
+ elif current_sym == 'u':
262
+ processed_symbols_vowels.append("u")
263
+ else:
264
+ processed_symbols_vowels.append(current_sym)
265
+
266
+ ipa_symbols = processed_symbols_vowels
267
+ ipa_str_processed_vowels = "".join(ipa_symbols)
268
+
269
+ parsed_final_ipa = parse_ipa_string(ipa_str_processed_vowels)
270
+
271
+ final_vowel_occurrences = []
272
+ current_char_idx_in_final_str = 0
273
+
274
+ for sym_idx, ipa_sym_final in enumerate(parsed_final_ipa):
275
+ if ipa_sym_final in IPA_VOWELS_SET:
276
+ final_vowel_occurrences.append({
277
+ 'char': ipa_sym_final,
278
+ 'start_index_in_str': current_char_idx_in_final_str
279
+ })
280
+ current_char_idx_in_final_str += len(ipa_sym_final)
281
+
282
+ stressed_ipa_str_final = ipa_str_processed_vowels
283
+ if final_vowel_occurrences:
284
+ target_stress_vowel_info_final = None
285
+ can_shift_stress_final = False
286
+ for suf in sorted(no_stress_suffixes_approx, key=len, reverse=True):
287
+ if original_text_for_stress_check.endswith(suf) and len(original_text_for_stress_check) > len(suf):
288
+ can_shift_stress_final = True
289
+ break
290
+
291
+ if can_shift_stress_final and len(final_vowel_occurrences) >= 2:
292
+ target_stress_vowel_info_final = final_vowel_occurrences[-2]
293
+ else:
294
+ target_stress_vowel_info_final = final_vowel_occurrences[-1]
295
+
296
+ if target_stress_vowel_info_final:
297
+ target_idx_in_str_final = target_stress_vowel_info_final['start_index_in_str']
298
+ stressed_ipa_str_final = (ipa_str_processed_vowels[:target_idx_in_str_final] +
299
+ "ˈ" +
300
+ ipa_str_processed_vowels[target_idx_in_str_final:])
301
+
302
+ return stressed_ipa_str_final
303
+
304
+
305
+ if __name__ == '__main__':
306
+
307
+ words_uz = [
308
+ "Oʻzbekiston", "yaxshi", "kitoblar", "senga", "qizsiz",
309
+ "iloji yoʻq", "telefonda", "mening", "Talabamisiz",
310
+ "Gʻalabaning", "ketdi", "nonvoy", "keldi", "keldimi",
311
+ "tong", "koʻngil", "sut", "yozdi", "yuzta", "e'lon", "ma'no", "sahifa",
312
+ "bilan", "uchun", "qiziq", "tushun", "iste'mol", "xususiyat", "mustaqillik",
313
+ "aytishicha", "institut", "koʻrsatkich", "bilimdonlik", "kitob", "ishchi", "yutuq",
314
+ "qir", "xirmon", "ipak", "qishloq", "iqtisod", "qoʻshiqchi", "tarixiy", "aqlli",
315
+ "mix", "nikotin", "xirurg",
316
+ "bilim", "kirim", "sizniki"
317
+ ]
318
+
319
+ print("Script Results with standard apostrophe variants:")
320
+ for w_uz in words_uz:
321
+ ipa_transcription = uzbek_to_ipa_final(w_uz)
322
+ print(f"{w_uz} -> {ipa_transcription}")
323
+
324
+ print("\nPotentially problematic words:")
325
+ problematic_words = ["kel", "men", "sen", "bor", "yoʻq", "bu", "shu", "ish", "hid"]
326
+ for w_uz in problematic_words:
327
+ ipa_transcription = uzbek_to_ipa_final(w_uz)
328
+ print(f"{w_uz} -> {ipa_transcription}")
329
+
@@ -0,0 +1,55 @@
1
+ import re
2
+
3
+ from gapiring.frontend.text_to_phoneme.phoneme_converter import uzbek_to_cmu_final, uzbek_to_cmu_strict_final, uzbek_to_ipa_final
4
+ from gapiring.frontend.text_to_phoneme.text_normalization_for_tts import text_normalization_for_tts
5
+
6
+
7
+ def pipeline_text_to_phoneme(text, phoneme_format="ipa"):
8
+ phoneme_format = phoneme_format.lower()
9
+ converters = {
10
+ "ipa": uzbek_to_ipa_final,
11
+ "cmu": uzbek_to_cmu_final,
12
+ "cmu_strict": uzbek_to_cmu_strict_final,
13
+ }
14
+ if phoneme_format not in converters:
15
+ supported_formats = ", ".join(sorted(converters))
16
+ raise ValueError(f"Unsupported phoneme_format: {phoneme_format!r}. Supported: {supported_formats}")
17
+ phoneme_converter = converters[phoneme_format]
18
+
19
+ normalized_text = text_normalization_for_tts(text)
20
+
21
+ words = tokenize_text(normalized_text)
22
+
23
+ phonemized_words = []
24
+
25
+ for word in words:
26
+ if is_punctuation_or_symbol(word):
27
+ phonemized_words.append(word)
28
+ else:
29
+ phoneme = phoneme_converter(word)
30
+ phonemized_words.append(phoneme)
31
+
32
+ phonemized_text = ' '.join(phonemized_words)
33
+
34
+ return normalized_text, phonemized_text
35
+
36
+
37
+ def tokenize_text(text):
38
+ pattern = r"[\w']+|[^\w\s]"
39
+ tokens = re.findall(pattern, text)
40
+
41
+ return tokens
42
+
43
+
44
+ def is_punctuation_or_symbol(word):
45
+ skip_chars = set(r"""!"#$%&()*+,-./:;<=>?@[\]^_`{|}~""" + '""''„"«»‹›')
46
+
47
+ return all(char in skip_chars for char in word)
48
+
49
+
50
+ if __name__ == "__main__":
51
+ input_text = "1-yanvar, 2025-yil soat 09:00 da OʻzMUda $10 evaziga imtihon boʻladi."
52
+
53
+ normalized, phonemized = pipeline_text_to_phoneme(input_text)
54
+ print("Normalized:", normalized)
55
+ print("Phonemized:", phonemized)
@@ -0,0 +1,208 @@
1
+ import re
2
+ from typing import List, Tuple
3
+
4
+ from gapiring.frontend.text_to_phoneme.uzbek_orthography import normalize_uzbek_apostrophes
5
+ from gapiring.frontend.text_to_phoneme.tools.convert_currency_to_text import convert_currency_to_text
6
+ from gapiring.frontend.text_to_phoneme.tools.convert_date_time_to_text import convert_date_time_to_text
7
+ from gapiring.frontend.text_to_phoneme.tools.full_normalize import full_normalize
8
+ from gapiring.frontend.text_to_phoneme.tools.convert_non_roman_numbers_to_text import convert_non_roman_numbers_to_text
9
+ from gapiring.frontend.text_to_phoneme.tools.split_text_numbers import split_text_numbers
10
+ from gapiring.frontend.text_to_phoneme.tools.convert_phone_numbers_to_text import convert_phone_numbers_to_text
11
+ from gapiring.frontend.text_to_phoneme.tools.convert_roman_numerals_to_text import convert_roman_numerals_to_text
12
+ from gapiring.frontend.text_to_phoneme.tools.pronounce_links_and_emails import pronounce_links_and_emails
13
+ from gapiring.frontend.text_to_phoneme.tools.convert_symbols_to_uzbek_text import convert_symbols_to_uzbek_text
14
+ from gapiring.frontend.text_to_phoneme.tools.expand_uzbek_abbreviations import expand_uzbek_abbreviations
15
+ from gapiring.frontend.text_to_phoneme.tools.spoken_lexicon import hide_terms, restore_terms
16
+ from gapiring.frontend.text_to_phoneme.tools.spoken_prepass import (attach_suffix, convert_decimals, convert_identifiers,
17
+ convert_ranges_and_codes, convert_times)
18
+
19
+ ELLIPSIS_MARKER = "ELLIPSISMARKER"
20
+ HYPHEN_MARKER = "zqhyphenqz"
21
+
22
+ NUMBER_WORDS = ("nol bir ikki uch to'rt besh olti yetti sakkiz to'qqiz o'n yigirma o'ttiz qirq ellik oltmish "
23
+ "yetmish sakson to'qson yuz ming million milliard yarim foiz").split()
24
+ _DETACHED_SUFFIX = re.compile(r"\b(" + "|".join(map(re.escape, NUMBER_WORDS)) +
25
+ r") (dagi|dan|da|gacha|ga|ning|ni|lardan|larda|lar|tadan|tasi|ta)(?![\w'])", re.IGNORECASE)
26
+
27
+
28
+ def _join_detached_suffix(match):
29
+ word, suffix = match.group(1), match.group(2).lower()
30
+ if word.lower() == "bir" and suffix.startswith("ta"):
31
+ return word[:1] + "itta" + suffix[2:]
32
+ return attach_suffix(word, suffix)
33
+
34
+
35
+ def text_normalization_for_tts(text: str) -> str:
36
+
37
+ processed_text = normalize_uzbek_apostrophes(text)
38
+
39
+ processed_text = re.sub(r"(?<=[\w'])\s*(?:\.{3,}|…)", f" {ELLIPSIS_MARKER} ", processed_text)
40
+ processed_text, terms = hide_terms(processed_text)
41
+
42
+ processed_text = convert_times(processed_text)
43
+ processed_text = convert_phone_numbers_to_text(processed_text)
44
+ processed_text = convert_date_time_to_text(processed_text)
45
+ processed_text = convert_ranges_and_codes(processed_text)
46
+ processed_text = convert_identifiers(processed_text)
47
+ processed_text = convert_currency_to_text(processed_text)
48
+ processed_text = expand_uzbek_abbreviations(processed_text)
49
+ processed_text = convert_decimals(processed_text)
50
+ processed_text = pronounce_links_and_emails(processed_text)
51
+ processed_text = convert_symbols_to_uzbek_text(processed_text)
52
+ processed_text = split_text_numbers(processed_text)
53
+ processed_text = convert_roman_numerals_to_text(processed_text)
54
+ processed_text = convert_non_roman_numbers_to_text(processed_text)
55
+
56
+ processed_text = re.sub(r"(?<=[A-Za-z'])-(?=[A-Za-z])", HYPHEN_MARKER, processed_text)
57
+ processed_text = full_normalize(processed_text)
58
+ processed_text = processed_text.replace(HYPHEN_MARKER, "-")
59
+ processed_text = re.sub(rf"\s*{ELLIPSIS_MARKER}", "...", processed_text)
60
+ processed_text = _DETACHED_SUFFIX.sub(_join_detached_suffix, processed_text)
61
+ processed_text = restore_terms(processed_text, terms)
62
+
63
+ return processed_text
64
+
65
+
66
+ def run_tests():
67
+ test_cases: List[Tuple[str, str]] = [
68
+ ("Salom dunyo!", "Salom dunyo!"),
69
+ ("Bu Oʻzbekiston.", "Bu O'zbekiston."),
70
+ ("Gʻoʻzal diyor.", "G'o'zal diyor."),
71
+ ("", ""),
72
+
73
+ ("Menda 5 ta olma bor.", "Menda beshta olma bor."),
74
+ ("12345", "o'n ikki ming uch yuz qirq besh"),
75
+ ("0", "nol"),
76
+ ("1000000 soʻm", "million so'm"),
77
+ ("Bu 1-chi qavat.", "Bu birinchi qavat."),
78
+ ("5.5", "besh yarim"),
79
+ ("5.25", "besh butun yigirma besh"),
80
+ ("Xonamiz raqami 203B.", "Xonamiz raqami ikki yuz uch B."),
81
+
82
+ ("Bugun 21.03.2024.", "Bugun yigirma birinchi mart ikki ming yigirma to'rtinchi yil."),
83
+ ("01/09/1991 da mustaqil boʻldik.",
84
+ "birinchi sentyabr bir ming to'qqiz yuz to'qson birinchi yilda mustaqil bo'ldik."),
85
+ ("2025-yil yanvar oyi.", "ikki ming yigirma beshinchi yil yanvar oyi."),
86
+ ("5-avgust kuni uchrashamiz.", "beshinchi avgust kuni uchrashamiz."),
87
+ ("1990-yillar", "bir ming to'qqiz yuz to'qsoninchi yillar"),
88
+
89
+ ("Soat 10:30.", "Soat o'n o'ttiz."),
90
+ ("9:05 da", "to'qqiz nol beshda"),
91
+ ("soat 9:05 da", "soat to'qqiz nol beshda"),
92
+ ("Soat 14:30 da", "Soat o'n to'rt o'ttizda"),
93
+ ("14:30 da", "o'n to'rt o'ttizda"),
94
+ ("35% gacha", "o'ttiz besh foizgacha"),
95
+ ("7 kVt quvvat", "yetti kilovatt quvvat"),
96
+ ("4,5 kVt", "to'rt yarim kilovatt"),
97
+ ("2,5 m", "ikki yarim metr"),
98
+ ("100% ta'minlaymiz", "yuz foiz ta'minlaymiz"),
99
+ ("Is'hoq aka", "Is'hoq aka"),
100
+ ("9:00 dan 18:00 gacha", "to'qqizdan o'n sakkizgacha"),
101
+ ("16:45 dagi", "o'n olti qirq beshdagi"),
102
+ ("Uchrashuv 14:00 da.", "Uchrashuv o'n to'rtda."),
103
+ ("23:59:58", "yigirma uch ellik to'qqiz ellik sakkiz"),
104
+ ("Yarim tunda (00:00).", "Yarim tunda nol nol ."),
105
+
106
+ ("Bu kitob 50000 soʻm turadi.", "Bu kitob ellik ming so'm turadi."),
107
+ ("Menda 100 USD bor.", "Menda yuz dollar bor."),
108
+ ("Narxi €25.", "Narxi yigirma besh yevro."),
109
+ ("15,500.75 UZS", "o'n besh ming besh yuz butun yetmish besh so'm"),
110
+
111
+ ("Prof. A. Ismoilov maʼruza qildi.", "Professor A. Ismoilov ma'ruza qildi."),
112
+ ("Doktor X bilan uchrashdim.", "Doktor X bilan uchrashdim."),
113
+
114
+ ("Chegirma 20% ni tashkil etadi.", "Chegirma yigirma foizni tashkil etadi."),
115
+ ("Tezlik 60 km/soat.", "Tezlik oltmish kilometr soat."),
116
+ ("Ogʻirligi 5 kg. Seniki nechi?", "Og'irligi besh kilogramm. Seniki nechi?"),
117
+ ("Ogʻirligi 5 kg. bo'lgan tovar.", "Og'irligi besh kilogramm bo'lgan tovar."),
118
+ ("Mening emailim: test@example.com.", "Mening emailim test kuchukcha example nuqta com."),
119
+ ("Qoʻngʻiroq qiling: +998901234567.",
120
+ "Qo'ng'iroq qiling plyus to'qqiz yuz to'qson sakkiz, to'qson, yuz yigirma uch, qirq besh, oltmish yetti."),
121
+ ("Telefon raqami (97) 777-66-55.",
122
+ "Telefon raqami to'qson yetti, yetti yuz yetmish yetti, oltmish olti, ellik besh."),
123
+ ("Web sayt: www.example.uz", "Web sayt dablyu dablyu dablyu nuqta example nuqta uz"),
124
+ ("Boʻlim #3.", "Bo'lim raqam uch."),
125
+
126
+ ("XXI asr texnologiyalari.", "yigirma birinchi asr texnologiyalari."),
127
+ ("IV bobni oʻqing.", "to'rtinchi bobni o'qing."),
128
+ ("Lyudovik XIV qirol boʻlgan.", "Lyudovik o'n to'rtinchi qirol bo'lgan."),
129
+
130
+ ("1-yanvar, 2025-yil soat 09:00 da OʻzMUda $10 evaziga imtihon boʻladi.",
131
+ "birinchi yanvar, ikki ming yigirma beshinchi yil soat to'qqizda O'zMUda o'n dollar evaziga imtihon bo'ladi."),
132
+ ("Toshkentda +25°C.", "Toshkentda plyus yigirma besh daraja Selsiy."),
133
+ ("Hisob: 45-32=13", "Hisob qirq besh ayiruv o'ttiz ikki teng o'n uch"),
134
+ ("100 m masofa.", "yuz metr masofa."),
135
+
136
+ ("Salom! Qalaysiz? Yaxshimisiz...", "Salom! Qalaysiz? Yaxshimisiz..."),
137
+ ("Bilmadim… balki ertaga.", "Bilmadim... balki ertaga."),
138
+
139
+ ("O‘g‘il bola qo’ng’iroq qildi.", "O'g'il bola qo'ng'iroq qildi."),
140
+ ("O`g`il bola", "O'g'il bola"),
141
+ ("yo'l-yo'riq ko'rsatdi", "yo'l-yo'riq ko'rsatdi"),
142
+ ("keladi-ku", "keladi-ku"),
143
+ ("mo'l-ko'l hosil", "mo'l-ko'l hosil"),
144
+ ("qalang'i-qasang'i gaplar", "qalang'i-qasang'i gaplar"),
145
+ ("son go'shti arzon", "son go'shti arzon"),
146
+ ("jinsiy shim.", "jinsiy shim."),
147
+ ("Xo'sh. Keyin-chi?", "Xo'sh. Keyin-chi?"),
148
+ ("Ism: ____", "Ism"),
149
+ ("o'g'ri mas-da", "o'g'ri mas-da"),
150
+ ("C-vitamin va D-vitamin", "C-vitamin va D-vitamin"),
151
+ ("MCHJ ochildi.", "Mas'uliyati Cheklangan Jamiyat ochildi."),
152
+ ("V-asrda", "beshinchi asrda"),
153
+ ("Tel.: +998901234567", "telefon plyus to'qqiz yuz to'qson sakkiz, to'qson, yuz yigirma uch, qirq besh, oltmish yetti"),
154
+ ("U dedi: \"Kel, biz bilan ketasan\".", "U dedi Kel, biz bilan ketasan ."),
155
+
156
+ ("1-2 chi dekabr", "birinchi-ikkinchi dekabr"),
157
+ ("1-2 kun", "bir-ikki kun"),
158
+ ("3-5-sinf", "uchinchi-beshinchi sinf"),
159
+ ("1,5 million so'm", "bir yarim million so'm"),
160
+ ("186 000 000 so'm", "yuz sakson olti million so'm"),
161
+ ("901234567", "to'qson, yuz yigirma uch, qirq besh, oltmish yetti"),
162
+ ("100 dan 100 ta", "yuzdan yuzta"),
163
+ ("5-da", "beshda"),
164
+ ("4821-337 kodi", "to'rt ming sakkiz yuz yigirma bir, uch yuz o'ttiz yetti kodi"),
165
+ ("SMS orqali", "es-em-es orqali"),
166
+ ("1. Bu birinchi punkt.", "bir. Bu birinchi punkt."),
167
+ ("1.2.3. Bu versiya raqami.", "bir.ikki.uch. Bu versiya raqami."),
168
+ ("No'malum so'zlar g'alati o'qilishi mumkin.", "No'malum so'zlar g'alati o'qilishi mumkin."),
169
+ ]
170
+
171
+ passed_count = 0
172
+ failed_count = 0
173
+
174
+ print("Starting Text Normalization Tests...\n")
175
+
176
+ for i, (input_text, expected_output) in enumerate(test_cases):
177
+ print(f"Test {i + 1}:")
178
+ print(f" Input: '{input_text}'")
179
+ try:
180
+ actual_output = text_normalization_for_tts(input_text)
181
+ print(f" Expected: '{expected_output}'")
182
+ print(f" Actual: '{actual_output}'")
183
+
184
+ if actual_output == expected_output:
185
+ print(" Result: PASS")
186
+ passed_count += 1
187
+ else:
188
+ print(" Result: FAIL")
189
+ failed_count += 1
190
+ except Exception as e:
191
+ print(f" Error: Exception during processing: {e}")
192
+ print(" Result: ERROR")
193
+ failed_count += 1
194
+ print("-" * 30)
195
+
196
+ print("\nTest Summary:")
197
+ print(f"Total tests: {len(test_cases)}")
198
+ print(f"Passed: {passed_count}")
199
+ print(f"Failed: {failed_count}")
200
+
201
+ if failed_count == 0:
202
+ print("\nAll tests passed successfully (based on current placeholder logic)!")
203
+ else:
204
+ print("\nSome tests failed or encountered errors.")
205
+
206
+
207
+ if __name__ == "__main__":
208
+ run_tests()
File without changes