Instructions to use RegaLabs/RegaLabs-TTS with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- CosyVoice
How to use RegaLabs/RegaLabs-TTS with CosyVoice:
# No code snippets available yet for this library. # To use this model, check the repository files and the library's documentation. # Want to help? PRs adding snippets are welcome at: # https://github.com/huggingface/huggingface.js
- Notebooks
- Google Colab
- Kaggle
Upload RegaLabs-TTS model weights, infer.py, and app.py Gradio demo
Browse files- .gitattributes +1 -0
- .gitignore +4 -0
- LICENSE +193 -0
- README.md +99 -0
- app.py +188 -0
- cosyvoice3_sorani_flow_best_step2300.pt +3 -0
- cosyvoice3_sorani_flow_best_step2300.yaml +11 -0
- infer.py +76 -0
- samples/aran_en021.wav +3 -0
- sorani/__init__.py +6 -0
- sorani/frontend.py +119 -0
.gitattributes
CHANGED
|
@@ -33,3 +33,4 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
|
| 33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
| 34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
| 35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
|
|
|
|
|
| 33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
| 34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
| 35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
| 36 |
+
samples/aran_en021.wav filter=lfs diff=lfs merge=lfs -text
|
.gitignore
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
__pycache__/
|
| 2 |
+
*.pyc
|
| 3 |
+
*.egg-info/
|
| 4 |
+
output*.wav
|
LICENSE
ADDED
|
@@ -0,0 +1,193 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
========================================================================
|
| 2 |
+
REGALABS ATTRIBUTION & CREDIT NOTICE
|
| 3 |
+
========================================================================
|
| 4 |
+
Copyright (c) 2026 RegaLabs. All rights reserved.
|
| 5 |
+
|
| 6 |
+
Any public use, generated media (including videos, podcasts, audiobooks,
|
| 7 |
+
voiceovers, TV/radio broadcasts, online content), software applications,
|
| 8 |
+
or derivative works utilizing RegaLabs-TTS, its model weights, or tools
|
| 9 |
+
MUST explicitly provide clear attribution and credit to RegaLabs:
|
| 10 |
+
|
| 11 |
+
"Voice synthesized using RegaLabs-TTS by RegaLabs"
|
| 12 |
+
(or "Audio powered by RegaLabs")
|
| 13 |
+
|
| 14 |
+
========================================================================
|
| 15 |
+
APACHE LICENSE VERSION 2.0
|
| 16 |
+
========================================================================
|
| 17 |
+
|
| 18 |
+
Apache License
|
| 19 |
+
Version 2.0, January 2004
|
| 20 |
+
http://www.apache.org/licenses/
|
| 21 |
+
|
| 22 |
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
| 23 |
+
|
| 24 |
+
1. Definitions.
|
| 25 |
+
|
| 26 |
+
"License" shall mean the terms and conditions for use, reproduction,
|
| 27 |
+
and distribution as defined by Sections 1 through 9 of this document.
|
| 28 |
+
|
| 29 |
+
"Licensor" shall mean the copyright owner or entity authorized by
|
| 30 |
+
the copyright owner that is granting the License.
|
| 31 |
+
|
| 32 |
+
"Legal Entity" shall mean the union of the acting entity and all
|
| 33 |
+
other entities that control, are controlled by, or are under common
|
| 34 |
+
control with that entity. For the purposes of this definition,
|
| 35 |
+
"control" means (i) the power, direct or indirect, to cause the
|
| 36 |
+
direction or management of such entity, whether by contract or
|
| 37 |
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
| 38 |
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
| 39 |
+
|
| 40 |
+
"You" (or "Your") shall mean an individual or Legal Entity
|
| 41 |
+
exercising permissions granted by this License.
|
| 42 |
+
|
| 43 |
+
"Source" form shall mean the preferred form for making modifications,
|
| 44 |
+
including but not limited to software source code, documentation
|
| 45 |
+
source, and configuration files.
|
| 46 |
+
|
| 47 |
+
"Object" form shall mean any form resulting from mechanical
|
| 48 |
+
transformation or translation of a Source form, including but
|
| 49 |
+
not limited to compiled object code, generated documentation,
|
| 50 |
+
and conversions to other media types.
|
| 51 |
+
|
| 52 |
+
"Work" shall mean the work of authorship, whether in Source or
|
| 53 |
+
Object form, made available under the License, as indicated by a
|
| 54 |
+
copyright notice that is included in or attached to the work
|
| 55 |
+
(an example is provided in the Appendix below).
|
| 56 |
+
|
| 57 |
+
"Derivative Works" shall mean any work, whether in Source or Object
|
| 58 |
+
form, that is based on (or derived from) the Work and for which the
|
| 59 |
+
editorial revisions, annotations, elaborations, or other modifications
|
| 60 |
+
represent, as a whole, an original work of authorship. For the purposes
|
| 61 |
+
of this License, Derivative Works shall not include works that remain
|
| 62 |
+
separable from, or merely link (or bind by name) to the interfaces of,
|
| 63 |
+
the Work and Derivative Works thereof.
|
| 64 |
+
|
| 65 |
+
"Contribution" shall mean any work of authorship, including
|
| 66 |
+
the original version of the Work and any modifications or additions
|
| 67 |
+
to that Work or Derivative Works thereof, that is intentionally
|
| 68 |
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
| 69 |
+
or by an individual or Legal Entity authorized to submit on behalf of
|
| 70 |
+
the copyright owner. For the purposes of this definition, "submitted"
|
| 71 |
+
means any form of electronic, verbal, or written communication sent
|
| 72 |
+
to the Licensor or its representatives, including but not limited to
|
| 73 |
+
communication on electronic mailing lists, source code control systems,
|
| 74 |
+
and issue tracking systems that are managed by, or on behalf of, the
|
| 75 |
+
Licensor for the purpose of discussing and improving the Work, but
|
| 76 |
+
excluding communication that is conspicuously marked or otherwise
|
| 77 |
+
designated in writing by the copyright owner as "Not a Contribution."
|
| 78 |
+
|
| 79 |
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
| 80 |
+
on behalf of whom a Contribution has been received by Licensor and
|
| 81 |
+
subsequently incorporated within the Work.
|
| 82 |
+
|
| 83 |
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
| 84 |
+
this License, each Contributor hereby grants to You a perpetual,
|
| 85 |
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
| 86 |
+
copyright license to reproduce, prepare Derivative Works of,
|
| 87 |
+
publicly display, publicly perform, sublicense, and distribute the
|
| 88 |
+
Work and such Derivative Works in Source or Object form.
|
| 89 |
+
|
| 90 |
+
3. Grant of Patent License. Subject to the terms and conditions of
|
| 91 |
+
this License, each Contributor hereby grants to You a perpetual,
|
| 92 |
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
| 93 |
+
(except as stated in this section) patent license to make, have made,
|
| 94 |
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
| 95 |
+
where such license applies only to those patent claims licensable
|
| 96 |
+
by such Contributor that are necessarily infringed by their
|
| 97 |
+
Contribution(s) alone or by combination of their Contribution(s)
|
| 98 |
+
with the Work to which such Contribution(s) was submitted. If You
|
| 99 |
+
institute patent litigation against any entity (including a
|
| 100 |
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
| 101 |
+
or a Contribution incorporated within the Work constitutes direct
|
| 102 |
+
or contributory patent infringement, then any patent licenses
|
| 103 |
+
granted to You under this License for that Work shall terminate
|
| 104 |
+
as of the date such litigation is filed.
|
| 105 |
+
|
| 106 |
+
4. Redistribution. You may reproduce and distribute copies of the
|
| 107 |
+
Work or Derivative Works thereof in any medium, with or without
|
| 108 |
+
modifications, and in Source or Object form, provided that You
|
| 109 |
+
meet the following conditions:
|
| 110 |
+
|
| 111 |
+
(a) You must give any other recipients of the Work or
|
| 112 |
+
Derivative Works a copy of this License; and
|
| 113 |
+
|
| 114 |
+
(b) You must cause any modified files to carry prominent notices
|
| 115 |
+
stating that You changed the files; and
|
| 116 |
+
|
| 117 |
+
(c) You must retain, in the Source form of any Derivative Works
|
| 118 |
+
that You distribute, all copyright, patent, trademark, and
|
| 119 |
+
attribution notices from the Source form of the Work,
|
| 120 |
+
excluding those notices that do not pertain to any part of
|
| 121 |
+
the Derivative Works; and
|
| 122 |
+
|
| 123 |
+
(d) If the Work includes a "NOTICE" text file as part of its
|
| 124 |
+
distribution, then any Derivative Works that You distribute must
|
| 125 |
+
include a readable copy of the attribution notices contained
|
| 126 |
+
within such NOTICE file, excluding those notices that do not
|
| 127 |
+
pertain to any part of the Derivative Works, in at least one
|
| 128 |
+
of the following places: within a NOTICE text file distributed
|
| 129 |
+
as part of the Derivative Works; within the Source form or
|
| 130 |
+
documentation, if provided along with the Derivative Works; or,
|
| 131 |
+
within a display generated by the Derivative Works, if and
|
| 132 |
+
wherever such third-party notices normally appear. The contents
|
| 133 |
+
of the NOTICE file are for informational purposes only and
|
| 134 |
+
do not modify the License. You may add Your own attribution
|
| 135 |
+
notices within Derivative Works that You distribute, alongside
|
| 136 |
+
or as an addendum to the NOTICE text from the Work, provided
|
| 137 |
+
that such additional attribution notices cannot be construed
|
| 138 |
+
as modifying the License.
|
| 139 |
+
|
| 140 |
+
You may add Your own copyright statement to Your modifications and
|
| 141 |
+
may provide additional or different license terms and conditions
|
| 142 |
+
for use, reproduction, or distribution of Your modifications, or
|
| 143 |
+
for any such Derivative Works as a whole, provided Your use,
|
| 144 |
+
reproduction, and distribution of the Work otherwise complies with
|
| 145 |
+
the conditions stated in this License.
|
| 146 |
+
|
| 147 |
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
| 148 |
+
any Contribution intentionally submitted for inclusion in the Work
|
| 149 |
+
by You to the Licensor shall be under the terms and conditions of
|
| 150 |
+
this License, without any additional terms or conditions.
|
| 151 |
+
Notwithstanding the above, nothing herein shall supersede or modify
|
| 152 |
+
the terms of any separate license agreement you may have executed
|
| 153 |
+
with Licensor regarding such Contributions.
|
| 154 |
+
|
| 155 |
+
6. Trademarks. This License does not grant permission to use the trade
|
| 156 |
+
names, trademarks, service marks, or product names of the Licensor,
|
| 157 |
+
except as required for reasonable and customary use in describing the
|
| 158 |
+
origin of the Work and reproducing the content of the NOTICE file.
|
| 159 |
+
|
| 160 |
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
| 161 |
+
agreed to in writing, Licensor provides the Work (and each
|
| 162 |
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
| 163 |
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
| 164 |
+
implied, including, without limitation, any warranties or conditions
|
| 165 |
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
| 166 |
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
| 167 |
+
appropriateness of using or redistributing the Work and assume any
|
| 168 |
+
risks associated with Your exercise of permissions under this License.
|
| 169 |
+
|
| 170 |
+
8. Limitation of Liability. In no event and under no legal theory,
|
| 171 |
+
whether in tort (including negligence), contract, or otherwise,
|
| 172 |
+
unless required by applicable law (such as deliberate and grossly
|
| 173 |
+
negligent acts) or agreed to in writing, shall any Contributor be
|
| 174 |
+
liable to You for damages, including any direct, indirect, special,
|
| 175 |
+
incidental, or consequential damages of any character arising as a
|
| 176 |
+
result of this License or out of the use or inability to use the
|
| 177 |
+
Work (including but not limited to damages for loss of goodwill,
|
| 178 |
+
work stoppage, computer failure or malfunction, or any and all
|
| 179 |
+
other commercial damages or losses), even if such Contributor
|
| 180 |
+
has been advised of the possibility of such damages.
|
| 181 |
+
|
| 182 |
+
9. Accepting Warranty or Additional Liability. While redistributing
|
| 183 |
+
the Work or Derivative Works thereof, You may choose to offer,
|
| 184 |
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
| 185 |
+
or other liability obligations and/or rights consistent with this
|
| 186 |
+
License. However, in accepting such obligations, You may act only
|
| 187 |
+
on Your own behalf and on Your sole responsibility, not on behalf
|
| 188 |
+
of any other Contributor, and only if You agree to indemnify,
|
| 189 |
+
defend, and hold each Contributor harmless for any liability
|
| 190 |
+
incurred by, or claims asserted against, such Contributor by reason
|
| 191 |
+
of your accepting any such warranty or additional liability.
|
| 192 |
+
|
| 193 |
+
END OF TERMS AND CONDITIONS
|
README.md
ADDED
|
@@ -0,0 +1,99 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
language:
|
| 3 |
+
- ckb
|
| 4 |
+
license: apache-2.0
|
| 5 |
+
tags:
|
| 6 |
+
- text-to-speech
|
| 7 |
+
- tts
|
| 8 |
+
- sorani
|
| 9 |
+
- kurdish
|
| 10 |
+
- cosyvoice3
|
| 11 |
+
- regalabs
|
| 12 |
+
base_model: FunAudioLLM/Fun-CosyVoice3-0.5B-2512
|
| 13 |
+
pipeline_tag: text-to-speech
|
| 14 |
+
library_name: cosyvoice
|
| 15 |
+
---
|
| 16 |
+
|
| 17 |
+
# RegaLabs-TTS: CosyVoice 3 Central Kurdish (Sorani) Adaptation
|
| 18 |
+
|
| 19 |
+
**RegaLabs-TTS** is a high-quality Central Kurdish (Sorani / سۆرانی) text-to-speech adaptation developed by **RegaLabs** based on **CosyVoice 3**.
|
| 20 |
+
|
| 21 |
+
* **Hugging Face Model:** [`RegaLabs/RegaLabs-TTS`](https://huggingface.co/RegaLabs/RegaLabs-TTS)
|
| 22 |
+
* **GitHub Repository:** [`RegaLabs/RegaLabs-TTS`](https://github.com/RegaLabs/RegaLabs-TTS)
|
| 23 |
+
|
| 24 |
+
---
|
| 25 |
+
|
| 26 |
+
## 🎧 Audio Example
|
| 27 |
+
|
| 28 |
+
Listen to a generated Sorani audio sample:
|
| 29 |
+
|
| 30 |
+
<audio controls src="https://huggingface.co/shahryyar/RegaLabs-TTS/resolve/main/samples/aran_en021.wav"></audio>
|
| 31 |
+
|
| 32 |
+
[🔊 Download Sample Audio WAV](https://huggingface.co/shahryyar/RegaLabs-TTS/resolve/main/samples/aran_en021.wav)
|
| 33 |
+
|
| 34 |
+
---
|
| 35 |
+
|
| 36 |
+
## 📊 Dataset & Model Capabilities
|
| 37 |
+
|
| 38 |
+
* **Dataset Volume:** Trained on **53 hours** of high-quality Sorani Kurdish speech data.
|
| 39 |
+
* **Male Speakers:** ~35–40 hours.
|
| 40 |
+
* **Female Speakers:** ~13–18 hours.
|
| 41 |
+
* **Voice Cloning Performance:**
|
| 42 |
+
* **Male Voices:** Evaluated and tested — clones male voices **flawlessly** with high similarity, prosody accuracy, and natural tone.
|
| 43 |
+
* **Female Voices:** Untested — zero-shot female voice cloning has not been evaluated yet.
|
| 44 |
+
|
| 45 |
+
---
|
| 46 |
+
|
| 47 |
+
## 💻 Installation & Usage
|
| 48 |
+
|
| 49 |
+
### 1. Install via `pip`
|
| 50 |
+
|
| 51 |
+
```bash
|
| 52 |
+
pip install git+https://github.com/RegaLabs/RegaLabs-TTS.git
|
| 53 |
+
```
|
| 54 |
+
|
| 55 |
+
### 2. Download Model Weights & Run Inference
|
| 56 |
+
|
| 57 |
+
```bash
|
| 58 |
+
# 1. Clone base engine
|
| 59 |
+
git clone --recursive https://github.com/FunAudioLLM/CosyVoice.git
|
| 60 |
+
cd CosyVoice
|
| 61 |
+
pip install -r requirements.txt
|
| 62 |
+
|
| 63 |
+
# 2. Clone RegaLabs-TTS model repo
|
| 64 |
+
git clone https://huggingface.co/RegaLabs/RegaLabs-TTS regalabs-tts-weights
|
| 65 |
+
|
| 66 |
+
# 3. Synthesize speech
|
| 67 |
+
python regalabs-tts-weights/infer.py \
|
| 68 |
+
--text "سڵاو، بەخێربێن بۆ پڕۆژەی RegaLabs-TTS" \
|
| 69 |
+
--prompt-wav regalabs-tts-weights/samples/aran_en021.wav \
|
| 70 |
+
--prompt-text "ئەمە دەنگی نموونەیە" \
|
| 71 |
+
--out output_sorani.wav
|
| 72 |
+
```
|
| 73 |
+
|
| 74 |
+
### 3. Launch Web Demo (Gradio)
|
| 75 |
+
|
| 76 |
+
```bash
|
| 77 |
+
python regalabs-tts-weights/app.py
|
| 78 |
+
```
|
| 79 |
+
|
| 80 |
+
---
|
| 81 |
+
|
| 82 |
+
## 📦 Model Artifacts
|
| 83 |
+
|
| 84 |
+
* `cosyvoice3_sorani_flow_best_step2300.pt` — Sorani acoustic/flow adaptation model weights (Step 2300).
|
| 85 |
+
* `cosyvoice3_sorani_flow_best_step2300.yaml` — Matching flow architecture configuration.
|
| 86 |
+
* `infer.py` — Ready-to-run Sorani inference script.
|
| 87 |
+
* `app.py` — Gradio Web UI Live Demo script.
|
| 88 |
+
* `samples/aran_en021.wav` — Sample generated audio snippet.
|
| 89 |
+
|
| 90 |
+
---
|
| 91 |
+
|
| 92 |
+
## 📜 License & Mandatory Attribution
|
| 93 |
+
|
| 94 |
+
Licensed under **Apache 2.0** by **RegaLabs**.
|
| 95 |
+
|
| 96 |
+
### 📌 Credit & Attribution Guidelines
|
| 97 |
+
Any public use, generated media (videos, podcasts, audiobooks, broadcasts, or AI services), software, or derivative works utilizing **RegaLabs-TTS** MUST explicitly provide visible credit to **RegaLabs**:
|
| 98 |
+
* **For Videos & Audio Content:** Include in description/credits: *"Voice synthesized using RegaLabs-TTS by RegaLabs"* or *"Audio powered by RegaLabs"*.
|
| 99 |
+
* **For Applications & Software:** Include attribution in application credits or about section.
|
app.py
ADDED
|
@@ -0,0 +1,188 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
import sys
|
| 3 |
+
from pathlib import Path
|
| 4 |
+
import torch
|
| 5 |
+
import soundfile as sf
|
| 6 |
+
import tempfile
|
| 7 |
+
import gradio as gr
|
| 8 |
+
|
| 9 |
+
# Ensure local imports and CosyVoice path are configured
|
| 10 |
+
ROOT_DIR = Path(__file__).parent.resolve()
|
| 11 |
+
sys.path.insert(0, str(ROOT_DIR))
|
| 12 |
+
|
| 13 |
+
# Ensure CosyVoice repo is accessible
|
| 14 |
+
COSYVOICE_REPO = os.environ.get("COSYVOICE_REPO", "./CosyVoice")
|
| 15 |
+
if os.path.exists(COSYVOICE_REPO):
|
| 16 |
+
sys.path.insert(0, COSYVOICE_REPO)
|
| 17 |
+
matcha_path = Path(COSYVOICE_REPO) / "third_party" / "Matcha-TTS"
|
| 18 |
+
if matcha_path.exists():
|
| 19 |
+
sys.path.insert(0, str(matcha_path))
|
| 20 |
+
|
| 21 |
+
# Sorani text normalizer fallback logic
|
| 22 |
+
try:
|
| 23 |
+
from sorani.frontend import normalize_sorani_text
|
| 24 |
+
except ImportError:
|
| 25 |
+
import unicodedata
|
| 26 |
+
import re
|
| 27 |
+
|
| 28 |
+
_CHARACTER_MAP = str.maketrans({"ك": "ک", "ي": "ی", "ى": "ی", "ة": "ە"})
|
| 29 |
+
def normalize_sorani_text(text: str) -> str:
|
| 30 |
+
if not text:
|
| 31 |
+
return ""
|
| 32 |
+
text = unicodedata.normalize("NFKC", text).translate(_CHARACTER_MAP)
|
| 33 |
+
text = re.sub(r"[\u064B-\u065F]", "", text)
|
| 34 |
+
return re.sub(r"\s+", " ", text).strip()
|
| 35 |
+
|
| 36 |
+
# Global model instance
|
| 37 |
+
COSYVOICE_MODEL = None
|
| 38 |
+
|
| 39 |
+
def get_model():
|
| 40 |
+
global COSYVOICE_MODEL
|
| 41 |
+
if COSYVOICE_MODEL is None:
|
| 42 |
+
try:
|
| 43 |
+
from cosyvoice.cli.cosyvoice import CosyVoice3
|
| 44 |
+
except ImportError:
|
| 45 |
+
raise RuntimeError(
|
| 46 |
+
"CosyVoice runtime not found. Please ensure CosyVoice is cloned: "
|
| 47 |
+
"git clone --recursive https://github.com/FunAudioLLM/CosyVoice.git"
|
| 48 |
+
)
|
| 49 |
+
|
| 50 |
+
base_model = "FunAudioLLM/Fun-CosyVoice3-0.5B-2512"
|
| 51 |
+
flow_ckpt = ROOT_DIR / "cosyvoice3_sorani_flow_best_step2300.pt"
|
| 52 |
+
|
| 53 |
+
print(f"Loading base CosyVoice model: {base_model}...")
|
| 54 |
+
device_fp16 = torch.cuda.is_available()
|
| 55 |
+
cosyvoice = CosyVoice3(base_model, fp16=device_fp16)
|
| 56 |
+
|
| 57 |
+
if flow_ckpt.exists():
|
| 58 |
+
print(f"Loading RegaLabs-TTS Sorani flow weights: {flow_ckpt}...")
|
| 59 |
+
flow_state = torch.load(flow_ckpt, map_location="cpu", weights_only=False)
|
| 60 |
+
if isinstance(flow_state, dict):
|
| 61 |
+
for key in ("model", "state_dict", "flow"):
|
| 62 |
+
nested = flow_state.get(key)
|
| 63 |
+
if isinstance(nested, dict):
|
| 64 |
+
flow_state = nested
|
| 65 |
+
break
|
| 66 |
+
flow_state = {k: v for k, v in flow_state.items() if isinstance(k, str) and isinstance(v, torch.Tensor)}
|
| 67 |
+
|
| 68 |
+
cosyvoice.model.flow.load_state_dict(flow_state, strict=False)
|
| 69 |
+
cosyvoice.model.flow.to(cosyvoice.model.device).eval()
|
| 70 |
+
print("Successfully loaded RegaLabs-TTS Sorani flow model.")
|
| 71 |
+
|
| 72 |
+
COSYVOICE_MODEL = cosyvoice
|
| 73 |
+
|
| 74 |
+
return COSYVOICE_MODEL
|
| 75 |
+
|
| 76 |
+
def synthesize_sorani(text, prompt_wav, prompt_text, speed, do_normalize):
|
| 77 |
+
if not text or not text.strip():
|
| 78 |
+
raise gr.Error("Please enter Sorani Kurdish text to synthesize.")
|
| 79 |
+
if not prompt_wav:
|
| 80 |
+
raise gr.Error("Please upload or select a reference prompt audio WAV.")
|
| 81 |
+
if not prompt_text or not prompt_text.strip():
|
| 82 |
+
raise gr.Error("Please provide the transcript text for the reference prompt audio.")
|
| 83 |
+
|
| 84 |
+
# Text Normalization
|
| 85 |
+
clean_text = normalize_sorani_text(text) if do_normalize else text.strip()
|
| 86 |
+
clean_prompt_text = normalize_sorani_text(prompt_text) if do_normalize else prompt_text.strip()
|
| 87 |
+
|
| 88 |
+
model = get_model()
|
| 89 |
+
|
| 90 |
+
pieces = []
|
| 91 |
+
with torch.inference_mode():
|
| 92 |
+
for output in model.inference_zero_shot(
|
| 93 |
+
clean_text,
|
| 94 |
+
clean_prompt_text,
|
| 95 |
+
prompt_wav,
|
| 96 |
+
stream=False,
|
| 97 |
+
speed=speed,
|
| 98 |
+
text_frontend=False,
|
| 99 |
+
):
|
| 100 |
+
pieces.append(output["tts_speech"].detach().cpu())
|
| 101 |
+
|
| 102 |
+
if not pieces:
|
| 103 |
+
raise RuntimeError("No audio was returned from the TTS model.")
|
| 104 |
+
|
| 105 |
+
speech = torch.cat(pieces, dim=1).squeeze(0).numpy()
|
| 106 |
+
|
| 107 |
+
with tempfile.NamedTemporaryFile(suffix=".wav", delete=False) as tmp_file:
|
| 108 |
+
sf.write(tmp_file.name, speech, model.sample_rate, subtype="PCM_16")
|
| 109 |
+
out_wav_path = tmp_file.name
|
| 110 |
+
|
| 111 |
+
return out_wav_path, f"✅ Synthesis complete! Normalized Text: '{clean_text}'"
|
| 112 |
+
|
| 113 |
+
# Default sample files
|
| 114 |
+
sample_wav = str(ROOT_DIR / "samples" / "aran_en021.wav") if (ROOT_DIR / "samples" / "aran_en021.wav").exists() else None
|
| 115 |
+
|
| 116 |
+
# Custom CSS
|
| 117 |
+
custom_css = """
|
| 118 |
+
.container { max-width: 900px; margin: auto; }
|
| 119 |
+
.header { text-align: center; margin-bottom: 20px; }
|
| 120 |
+
.attribution { background-color: #1a1a24; border-radius: 8px; padding: 15px; margin-top: 25px; border-left: 4px solid #6366f1; }
|
| 121 |
+
"""
|
| 122 |
+
|
| 123 |
+
with gr.Blocks(title="RegaLabs-TTS: Sorani Speech Synthesis", css=custom_css) as demo:
|
| 124 |
+
gr.Markdown(
|
| 125 |
+
"""
|
| 126 |
+
# 🎙️ RegaLabs-TTS: Central Kurdish (Sorani) Speech Synthesis
|
| 127 |
+
**CosyVoice 3 Zero-Shot TTS & Voice Cloning Adaptation for Sorani Kurdish (سۆرانی)**
|
| 128 |
+
Developed by **[RegaLabs](https://huggingface.co/RegaLabs)**
|
| 129 |
+
""",
|
| 130 |
+
elem_classes=["header"]
|
| 131 |
+
)
|
| 132 |
+
|
| 133 |
+
with gr.Row():
|
| 134 |
+
with gr.Column(scale=1):
|
| 135 |
+
text_input = gr.Textbox(
|
| 136 |
+
label="Sorani Text (دەقی سۆرانی)",
|
| 137 |
+
placeholder="سڵاو، بەخێربێن بۆ تاقیکردنەوەی دەنگی RegaLabs-TTS...",
|
| 138 |
+
value="سڵاو، بەخێربێن بۆ تاقیکردنەوەی دەنگی RegaLabs-TTS",
|
| 139 |
+
lines=4,
|
| 140 |
+
)
|
| 141 |
+
|
| 142 |
+
prompt_audio = gr.Audio(
|
| 143 |
+
label="Reference Voice Audio (دەنگی نموونە)",
|
| 144 |
+
type="filepath",
|
| 145 |
+
value=sample_wav,
|
| 146 |
+
)
|
| 147 |
+
|
| 148 |
+
prompt_text_input = gr.Textbox(
|
| 149 |
+
label="Reference Voice Transcript (دەقی دەنگی نموونەکە)",
|
| 150 |
+
placeholder="ئەمە دەنگی نموونەیە",
|
| 151 |
+
value="ئەمە دەنگی نموونەیە",
|
| 152 |
+
lines=2,
|
| 153 |
+
)
|
| 154 |
+
|
| 155 |
+
with gr.Accordion("Advanced Options (ڕێکخستنەکان)", open=False):
|
| 156 |
+
speed_slider = gr.Slider(
|
| 157 |
+
minimum=0.5, maximum=1.5, value=1.0, step=0.05, label="Speech Speed (خێرایی خوێندنەوە)"
|
| 158 |
+
)
|
| 159 |
+
normalize_check = gr.Checkbox(
|
| 160 |
+
value=True, label="Enable Sorani Text Normalization (ڕێکخستنی دەق)"
|
| 161 |
+
)
|
| 162 |
+
|
| 163 |
+
generate_btn = gr.Button("🎤 Synthesize Sorani Speech (دروستکردنی دەنگ)", variant="primary", size="lg")
|
| 164 |
+
|
| 165 |
+
with gr.Column(scale=1):
|
| 166 |
+
audio_output = gr.Audio(label="Synthesized Sorani Speech (دەنگی دروستکراو)", type="filepath")
|
| 167 |
+
status_output = gr.Textbox(label="Status & Info", interactive=False)
|
| 168 |
+
|
| 169 |
+
generate_btn.click(
|
| 170 |
+
fn=synthesize_sorani,
|
| 171 |
+
inputs=[text_input, prompt_audio, prompt_text_input, speed_slider, normalize_check],
|
| 172 |
+
outputs=[audio_output, status_output],
|
| 173 |
+
)
|
| 174 |
+
|
| 175 |
+
gr.Markdown(
|
| 176 |
+
"""
|
| 177 |
+
---
|
| 178 |
+
### 📜 License & Mandatory Attribution
|
| 179 |
+
**RegaLabs-TTS** is released by **RegaLabs** under Apache 2.0.
|
| 180 |
+
|
| 181 |
+
**📌 Attribution Requirement:** Any public use, generated media (videos, podcasts, voiceovers, radio/TV), applications, or derivative works MUST explicitly credit **RegaLabs**:
|
| 182 |
+
> *"Voice synthesized using RegaLabs-TTS by RegaLabs"* (or *"Audio powered by RegaLabs"*).
|
| 183 |
+
""",
|
| 184 |
+
elem_classes=["attribution"]
|
| 185 |
+
)
|
| 186 |
+
|
| 187 |
+
if __name__ == "__main__":
|
| 188 |
+
demo.launch(server_name="0.0.0.0", server_port=7860)
|
cosyvoice3_sorani_flow_best_step2300.pt
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:033abd6fcb88c8069a24ac7215dfaac92b2526ee687a05dc0e327693a1cea75c
|
| 3 |
+
size 1329146699
|
cosyvoice3_sorani_flow_best_step2300.yaml
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Sanitized release metadata for the accompanying flow checkpoint.
|
| 2 |
+
# Private dataset, manifest, host, and experiment paths are intentionally omitted.
|
| 3 |
+
model: flow
|
| 4 |
+
base_model: Fun-CosyVoice3-0.5B
|
| 5 |
+
adaptation: Central Kurdish (Sorani) acoustic/flow adaptation
|
| 6 |
+
checkpoint_step: 2300
|
| 7 |
+
epoch: 0
|
| 8 |
+
dtype: bf16
|
| 9 |
+
learning_rate: 5.0e-6
|
| 10 |
+
save_per_step: 100
|
| 11 |
+
lora: false
|
infer.py
ADDED
|
@@ -0,0 +1,76 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env python3
|
| 2 |
+
"""RegaLabs-TTS: Direct Hugging Face Sorani Text-to-Speech Inference Script."""
|
| 3 |
+
|
| 4 |
+
import argparse
|
| 5 |
+
import sys
|
| 6 |
+
import os
|
| 7 |
+
from pathlib import Path
|
| 8 |
+
import torch
|
| 9 |
+
import soundfile as sf
|
| 10 |
+
|
| 11 |
+
def parse_args():
|
| 12 |
+
parser = argparse.ArgumentParser(description="RegaLabs-TTS Sorani Speech Synthesis")
|
| 13 |
+
parser.add_argument("--text", required=True, help="Sorani text to synthesize")
|
| 14 |
+
parser.add_argument("--prompt-wav", required=True, help="Path to reference audio WAV")
|
| 15 |
+
parser.add_argument("--prompt-text", required=True, help="Transcript of reference audio prompt")
|
| 16 |
+
parser.add_argument("--flow-checkpoint", default=str(Path(__file__).parent / "cosyvoice3_sorani_flow_best_step2300.pt"), help="Path to flow checkpoint")
|
| 17 |
+
parser.add_argument("--base-model", default="FunAudioLLM/Fun-CosyVoice3-0.5B-2512", help="Hugging Face base model ID")
|
| 18 |
+
parser.add_argument("--out", default="output_sorani.wav", help="Output WAV path")
|
| 19 |
+
parser.add_argument("--cosyvoice-repo", default=os.environ.get("COSYVOICE_REPO", "./CosyVoice"), help="Path to cloned CosyVoice repo")
|
| 20 |
+
return parser.parse_args()
|
| 21 |
+
|
| 22 |
+
def main():
|
| 23 |
+
args = parse_args()
|
| 24 |
+
|
| 25 |
+
repo = Path(args.cosyvoice_repo).resolve()
|
| 26 |
+
if not repo.exists():
|
| 27 |
+
print(f"Error: CosyVoice engine directory not found at {repo}.", file=sys.stderr)
|
| 28 |
+
print("Please clone CosyVoice: git clone --recursive https://github.com/FunAudioLLM/CosyVoice.git", file=sys.stderr)
|
| 29 |
+
sys.exit(1)
|
| 30 |
+
|
| 31 |
+
sys.path.insert(0, str(repo))
|
| 32 |
+
matcha_path = repo / "third_party" / "Matcha-TTS"
|
| 33 |
+
if matcha_path.exists():
|
| 34 |
+
sys.path.insert(0, str(matcha_path))
|
| 35 |
+
|
| 36 |
+
from cosyvoice.cli.cosyvoice import CosyVoice3
|
| 37 |
+
|
| 38 |
+
print(f"Loading base model: {args.base_model}...")
|
| 39 |
+
cosyvoice = CosyVoice3(args.base_model, fp16=torch.cuda.is_available())
|
| 40 |
+
|
| 41 |
+
print(f"Loading RegaLabs-TTS Sorani flow checkpoint: {args.flow_checkpoint}...")
|
| 42 |
+
flow_state = torch.load(args.flow_checkpoint, map_location="cpu", weights_only=False)
|
| 43 |
+
if isinstance(flow_state, dict):
|
| 44 |
+
for key in ("model", "state_dict", "flow"):
|
| 45 |
+
nested = flow_state.get(key)
|
| 46 |
+
if isinstance(nested, dict):
|
| 47 |
+
flow_state = nested
|
| 48 |
+
break
|
| 49 |
+
flow_state = {k: v for k, v in flow_state.items() if isinstance(k, str) and isinstance(v, torch.Tensor)}
|
| 50 |
+
|
| 51 |
+
cosyvoice.model.flow.load_state_dict(flow_state, strict=False)
|
| 52 |
+
cosyvoice.model.flow.to(cosyvoice.model.device).eval()
|
| 53 |
+
|
| 54 |
+
print(f"Synthesizing Sorani text: '{args.text}'...")
|
| 55 |
+
pieces = []
|
| 56 |
+
with torch.inference_mode():
|
| 57 |
+
for output in cosyvoice.inference_zero_shot(
|
| 58 |
+
args.text,
|
| 59 |
+
args.prompt_text,
|
| 60 |
+
args.prompt_wav,
|
| 61 |
+
stream=False,
|
| 62 |
+
text_frontend=False,
|
| 63 |
+
):
|
| 64 |
+
pieces.append(output["tts_speech"].detach().cpu())
|
| 65 |
+
|
| 66 |
+
if not pieces:
|
| 67 |
+
raise RuntimeError("No audio output returned.")
|
| 68 |
+
|
| 69 |
+
speech = torch.cat(pieces, dim=1).squeeze(0).numpy()
|
| 70 |
+
out_path = Path(args.out)
|
| 71 |
+
out_path.parent.mkdir(parents=True, exist_ok=True)
|
| 72 |
+
sf.write(out_path, speech, cosyvoice.sample_rate, subtype="PCM_16")
|
| 73 |
+
print(f"✅ Audio generated successfully: {out_path}")
|
| 74 |
+
|
| 75 |
+
if __name__ == "__main__":
|
| 76 |
+
main()
|
samples/aran_en021.wav
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:7c5dbd441ecea4bcc97498d01c8e7d5c946a3b10c84fa0a3d735b14bb7d5ac5d
|
| 3 |
+
size 288044
|
sorani/__init__.py
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""RegaLabs-TTS Sorani Kurdish Text-to-Speech Package."""
|
| 2 |
+
|
| 3 |
+
from .frontend import normalize_sorani_text, normalize_kurdish_text, number_to_sorani
|
| 4 |
+
|
| 5 |
+
__version__ = "1.0.0"
|
| 6 |
+
__all__ = ["normalize_sorani_text", "normalize_kurdish_text", "number_to_sorani"]
|
sorani/frontend.py
ADDED
|
@@ -0,0 +1,119 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env python3
|
| 2 |
+
"""Conservative Central Kurdish (Sorani) text normalization.
|
| 3 |
+
|
| 4 |
+
This frontend deliberately does not apply contextual ``ه`` -> ``ھ`` guesses.
|
| 5 |
+
Both characters occur in Kurdish text, and changing one without a lexicon can
|
| 6 |
+
alter the model's learned pronunciation. User-confirmed spelling is preserved
|
| 7 |
+
unless it is an unambiguous Arabic/Persian codepoint variant.
|
| 8 |
+
"""
|
| 9 |
+
|
| 10 |
+
from __future__ import annotations
|
| 11 |
+
|
| 12 |
+
import re
|
| 13 |
+
import unicodedata
|
| 14 |
+
|
| 15 |
+
|
| 16 |
+
_CHARACTER_MAP = str.maketrans({
|
| 17 |
+
"ك": "ک", # Arabic kaf -> Kurdish kaf
|
| 18 |
+
"ي": "ی", # Arabic yeh -> Kurdish yeh
|
| 19 |
+
"ى": "ی", # alef maksura -> Kurdish yeh
|
| 20 |
+
"ة": "ە", # teh marbuta -> Kurdish ae
|
| 21 |
+
})
|
| 22 |
+
|
| 23 |
+
_DIGIT_MAP = str.maketrans({
|
| 24 |
+
"٠": "0", "١": "1", "٢": "2", "٣": "3", "٤": "4",
|
| 25 |
+
"٥": "5", "٦": "6", "٧": "7", "٨": "8", "٩": "9",
|
| 26 |
+
"۰": "0", "۱": "1", "۲": "2", "۳": "3", "۴": "4",
|
| 27 |
+
"۵": "5", "۶": "6", "۷": "7", "۸": "8", "۹": "9",
|
| 28 |
+
})
|
| 29 |
+
|
| 30 |
+
_DIGIT_WORDS = {
|
| 31 |
+
"0": "سفر", "1": "یەک", "2": "دوو", "3": "سێ", "4": "چوار",
|
| 32 |
+
"5": "پێنج", "6": "شەش", "7": "حەوت", "8": "هەشت", "9": "نۆ",
|
| 33 |
+
}
|
| 34 |
+
_UNDER_20 = {
|
| 35 |
+
0: "سفر", 1: "یەک", 2: "دوو", 3: "سێ", 4: "چوار", 5: "پێنج",
|
| 36 |
+
6: "شەش", 7: "حەوت", 8: "هەشت", 9: "نۆ", 10: "دە", 11: "یازدە",
|
| 37 |
+
12: "دوازدە", 13: "سێزدە", 14: "چواردە", 15: "پازدە", 16: "شازدە",
|
| 38 |
+
17: "حەڤدە", 18: "هەژدە", 19: "نۆزدە",
|
| 39 |
+
}
|
| 40 |
+
_TENS = {20: "بیست", 30: "سی", 40: "چل", 50: "پەنجا", 60: "شەست",
|
| 41 |
+
70: "حەفتا", 80: "هەشتا", 90: "نەوەد"}
|
| 42 |
+
_HUNDREDS = {
|
| 43 |
+
100: "سەد", 200: "دووسەد", 300: "سێسەد", 400: "چوارسەد",
|
| 44 |
+
500: "پێنجسەد", 600: "شەشسەد", 700: "حەوتسەد", 800: "هەشتسەد",
|
| 45 |
+
900: "نۆسەد",
|
| 46 |
+
}
|
| 47 |
+
|
| 48 |
+
|
| 49 |
+
def number_to_sorani(number: int) -> str:
|
| 50 |
+
"""Spell ordinary integers without changing the spelling of input words."""
|
| 51 |
+
if number < 0:
|
| 52 |
+
return "نێگەتیڤ و " + number_to_sorani(-number)
|
| 53 |
+
if number < 20:
|
| 54 |
+
return _UNDER_20[number]
|
| 55 |
+
if number < 100:
|
| 56 |
+
tens, units = divmod(number, 10)
|
| 57 |
+
return _TENS[tens * 10] + (f" و {_UNDER_20[units]}" if units else "")
|
| 58 |
+
if number < 1000:
|
| 59 |
+
hundreds, remainder = divmod(number, 100)
|
| 60 |
+
result = _HUNDREDS[hundreds * 100]
|
| 61 |
+
return result + (f" و {number_to_sorani(remainder)}" if remainder else "")
|
| 62 |
+
if number < 1_000_000:
|
| 63 |
+
thousands, remainder = divmod(number, 1000)
|
| 64 |
+
result = ("هەزار" if thousands == 1 else f"{number_to_sorani(thousands)} هەزار")
|
| 65 |
+
return result + (f" و {number_to_sorani(remainder)}" if remainder else "")
|
| 66 |
+
if number < 1_000_000_000:
|
| 67 |
+
millions, remainder = divmod(number, 1_000_000)
|
| 68 |
+
result = f"{number_to_sorani(millions)} ملیۆن"
|
| 69 |
+
return result + (f" و {number_to_sorani(remainder)}" if remainder else "")
|
| 70 |
+
billions, remainder = divmod(number, 1_000_000_000)
|
| 71 |
+
result = f"{number_to_sorani(billions)} ملیار"
|
| 72 |
+
return result + (f" و {number_to_sorani(remainder)}" if remainder else "")
|
| 73 |
+
|
| 74 |
+
|
| 75 |
+
def _replace_number(match: re.Match[str]) -> str:
|
| 76 |
+
value = match.group(0)
|
| 77 |
+
digits = value.lstrip("-")
|
| 78 |
+
if len(digits) >= 10 or (len(digits) > 1 and digits.startswith("0")):
|
| 79 |
+
words = " ".join(_DIGIT_WORDS[digit] for digit in digits)
|
| 80 |
+
return f"نێگەتیڤ {words}" if value.startswith("-") else words
|
| 81 |
+
return number_to_sorani(int(value))
|
| 82 |
+
|
| 83 |
+
|
| 84 |
+
def expand_numbers(text: str) -> str:
|
| 85 |
+
text = text.translate(_DIGIT_MAP)
|
| 86 |
+
text = re.sub(r"(?<=\d)[,،](?=\d{3}(?!\d))", "", text)
|
| 87 |
+
text = re.sub(r"(?<=\d)[,،](?=\d)", ".", text)
|
| 88 |
+
text = re.sub(r"(\d+(?:\.\d+)?)\s*[%٪]", r"\1 لەسەد", text)
|
| 89 |
+
text = re.sub(r"(\d+(?:\.\d+)?)\s*\$", r"\1 دۆلار", text)
|
| 90 |
+
|
| 91 |
+
def replace_decimal(match: re.Match[str]) -> str:
|
| 92 |
+
integer, fraction = match.group(0).split(".", 1)
|
| 93 |
+
digits = " ".join(_DIGIT_WORDS[digit] for digit in fraction)
|
| 94 |
+
return f"{number_to_sorani(int(integer))} پۆینت {digits}"
|
| 95 |
+
|
| 96 |
+
text = re.sub(r"(?<!\w)-?\d+\.\d+", replace_decimal, text)
|
| 97 |
+
return re.sub(r"(?<!\w)-?\d+", _replace_number, text)
|
| 98 |
+
|
| 99 |
+
|
| 100 |
+
def normalize_sorani_text(text: str) -> str:
|
| 101 |
+
"""Normalize safe orthographic variants while preserving Kurdish spelling."""
|
| 102 |
+
if not text:
|
| 103 |
+
return ""
|
| 104 |
+
text = unicodedata.normalize("NFKC", text).translate(_CHARACTER_MAP)
|
| 105 |
+
text = re.sub(r"[\u064B-\u065F]", "", text)
|
| 106 |
+
text = expand_numbers(text)
|
| 107 |
+
text = text.replace("؟", "؟").replace("?", "؟")
|
| 108 |
+
text = text.replace(";", "؛").replace(",", "،")
|
| 109 |
+
return re.sub(r"\s+", " ", text).strip()
|
| 110 |
+
|
| 111 |
+
|
| 112 |
+
normalize_kurdish_text = normalize_sorani_text
|
| 113 |
+
|
| 114 |
+
|
| 115 |
+
if __name__ == "__main__":
|
| 116 |
+
assert normalize_sorani_text("هێشتا") == "هێشتا"
|
| 117 |
+
assert normalize_sorani_text("ك ى ة") == "ک ی ە"
|
| 118 |
+
assert normalize_sorani_text("2026") == "دوو هەزار و بیست و شەش"
|
| 119 |
+
print("conservative Sorani frontend self-check passed")
|