stressonnx 0.0.2__tar.gz

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 (70) hide show
  1. stressonnx-0.0.2/LICENSE +202 -0
  2. stressonnx-0.0.2/MANIFEST.in +1 -0
  3. stressonnx-0.0.2/PKG-INFO +313 -0
  4. stressonnx-0.0.2/README.md +288 -0
  5. stressonnx-0.0.2/pyproject.toml +48 -0
  6. stressonnx-0.0.2/setup.cfg +4 -0
  7. stressonnx-0.0.2/stressonnx/__init__.py +186 -0
  8. stressonnx-0.0.2/stressonnx/_common.py +96 -0
  9. stressonnx-0.0.2/stressonnx/backends/__init__.py +10 -0
  10. stressonnx-0.0.2/stressonnx/backends/ruaccent.py +448 -0
  11. stressonnx-0.0.2/stressonnx/backends/silero.py +315 -0
  12. stressonnx-0.0.2/stressonnx/backends/simple.py +308 -0
  13. stressonnx-0.0.2/stressonnx/download.py +71 -0
  14. stressonnx-0.0.2/stressonnx/errors.py +59 -0
  15. stressonnx-0.0.2/stressonnx/langs.py +23 -0
  16. stressonnx-0.0.2/stressonnx/languages/az-Cyrl.json +15 -0
  17. stressonnx-0.0.2/stressonnx/languages/az-Latn.json +15 -0
  18. stressonnx-0.0.2/stressonnx/languages/ba.json +15 -0
  19. stressonnx-0.0.2/stressonnx/languages/be.json +19 -0
  20. stressonnx-0.0.2/stressonnx/languages/bg.json +14 -0
  21. stressonnx-0.0.2/stressonnx/languages/cv.json +15 -0
  22. stressonnx-0.0.2/stressonnx/languages/hy.json +15 -0
  23. stressonnx-0.0.2/stressonnx/languages/ka.json +15 -0
  24. stressonnx-0.0.2/stressonnx/languages/kbd.json +15 -0
  25. stressonnx-0.0.2/stressonnx/languages/kjh.json +15 -0
  26. stressonnx-0.0.2/stressonnx/languages/kk.json +15 -0
  27. stressonnx-0.0.2/stressonnx/languages/ky.json +15 -0
  28. stressonnx-0.0.2/stressonnx/languages/lv.json +14 -0
  29. stressonnx-0.0.2/stressonnx/languages/mdf.json +15 -0
  30. stressonnx-0.0.2/stressonnx/languages/mk.json +14 -0
  31. stressonnx-0.0.2/stressonnx/languages/myv.json +15 -0
  32. stressonnx-0.0.2/stressonnx/languages/ru.json +20 -0
  33. stressonnx-0.0.2/stressonnx/languages/sah.json +15 -0
  34. stressonnx-0.0.2/stressonnx/languages/sl.json +14 -0
  35. stressonnx-0.0.2/stressonnx/languages/tg.json +15 -0
  36. stressonnx-0.0.2/stressonnx/languages/tt.json +15 -0
  37. stressonnx-0.0.2/stressonnx/languages/udm.json +15 -0
  38. stressonnx-0.0.2/stressonnx/languages/uk.json +18 -0
  39. stressonnx-0.0.2/stressonnx/languages/uz-Cyrl.json +15 -0
  40. stressonnx-0.0.2/stressonnx/languages/uz-Latn.json +15 -0
  41. stressonnx-0.0.2/stressonnx/languages/xal.json +15 -0
  42. stressonnx-0.0.2/stressonnx/notation.py +124 -0
  43. stressonnx-0.0.2/stressonnx/pipeline.py +281 -0
  44. stressonnx-0.0.2/stressonnx/py.typed +0 -0
  45. stressonnx-0.0.2/stressonnx/registry.py +260 -0
  46. stressonnx-0.0.2/stressonnx/stressor.py +72 -0
  47. stressonnx-0.0.2/stressonnx.egg-info/PKG-INFO +313 -0
  48. stressonnx-0.0.2/stressonnx.egg-info/SOURCES.txt +68 -0
  49. stressonnx-0.0.2/stressonnx.egg-info/dependency_links.txt +1 -0
  50. stressonnx-0.0.2/stressonnx.egg-info/requires.txt +12 -0
  51. stressonnx-0.0.2/stressonnx.egg-info/top_level.txt +1 -0
  52. stressonnx-0.0.2/tests/test_download_layout.py +93 -0
  53. stressonnx-0.0.2/tests/test_errors_fallback.py +82 -0
  54. stressonnx-0.0.2/tests/test_export_parity.py +58 -0
  55. stressonnx-0.0.2/tests/test_internals.py +236 -0
  56. stressonnx-0.0.2/tests/test_linguistic_edge_cases.py +214 -0
  57. stressonnx-0.0.2/tests/test_model_registry.py +163 -0
  58. stressonnx-0.0.2/tests/test_new_languages.py +60 -0
  59. stressonnx-0.0.2/tests/test_no_torch_import.py +47 -0
  60. stressonnx-0.0.2/tests/test_notation.py +146 -0
  61. stressonnx-0.0.2/tests/test_oov_rules.py +111 -0
  62. stressonnx-0.0.2/tests/test_properties.py +82 -0
  63. stressonnx-0.0.2/tests/test_review_fixes.py +130 -0
  64. stressonnx-0.0.2/tests/test_stress_ru.py +77 -0
  65. stressonnx-0.0.2/tests/test_stress_ru_silero.py +40 -0
  66. stressonnx-0.0.2/tests/test_stress_simple.py +37 -0
  67. stressonnx-0.0.2/tests/test_stress_ukr_bel.py +27 -0
  68. stressonnx-0.0.2/tests/test_types.py +216 -0
  69. stressonnx-0.0.2/tests/test_v2_api.py +58 -0
  70. stressonnx-0.0.2/version.py +10 -0
@@ -0,0 +1,202 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Copyright 2026 TigreGotico Lda
191
+
192
+ Licensed under the Apache License, Version 2.0 (the "License");
193
+ you may not use this file except in compliance with the License.
194
+ You may obtain a copy of the License at
195
+
196
+ http://www.apache.org/licenses/LICENSE-2.0
197
+
198
+ Unless required by applicable law or agreed to in writing, software
199
+ distributed under the License is distributed on an "AS IS" BASIS,
200
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
+ See the License for the specific language governing permissions and
202
+ limitations under the License.
@@ -0,0 +1 @@
1
+ include version.py
@@ -0,0 +1,313 @@
1
+ Metadata-Version: 2.4
2
+ Name: stressonnx
3
+ Version: 0.0.2
4
+ Summary: Pure-onnxruntime multi-language word-stress / accentuation
5
+ Author-email: JarbasAI <jarbasai@mailfence.com>
6
+ License: Apache-2.0
7
+ Project-URL: Homepage, https://github.com/TigreGotico/stressonnx
8
+ Classifier: Programming Language :: Python :: 3
9
+ Classifier: License :: OSI Approved :: Apache Software License
10
+ Classifier: Operating System :: OS Independent
11
+ Requires-Python: >=3.10
12
+ Description-Content-Type: text/markdown
13
+ License-File: LICENSE
14
+ Requires-Dist: numpy
15
+ Requires-Dist: onnxruntime
16
+ Requires-Dist: huggingface_hub
17
+ Requires-Dist: tokenizers
18
+ Provides-Extra: export
19
+ Requires-Dist: torch; extra == "export"
20
+ Requires-Dist: silero_stress; extra == "export"
21
+ Provides-Extra: test
22
+ Requires-Dist: pytest; extra == "test"
23
+ Requires-Dist: hypothesis; extra == "test"
24
+ Dynamic: license-file
25
+
26
+ # stressonnx
27
+
28
+ Multi-language **word-stress placement** ("accentuation") for text, built for
29
+ TTS front-ends. Pure `onnxruntime + numpy` at runtime — **no torch, ever**.
30
+
31
+ ```python
32
+ from stressonnx import stress
33
+
34
+ stress("старинный замок стоит на горе", "ru") # 'стари́нный за́мок сто́ит на горе́'
35
+ stress("дверной замок надёжен", "ru") # 'дверно́й замо́к надёжен'
36
+ ```
37
+
38
+ Same spelling, different word: за́мок is a castle, замо́к is a lock. stressonnx
39
+ reads the sentence, decides which one you meant, and marks the stressed vowel.
40
+
41
+ ---
42
+
43
+ ## Why word stress?
44
+
45
+ **Word stress** (lexical stress) is which syllable of a word is pronounced
46
+ prominently: English *REcord* (noun) vs *reCORD* (verb). A text-to-speech
47
+ system must know it before it can pick the right sounds — in Russian,
48
+ unstressed vowels *reduce* (о sounds like а), so getting the stress wrong
49
+ changes every vowel in the word, not just the melody.
50
+
51
+ Whether **you** need this library depends on how your language writes stress:
52
+
53
+ | Orthography type | Examples | What you need |
54
+ |---|---|---|
55
+ | Stress is free/mobile and **not written** | Russian, Ukrainian, Belarusian, most languages here | **A stress model — this library.** Nothing in the spelling of `замок` tells you which syllable to stress; only context does. |
56
+ | Stress is **predictable by rule** | Kazakh/Turkic (final syllable), Armenian, Georgian | A positional rule covers most words — that is the `simple` backend: a curated exception vocabulary plus a per-language default rule. |
57
+ | Stress is **already written** | Spanish, Greek, Portuguese | You do **not** need stressonnx — the orthography (accent rules) already encodes it. But you may still need *sense* disambiguation, see below. |
58
+
59
+ **The Portuguese case (why "stress is written" isn't the end of the story):**
60
+ Portuguese spelling pins down the stressed syllable, yet pairs like *sede*
61
+ (thirst /ˈsedɨ/ vs headquarters /ˈsɛdɨ/) share spelling *and* stress position
62
+ while differing in vowel **quality** — resolvable only from meaning. Our
63
+ sibling library [bifonia](https://github.com/TigreGotico/bifonia) solves that
64
+ with the same "disambiguate before G2P" idea used here: its
65
+ `add_extra_diacritics(text)` rewrites the homograph with an explicit
66
+ open/closed-vowel diacritic (*séde*/*sêde*) so any downstream phonemizer gets
67
+ it right. Rule of thumb: **unwritten stress → stressonnx; written stress but
68
+ sense-dependent pronunciation → a bifonia-style diacritic restorer.**
69
+
70
+ ---
71
+
72
+ ## Supported languages
73
+
74
+ | Model id | Languages | What it is | Measured quality |
75
+ |----------|-----------|------------|------------------|
76
+ | `ruaccent` | `ru` (default) | Homograph-aware 4-model ONNX pipeline (derived from [RUAccent](https://github.com/Den4ikAI/ruaccent), Apache-2.0) | 0.938 word accuracy, **0.820 on homographs** |
77
+ | `silero` | `uk`, `be` (defaults), `ru` | Neural ONNX pipeline exported from [silero_stress](https://github.com/snakers4/silero-stress) (MIT); the `ru` variant also restores е→ё | ru 0.914 / uk 0.785 / be 0.873 |
78
+ | `simple` | 26 languages¹ | Curated vocabulary + per-language positional rule; no neural inference | parity-locked to upstream / sourced rules, see scoreboard |
79
+
80
+ ¹ `ru uk be bg mk sl lv hy ka kk ky tt ba cv sah kjh tg udm mdf myv kbd xal
81
+ az-Latn az-Cyrl uz-Latn uz-Cyrl` — Russian, Ukrainian, Belarusian (all
82
+ dictionary-path), Bulgarian, Macedonian, Slovene, Latvian, Armenian,
83
+ Georgian, Kazakh, Kyrgyz, Tatar, Bashkir, Chuvash, Yakut, Khakas, Tajik,
84
+ Udmurt, Moksha, Erzya, Kabardian, Kalmyk, Azerbaijani (both scripts), Uzbek
85
+ (both scripts). Every language — including ru/uk/be — has a torch-free,
86
+ ONNX-free rule/vocabulary path (`model="simple"`), so `fallback=True` always
87
+ bottoms out in a model that needs nothing but a small vocabulary file.
88
+
89
+ Numbers come from the committed, reproducible
90
+ [benchmark scoreboard](benchmarks/RESULTS.md) (annotated UD-treebank gold;
91
+ read its noise-ceiling note before quoting absolutes). Defaults per
92
+ language: `ru → ruaccent`, `uk/be → silero`, everything else → `simple`.
93
+
94
+ Models are hosted on
95
+ [TigreGotico/stressonnx-models](https://huggingface.co/TigreGotico/stressonnx-models)
96
+ and downloaded automatically on first use (see *Offline & failure behavior*).
97
+
98
+ ---
99
+
100
+ ## Install
101
+
102
+ ```bash
103
+ pip install stressonnx
104
+ ```
105
+
106
+ Runtime dependencies: `onnxruntime`, `numpy`, `huggingface_hub`, and
107
+ `tokenizers` (used only by the `ru` ruaccent pipeline). Optional:
108
+
109
+ - `razdel` — better Russian sentence splitting inside the ruaccent pipeline
110
+ (`pip install razdel`); without it the whole input is processed as one span.
111
+ - `pip install stressonnx[export]` — torch + silero_stress, **only** for
112
+ re-exporting models from a checkout (never needed at runtime).
113
+
114
+ ---
115
+
116
+ ## Usage
117
+
118
+ ```python
119
+ from stressonnx import StressPipeline, analyze, stress, to_plus_notation
120
+
121
+ # One-shot function (caches model instances internally)
122
+ stress("Привіт світ", "uk") # 'Приві́т сві́т'
123
+ stress("Сәлем Қазақстан", "kk") # 'Сәле́м Қазақста́н'
124
+
125
+ # Pick a specific model, or a capability instead of a model id
126
+ stress("красивый город", "ru", model="silero") # 'краси́вый го́род'
127
+ stress("красивый город", "ru", model="simple") # 'краси́вый го́род'
128
+ stress("красивый город", "ru", prefer="fast") # 'краси́вый го́род' (silero)
129
+
130
+ # An isolated engine with its own cache and failure policy
131
+ pipeline = StressPipeline()
132
+ pipeline.stress("замок стоит на горе", "ru") # 'за́мок сто́ит на горе́'
133
+ ```
134
+
135
+ ### Structured results: `analyze()`
136
+
137
+ For TTS pipelines that need to reason about individual words rather than a
138
+ marked string, `analyze()` returns a `StressResult`: per-word spans with
139
+ offsets into the **original, untouched input**.
140
+
141
+ ```python
142
+ result = analyze("замок стоит на горе", "ru")
143
+ result.text # 'за́мок сто́ит на горе́' (same as stress())
144
+
145
+ for w in result.words:
146
+ print(w.text, w.start, w.end, w.stressed_index, w.yo_restored)
147
+ # замок 0 5 1 False
148
+ # стоит 6 11 2 False
149
+ # на 12 14 None False
150
+ # горе 15 19 2 False
151
+ ```
152
+
153
+ `w.stressed_index` is the offset of the stressed vowel *within the word*
154
+ (`None` if the word carries no mark); `w.yo_restored` is `True` when the
155
+ backend rewrote е→ё inside that word. Because offsets refer to `result.original`
156
+ exactly as passed in, callers never need to re-parse the marked string to
157
+ locate a word.
158
+
159
+ ### Batches: `stress_batch()`
160
+
161
+ ```python
162
+ from stressonnx import stress_batch
163
+
164
+ stress_batch(["привет", "мир"], "ru") # ['приве́т', 'мир']
165
+ ```
166
+
167
+ ### Output notation
168
+
169
+ All backends emit the **combining acute accent** (U+0301) *after* the
170
+ stressed vowel — `приве́т` is `п р и в е U+0301 т`. For TTS models trained on
171
+ the `+`-before-vowel format:
172
+
173
+ ```python
174
+ stress("привет", "ru", notation="plus") # 'прив+ет'
175
+ to_plus_notation("приве́т") # 'прив+ет' (handles NFC-composed á too)
176
+ ```
177
+
178
+ ### ё restoration (Russian)
179
+
180
+ Both Russian neural backends restore ё that writers commonly type as е:
181
+ `зеленый → зелё́ный`. Genuinely ambiguous ё-homographs (все/всё) are resolved
182
+ by `ruaccent` from context and deliberately left untouched by `silero`.
183
+
184
+ ---
185
+
186
+ ## Offline & failure behavior
187
+
188
+ - **First call per language downloads models** into the standard Hugging Face
189
+ cache (`~/.cache/huggingface`, relocatable via `HF_HOME`). Sizes: `ru`
190
+ ruaccent ≈ 500 MB, silero ≈ tens of MB, `simple` languages ≈ 1 MB.
191
+ - **Warm-up ahead of serving:** call `warm_up(lang)` once at startup so no
192
+ synthesis request ever blocks on a model download; it loads the same
193
+ cached instance later `stress()` calls use.
194
+ - **Fully offline:** after a warm run, set `HF_HUB_OFFLINE=1` — cached models
195
+ keep working, network is never touched.
196
+ - **Typed failures:**
197
+
198
+ ```python
199
+ from stressonnx import stress, UnsupportedLanguageError, ModelDownloadError
200
+
201
+ try:
202
+ out = stress(text, lang, fallback=True) # opt-in: walk ruaccent→silero→simple
203
+ except UnsupportedLanguageError as e: # also catchable as ValueError
204
+ out = text # e.supported lists valid tags
205
+ except ModelDownloadError as e: # names the exact missing HF path
206
+ out = text
207
+ ```
208
+
209
+ `fallback=True` degrades down the quality chain with a logged warning per
210
+ hop (it also engages on `ModelLoadError` — a corrupt cache — not just
211
+ failed downloads); the default (`False`) raises immediately. A failed
212
+ (lang, model) pair is not retried for 30 s, so an outage never triggers a
213
+ download attempt per call.
214
+
215
+ **Supply-chain pinning:** model files are fetched from a commit-pinned
216
+ revision of the HF repo (`HF_REPO_REVISION` in `stressonnx/registry.py`),
217
+ so releases are reproducible and upstream changes never reach users
218
+ implicitly.
219
+
220
+ **Thread safety:** `stress()` and the backends use double-checked locking
221
+ for lazy loads; calling from multiple threads is supported (onnxruntime
222
+ sessions are thread-safe for inference).
223
+
224
+ ### Contracts worth knowing
225
+
226
+ - `simple`/`silero` **skip** words already carrying U+0301; `ruaccent`
227
+ **strips and re-derives** (wrong input marks get corrected).
228
+ - Monosyllables: `simple`/`silero` always stress them; `ruaccent` usually
229
+ leaves bare single-vowel words unmarked.
230
+ - `ruaccent` normalizes its input (drops symbols like `…`, collapses runs of
231
+ whitespace) — it is not byte-layout-preserving; the other backends are.
232
+ - Russian hyphenated clitics (`кто́-то`, `како́й-нибудь`, `-либо`, `-таки`,
233
+ `-ка`) never receive a mark on the particle.
234
+
235
+ ---
236
+
237
+ ## Guarding by writing system
238
+
239
+ Feeding Cyrillic to the Georgian model (or vice versa) is a silent no-op — the
240
+ input never matches the model's alphabet. Check first:
241
+
242
+ ```python
243
+ from stressonnx import lang_to_script, MODEL_REGISTRY
244
+
245
+ if lang_to_script(lang) in MODEL_REGISTRY[model_id].input_scripts:
246
+ text = stress(text, lang, model=model_id)
247
+ ```
248
+
249
+ `Script` values (`"cyrillic"`, `"latin"`, `"armenian"`, `"georgian"`) are
250
+ plain strings shared with phoonnx's `Alphabet` enum for direct comparison.
251
+
252
+ ---
253
+
254
+ ## Adding a language
255
+
256
+ Two paths, both documented step-by-step for newcomers in
257
+ [`export/ADDING_A_LANGUAGE.md`](export/ADDING_A_LANGUAGE.md):
258
+
259
+ 1. **You have a stressed wordlist** → ship a `simple` language: package the
260
+ vocabulary, declare alphabet/vowels/OOV rule, upload to the HF repo,
261
+ register the language tag. No training, no torch.
262
+ 2. **You have (or train) a neural accentor** → export it to ONNX with the
263
+ scripts in `export/` and add a backend entry.
264
+
265
+ All 20 upstream silero_stress vocabularies are already shipped, and
266
+ `export/build_wiktionary_vocab.py` turns any language whose Wiktionary
267
+ headwords carry stress marks into a `simple` language (that is how
268
+ Bulgarian, Macedonian, Slovene, Latvian and Ukrainian were built; Russian
269
+ came from the RUAccent pronunciation dictionary).
270
+
271
+ ---
272
+
273
+ ## Documentation
274
+
275
+ Pick your entry point:
276
+
277
+ - **New to all of this?** The [Why word stress?](#why-word-stress) section
278
+ above, then [`docs/languages.md`](docs/languages.md) — a plain-language,
279
+ per-language guide to why stress marking is needed and what we do about it.
280
+ - **Developer integrating stressonnx?** [Usage](#usage) above, then
281
+ [`docs/models.md`](docs/models.md) for backend contracts and
282
+ [`docs/architecture.md`](docs/architecture.md) for the package internals.
283
+ - **Linguist checking our homework?** [`docs/languages.md`](docs/languages.md)
284
+ carries the typology and per-rule citations;
285
+ [`benchmarks/RESULTS.md`](benchmarks/RESULTS.md) the measurements; every
286
+ OOV rule's source is quoted in `stressonnx/backends/simple.py`.
287
+
288
+ - [`docs/languages.md`](docs/languages.md) — per-language guide: stress
289
+ system, why TTS needs it, what stressonnx does, with citations.
290
+ - [`docs/models.md`](docs/models.md) — every backend in depth: pipeline
291
+ stages, per-language rules, quality numbers, contracts.
292
+ - [`docs/architecture.md`](docs/architecture.md) — package layout, the single
293
+ download layer, data flow.
294
+ - [`benchmarks/RESULTS.md`](benchmarks/RESULTS.md) — the scoreboard and how to
295
+ reproduce it.
296
+ - [`examples/`](examples/) — runnable scripts, from basics to homograph demos.
297
+
298
+ ## Related projects
299
+
300
+ - [phoonnx](https://github.com/TigreGotico/phoonnx) — ONNX TTS engine; calls
301
+ stressonnx before phonemization for Russian voices.
302
+ - [bifonia](https://github.com/TigreGotico/bifonia) — European-Portuguese
303
+ homograph disambiguation by meaning (the "written stress, unwritten vowel
304
+ quality" counterpart to this library).
305
+ - [scriptconv](https://github.com/TigreGotico/scriptconv) — script detection
306
+ and phoneme-notation conversion.
307
+ - [silabificador](https://github.com/TigreGotico/silabificador) — Portuguese
308
+ syllabification and stress by rule.
309
+
310
+ ## License
311
+
312
+ Apache-2.0. Model attributions: RUAccent (Den4ikAI, Apache-2.0),
313
+ silero_stress (snakers4, MIT).