Model: 2026-11-19
Browse filesTrained 118k steps on the tiny-broca dataset (see runs/eval-ft2/report.json)
- .gitattributes +16 -0
- LICENSE.md +202 -0
- README.md +215 -0
- config.json +37 -0
- onnx/model.onnx +3 -0
- samples/F1-0.wav +3 -0
- samples/F1-1.wav +3 -0
- samples/F1-2.wav +3 -0
- samples/F1-3.wav +3 -0
- samples/F1-4.wav +3 -0
- samples/F1-5.wav +3 -0
- samples/F1-6.wav +3 -0
- samples/F1-7.wav +3 -0
- samples/M1-0.wav +3 -0
- samples/M1-1.wav +3 -0
- samples/M1-2.wav +3 -0
- samples/M1-3.wav +3 -0
- samples/M1-4.wav +3 -0
- samples/M1-5.wav +3 -0
- samples/M1-6.wav +3 -0
- samples/M1-7.wav +3 -0
- text.py +436 -0
- tiny-broca.pt +3 -0
.gitattributes
CHANGED
|
@@ -33,3 +33,19 @@ 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/F1-0.wav filter=lfs diff=lfs merge=lfs -text
|
| 37 |
+
samples/F1-1.wav filter=lfs diff=lfs merge=lfs -text
|
| 38 |
+
samples/F1-2.wav filter=lfs diff=lfs merge=lfs -text
|
| 39 |
+
samples/F1-3.wav filter=lfs diff=lfs merge=lfs -text
|
| 40 |
+
samples/F1-4.wav filter=lfs diff=lfs merge=lfs -text
|
| 41 |
+
samples/F1-5.wav filter=lfs diff=lfs merge=lfs -text
|
| 42 |
+
samples/F1-6.wav filter=lfs diff=lfs merge=lfs -text
|
| 43 |
+
samples/F1-7.wav filter=lfs diff=lfs merge=lfs -text
|
| 44 |
+
samples/M1-0.wav filter=lfs diff=lfs merge=lfs -text
|
| 45 |
+
samples/M1-1.wav filter=lfs diff=lfs merge=lfs -text
|
| 46 |
+
samples/M1-2.wav filter=lfs diff=lfs merge=lfs -text
|
| 47 |
+
samples/M1-3.wav filter=lfs diff=lfs merge=lfs -text
|
| 48 |
+
samples/M1-4.wav filter=lfs diff=lfs merge=lfs -text
|
| 49 |
+
samples/M1-5.wav filter=lfs diff=lfs merge=lfs -text
|
| 50 |
+
samples/M1-6.wav filter=lfs diff=lfs merge=lfs -text
|
| 51 |
+
samples/M1-7.wav filter=lfs diff=lfs merge=lfs -text
|
LICENSE.md
ADDED
|
@@ -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 [yyyy] [name of copyright owner]
|
| 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.
|
README.md
ADDED
|
@@ -0,0 +1,215 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
license: apache-2.0
|
| 3 |
+
language:
|
| 4 |
+
- pt
|
| 5 |
+
pipeline_tag: text-to-speech
|
| 6 |
+
tags:
|
| 7 |
+
- text-to-speech
|
| 8 |
+
- onnx
|
| 9 |
+
- portuguese
|
| 10 |
+
datasets:
|
| 11 |
+
- brenorb/tiny-broca
|
| 12 |
+
---
|
| 13 |
+
# tiny-broca
|
| 14 |
+
|
| 15 |
+
tiny-broca is a small **Brazilian Portuguese** text-to-speech model with two
|
| 16 |
+
voices, F1 (female) and M1 (male). The complete model, including the waveform
|
| 17 |
+
generator, has 4.5M parameters and was trained from scratch on 17 hours
|
| 18 |
+
of synthetic speech.
|
| 19 |
+
|
| 20 |
+
<audio controls src="https://huggingface.co/brenorb/tiny-broca/resolve/main/samples/F1-1.wav"></audio>
|
| 21 |
+
|
| 22 |
+
- Code: https://github.com/brenorb/tiny-broca
|
| 23 |
+
- Dataset: https://huggingface.co/datasets/brenorb/tiny-broca
|
| 24 |
+
|
| 25 |
+
| | |
|
| 26 |
+
|---|---|
|
| 27 |
+
| Parameters | 4,533,835 |
|
| 28 |
+
| Voices | F1, M1 (Brazilian Portuguese) |
|
| 29 |
+
| Output | 24 kHz mono |
|
| 30 |
+
| Input | Text, tokenised as letters (58 symbols), no dictionary |
|
| 31 |
+
| Pretrained weights in the model | None |
|
| 32 |
+
| License | Apache-2.0 |
|
| 33 |
+
|
| 34 |
+
## Files
|
| 35 |
+
|
| 36 |
+
| File | Contents |
|
| 37 |
+
|---|---|
|
| 38 |
+
| `tiny-broca.pt` | PyTorch weights, float32 |
|
| 39 |
+
| `onnx/model.onnx` | ONNX export, float32, opset 17 |
|
| 40 |
+
| `config.json` | Model settings: sample rate, windows, voices, vocabulary size |
|
| 41 |
+
| `text.py` | The front end module, verbatim (the web demo runs it in the browser) |
|
| 42 |
+
| `samples/` | The audio on this page |
|
| 43 |
+
|
| 44 |
+
## Samples
|
| 45 |
+
|
| 46 |
+
| Text | F1 | M1 |
|
| 47 |
+
|---|---|---|
|
| 48 |
+
| A reunião de amanhã foi remarcada para as quinze horas e quinze. | <audio controls src="https://huggingface.co/brenorb/tiny-broca/resolve/main/samples/F1-0.wav"></audio> | <audio controls src="https://huggingface.co/brenorb/tiny-broca/resolve/main/samples/M1-0.wav"></audio> |
|
| 49 |
+
| Ligue para a sua avó antes que comece o fim de semana, por favor. | <audio controls src="https://huggingface.co/brenorb/tiny-broca/resolve/main/samples/F1-1.wav"></audio> | <audio controls src="https://huggingface.co/brenorb/tiny-broca/resolve/main/samples/M1-1.wav"></audio> |
|
| 50 |
+
| Quantas pessoas vão à conferência em setembro? | <audio controls src="https://huggingface.co/brenorb/tiny-broca/resolve/main/samples/F1-2.wav"></audio> | <audio controls src="https://huggingface.co/brenorb/tiny-broca/resolve/main/samples/M1-2.wav"></audio> |
|
| 51 |
+
| Não acredito que já é meia-noite e meia; devemos ir embora agora! | <audio controls src="https://huggingface.co/brenorb/tiny-broca/resolve/main/samples/F1-3.wav"></audio> | <audio controls src="https://huggingface.co/brenorb/tiny-broca/resolve/main/samples/M1-3.wav"></audio> |
|
| 52 |
+
| A tiny broca é um pequeno modelo de texto para fala treinado do zero. | <audio controls src="https://huggingface.co/brenorb/tiny-broca/resolve/main/samples/F1-4.wav"></audio> | <audio controls src="https://huggingface.co/brenorb/tiny-broca/resolve/main/samples/M1-4.wav"></audio> |
|
| 53 |
+
| Depois da tempestade, o ar da montanha parecia fresco, limpo e surpreendentemente quente. | <audio controls src="https://huggingface.co/brenorb/tiny-broca/resolve/main/samples/F1-5.wav"></audio> | <audio controls src="https://huggingface.co/brenorb/tiny-broca/resolve/main/samples/M1-5.wav"></audio> |
|
| 54 |
+
| Você pode me enviar o relatório até sexta-feira à tarde, por favor? | <audio controls src="https://huggingface.co/brenorb/tiny-broca/resolve/main/samples/F1-6.wav"></audio> | <audio controls src="https://huggingface.co/brenorb/tiny-broca/resolve/main/samples/M1-6.wav"></audio> |
|
| 55 |
+
| A conta do aluguel fechou em mil duzentos e quarenta e cinco reais e dez centavos. | <audio controls src="https://huggingface.co/brenorb/tiny-broca/resolve/main/samples/F1-7.wav"></audio> | <audio controls src="https://huggingface.co/brenorb/tiny-broca/resolve/main/samples/M1-7.wav"></audio> |
|
| 56 |
+
|
| 57 |
+
## Usage
|
| 58 |
+
|
| 59 |
+
### PyTorch
|
| 60 |
+
|
| 61 |
+
```bash
|
| 62 |
+
pip install git+https://github.com/brenorb/tiny-broca
|
| 63 |
+
hf download brenorb/tiny-broca --local-dir tiny-broca
|
| 64 |
+
|
| 65 |
+
python -m tiny_broca.infer \
|
| 66 |
+
--checkpoint tiny-broca/tiny-broca.pt \
|
| 67 |
+
--voice F1 \
|
| 68 |
+
--text "Olá! Eu sou a tiny broca." \
|
| 69 |
+
--output ola.wav
|
| 70 |
+
```
|
| 71 |
+
|
| 72 |
+
| Option | Default | Meaning |
|
| 73 |
+
|---|---|---|
|
| 74 |
+
| `--voice` | `F1` | `F1` or `M1` |
|
| 75 |
+
| `--speed` | 1.0 | Speaking rate |
|
| 76 |
+
| `--pitch-shift` | 0 | Added to log F0. 0.058 is about one semitone. |
|
| 77 |
+
| `--pitch-range` | 1.0 | Scales pitch movement around the utterance mean. |
|
| 78 |
+
|
| 79 |
+
### ONNX
|
| 80 |
+
|
| 81 |
+
The graph takes letter ids and stress values and returns the waveform. Text is
|
| 82 |
+
converted to ids outside the graph by the front end (`text.py`); the ids are
|
| 83 |
+
the positions in its letter inventory.
|
| 84 |
+
|
| 85 |
+
```python
|
| 86 |
+
import numpy as np
|
| 87 |
+
import onnxruntime as ort
|
| 88 |
+
import soundfile as sf
|
| 89 |
+
import sys
|
| 90 |
+
sys.path.insert(0, "tiny-broca")
|
| 91 |
+
from text import phonemize, SYMBOL_TO_ID
|
| 92 |
+
|
| 93 |
+
letters = phonemize("Olá! Eu sou a tiny broca.")
|
| 94 |
+
one = lambda value: np.array([value], dtype=np.float32)
|
| 95 |
+
|
| 96 |
+
session = ort.InferenceSession("tiny-broca/onnx/model.onnx")
|
| 97 |
+
audio, durations = session.run(None, {
|
| 98 |
+
"tokens": np.array([letters.ids], dtype=np.int64),
|
| 99 |
+
"stress": np.array([letters.stress], dtype=np.int64),
|
| 100 |
+
"voice": np.array([0], dtype=np.int64), # 0 = F1, 1 = M1
|
| 101 |
+
"speed": one(1.0),
|
| 102 |
+
"pitch_shift": one(0.0),
|
| 103 |
+
"pitch_range": one(1.0),
|
| 104 |
+
})
|
| 105 |
+
sf.write("ola.wav", audio[0], 24000)
|
| 106 |
+
```
|
| 107 |
+
|
| 108 |
+
| Input | Type | Shape | Meaning |
|
| 109 |
+
|---|---|---|---|
|
| 110 |
+
| `tokens` | int64 | [1, N] | Letter ids, including the start and end tokens |
|
| 111 |
+
| `stress` | int64 | [1, N] | 0 unstressed, 1 stressed syllable |
|
| 112 |
+
| `voice` | int64 | [1] | 0 = F1, 1 = M1 |
|
| 113 |
+
| `speed` | float32 | [1] | 1.0 as predicted; larger is faster |
|
| 114 |
+
| `pitch_shift` | float32 | [1] | Added to log F0 |
|
| 115 |
+
| `pitch_range` | float32 | [1] | Scales pitch movement |
|
| 116 |
+
|
| 117 |
+
| Output | Type | Shape | Meaning |
|
| 118 |
+
|---|---|---|---|
|
| 119 |
+
| `audio` | float32 | [1, samples] | Waveform at 24 kHz |
|
| 120 |
+
| `durations` | int64 | [1, N] | Length of each token in frames of 256 samples |
|
| 121 |
+
|
| 122 |
+
The model reads one utterance per call, up to 512 tokens and 32 seconds. Split
|
| 123 |
+
longer text into sentences. The same file runs in onnxruntime-web
|
| 124 |
+
(WebAssembly); the page at the demo URL speaks in the browser.
|
| 125 |
+
|
| 126 |
+
## Model
|
| 127 |
+
|
| 128 |
+
Text is tokenised as letters (the 26 letters plus the accented graphemes that
|
| 129 |
+
are distinct letters in Portuguese), with a stress value per letter. A
|
| 130 |
+
transformer encoder (4 blocks) reads the letters, a duration predictor gives
|
| 131 |
+
each one a length in frames, and two frame-level transformers (2 and 5 blocks)
|
| 132 |
+
predict pitch, voicing and energy and then the parameters of the waveform
|
| 133 |
+
generator. All blocks use 192 channels, 4 heads and rotary position
|
| 134 |
+
embeddings.
|
| 135 |
+
|
| 136 |
+
The waveform is produced by a source-filter synthesizer instead of a neural
|
| 137 |
+
vocoder. A band-limited pulse train at the predicted pitch and a noise signal
|
| 138 |
+
are each shaped by a time-varying filter, whose cepstrum the network predicts
|
| 139 |
+
once per frame (256 samples, 10.7 ms). This part has 25,862 parameters.
|
| 140 |
+
|
| 141 |
+
| Component | Parameters |
|
| 142 |
+
|---|---:|
|
| 143 |
+
| Embeddings (letter, stress, voice) | 13,248 |
|
| 144 |
+
| Text encoder | 1,588,864 |
|
| 145 |
+
| Duration and pause predictor | 123,906 |
|
| 146 |
+
| Frame transformer A, prosody head | 795,971 |
|
| 147 |
+
| Frame transformer B | 1,985,984 |
|
| 148 |
+
| Source-filter waveform head | 25,862 |
|
| 149 |
+
| Total | 4,533,835 |
|
| 150 |
+
|
| 151 |
+
## Training
|
| 152 |
+
|
| 153 |
+
| | |
|
| 154 |
+
|---|---|
|
| 155 |
+
| Data | [brenorb/tiny-broca](https://huggingface.co/datasets/brenorb/tiny-broca): 9,384 sentences, 16,434 clips, two voices |
|
| 156 |
+
| Steps | 118,000 |
|
| 157 |
+
| Losses | Multi-resolution spectral losses; adversarial loss with multi-period and multi-resolution discriminators after step 8,000 |
|
| 158 |
+
| Hardware | Apple M4 Pro, 18-core, MPS |
|
| 159 |
+
|
| 160 |
+
The training audio is synthetic: every clip was generated with Qwen3-TTS 1.7B
|
| 161 |
+
Base (Apache-2.0) in one of the two voices. The voices are clones of two
|
| 162 |
+
Common Voice speakers (CC0): short clean recordings of real people, used only
|
| 163 |
+
as voice prompts for the generator. No recording of a real speaker is part of
|
| 164 |
+
the model. Letter durations come from forced alignment with
|
| 165 |
+
`jonatasgrosman/wav2vec2-xls-r-1b-portuguese`, which is used only to label
|
| 166 |
+
the training data. No pretrained weights are part of the model.
|
| 167 |
+
|
| 168 |
+
The first 104,000 steps use `batch1` and `batch2`. The released model then
|
| 169 |
+
continues for 14,000 more steps (to step 118,000) on the same data plus
|
| 170 |
+
`batch3`, money phrases: the generator tends to rush long number strings, so
|
| 171 |
+
the later rounds give money values extra weight.
|
| 172 |
+
|
| 173 |
+
## Evaluation
|
| 174 |
+
|
| 175 |
+
Word error rate of synthesized speech, transcribed with Whisper
|
| 176 |
+
(multilingual, pt). The recordings of the same sentences are scored the same
|
| 177 |
+
way for reference. (Pending the training run.)
|
| 178 |
+
|
| 179 |
+
## Limitations
|
| 180 |
+
|
| 181 |
+
- Brazilian Portuguese only, two fixed voices, no voice cloning.
|
| 182 |
+
- The voice is clear but can sound slightly synthetic.
|
| 183 |
+
- The same text is always read the same way. There is no sampling of prosody.
|
| 184 |
+
- Very long number strings (a dozen or more words) are read a little faster
|
| 185 |
+
than the training data; the duration predictor compresses them slightly.
|
| 186 |
+
- Foreign names and unusual spellings are often mispronounced.
|
| 187 |
+
- No streaming.
|
| 188 |
+
- The training data is itself synthetic, so the model cannot be more natural
|
| 189 |
+
than the model that generated it.
|
| 190 |
+
|
| 191 |
+
## License
|
| 192 |
+
|
| 193 |
+
The weights and code are released under Apache-2.0. No pronouncing dictionary
|
| 194 |
+
is used anywhere: the front end is self-contained. The Common Voice reference
|
| 195 |
+
recordings are CC0.
|
| 196 |
+
|
| 197 |
+
## Citation
|
| 198 |
+
|
| 199 |
+
```bibtex
|
| 200 |
+
@software{brenorb2026tinybroca,
|
| 201 |
+
author = {brenorb},
|
| 202 |
+
title = {tiny-broca: a 4.5M-parameter two-voice Brazilian Portuguese text-to-speech model},
|
| 203 |
+
year = {2026},
|
| 204 |
+
url = {https://huggingface.co/brenorb/tiny-broca}
|
| 205 |
+
}
|
| 206 |
+
```
|
| 207 |
+
|
| 208 |
+
## Acknowledgements
|
| 209 |
+
|
| 210 |
+
The project replicates the open English two-voice model by Muhammed Nazeem
|
| 211 |
+
(tiny-voca, Apache-2.0): same architecture, training recipe and release
|
| 212 |
+
methodology, adapted to Brazilian Portuguese. The design builds on FastSpeech
|
| 213 |
+
2 (explicit duration and prosody prediction), DDSP and the neural homomorphic
|
| 214 |
+
vocoder (source-filter synthesis with predicted filters), and HiFi-GAN and
|
| 215 |
+
UnivNet (discriminators). No code or weights from these projects are used.
|
config.json
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"sample_rate": 24000,
|
| 3 |
+
"hop": 256,
|
| 4 |
+
"n_fft": 1024,
|
| 5 |
+
"n_mels": 80,
|
| 6 |
+
"f0_min": 50.0,
|
| 7 |
+
"f0_max": 600.0,
|
| 8 |
+
"speakers": [
|
| 9 |
+
"F1",
|
| 10 |
+
"M1"
|
| 11 |
+
],
|
| 12 |
+
"vocab_size": 58,
|
| 13 |
+
"channels": 192,
|
| 14 |
+
"heads": 4,
|
| 15 |
+
"feedforward": 640,
|
| 16 |
+
"kernel": 7,
|
| 17 |
+
"encoder_layers": 4,
|
| 18 |
+
"prosody_layers": 2,
|
| 19 |
+
"acoustic_layers": 5,
|
| 20 |
+
"dropout": 0.1,
|
| 21 |
+
"predictor_channels": 128,
|
| 22 |
+
"synth_fft": 512,
|
| 23 |
+
"synth_hop": 128,
|
| 24 |
+
"noise_fft": 256,
|
| 25 |
+
"noise_hop": 64,
|
| 26 |
+
"cep_causal": 80,
|
| 27 |
+
"cep_anti": 16,
|
| 28 |
+
"noise_cep": 32,
|
| 29 |
+
"harmonic_limit": 0.47,
|
| 30 |
+
"max_tokens": 512,
|
| 31 |
+
"max_frames": 3000,
|
| 32 |
+
"mel_mean": -5.0,
|
| 33 |
+
"mel_scale": 5.0,
|
| 34 |
+
"energy_mean": -4.0,
|
| 35 |
+
"energy_scale": 2.0,
|
| 36 |
+
"pitch_reference_hz": 200.0
|
| 37 |
+
}
|
onnx/model.onnx
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:2e3b7a57884047b933eb35782d9456afd3e04311009828b775c94f28270dd616
|
| 3 |
+
size 21372510
|
samples/F1-0.wav
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:5cc0c851ad56e0fa5f4bc32bf3bc05bab1793b1f24c5b4d3e6f13aecf534a925
|
| 3 |
+
size 196652
|
samples/F1-1.wav
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:401c8625f4986f32a7109aaa6fd6ab8a9ce4be189e97cb4c816c75336b4d5b46
|
| 3 |
+
size 213548
|
samples/F1-2.wav
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:94441bfed8e68c33ef588a11e7b32fe6cd0b863b3218f1f9f8bccec320725a79
|
| 3 |
+
size 152620
|
samples/F1-3.wav
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:a95f9e703b4c8b96e196374f06dec0414badddc381bf2e36872109873f6775fa
|
| 3 |
+
size 229932
|
samples/F1-4.wav
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:9b511909defc1e205f6b470af72f985355191226e27a784f980e4671e195bd4e
|
| 3 |
+
size 232492
|
samples/F1-5.wav
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:da999d9bd1d33dae77eb76e5752a70e920af94d1313382dfd1b1f4852b95b41f
|
| 3 |
+
size 294444
|
samples/F1-6.wav
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:98554ee7c6963d97dd88d9cb7e76b4bf7fe702ec5cf618b8c523aaf2f88db1a6
|
| 3 |
+
size 221740
|
samples/F1-7.wav
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:9d9afdc2379625093fd7eea3020b3c6647996970945607c6f6866a169171a97a
|
| 3 |
+
size 185900
|
samples/M1-0.wav
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:de1647a291543766bd997781c5f62f49662c45055a13b79fc0471147fd2e2e61
|
| 3 |
+
size 189484
|
samples/M1-1.wav
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:a1a7a081a39ba2f504fcacf09aacead80712989fe1d0dc3aaeea2eb058a56659
|
| 3 |
+
size 191532
|
samples/M1-2.wav
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:8eb12116330b8046bdb4f4462725682ea1e32d0f5efe3de5ea445f340c71bf64
|
| 3 |
+
size 139820
|
samples/M1-3.wav
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:5811812767826fa0d6434e3ad547b500f529c4e1f8869f1ec6582df0e9c2f298
|
| 3 |
+
size 213036
|
samples/M1-4.wav
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:c085ae7da6a5500cdb510e1dcf928f7b38eed80c92cfcb66c86deaad7738ef41
|
| 3 |
+
size 232492
|
samples/M1-5.wav
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:d869478193fa2d9ed46a3a4eefdb8ae011fd84fb4d83a3a07b1cabf04be18fdd
|
| 3 |
+
size 287276
|
samples/M1-6.wav
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:e27d1bee68ff295f2b8522f62da5f6f52863bee6eb67396d903676608214f458
|
| 3 |
+
size 214572
|
samples/M1-7.wav
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:45bae1e4bd1d85edbd7bb5fa4071985fd36e572c68d28d2bd21b0d2222c69634
|
| 3 |
+
size 183340
|
text.py
ADDED
|
@@ -0,0 +1,436 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Brazilian Portuguese front end: text -> letter tokens with a stress feature.
|
| 2 |
+
|
| 3 |
+
The token alphabet is the Portuguese written form itself: lowercase letters
|
| 4 |
+
(including the accented ones that are distinct graphemes), punctuation, and
|
| 5 |
+
the usual special tokens. Two decisions, documented against the English
|
| 6 |
+
original:
|
| 7 |
+
|
| 8 |
+
* **Characters, not phonemes.** The original front end mapped text to eSpeak
|
| 9 |
+
phonemes through the ``dizione`` package (CMUdict + G2P + rules). No
|
| 10 |
+
permissive Portuguese equivalent exists: eSpeak's Portuguese voice falls
|
| 11 |
+
back to English phonemes for most words, and no copyleft pronouncing
|
| 12 |
+
dictionary is available. Portuguese graphemes map to phones through a small,
|
| 13 |
+
regular set of context rules, so a character-level front end whose encoder
|
| 14 |
+
learns the context is the standard, fully permissive design.
|
| 15 |
+
* **The number reader lives in the normaliser.** Digits, dates, money and
|
| 16 |
+
identifiers are spelled in Brazilian conventions (dot thousands separator,
|
| 17 |
+
comma decimal) before tokenisation, so "R$ 1.234,56" and "15/11/2026" reach
|
| 18 |
+
the model as ordinary words. This is the feature the model is known for
|
| 19 |
+
(reading numbers, dates and money from context) and it is language-specific
|
| 20 |
+
either way.
|
| 21 |
+
|
| 22 |
+
The forced aligner (``tiny_broca.align``) is a Portuguese character-level CTC
|
| 23 |
+
recogniser, so every written letter is a label it can emit; punctuation is
|
| 24 |
+
pause-capable and is never forced.
|
| 25 |
+
"""
|
| 26 |
+
|
| 27 |
+
import hashlib
|
| 28 |
+
import json
|
| 29 |
+
import os
|
| 30 |
+
import re
|
| 31 |
+
import unicodedata
|
| 32 |
+
from dataclasses import dataclass
|
| 33 |
+
|
| 34 |
+
FRONTEND_VERSION = 1
|
| 35 |
+
NORMALIZER_VERSION = 1
|
| 36 |
+
SEPARATOR = "_"
|
| 37 |
+
FRONTENDS = ("pt",)
|
| 38 |
+
FRONTEND_VARIABLE = "TINY_BROCA_FRONTEND"
|
| 39 |
+
_frontend = os.environ.get(FRONTEND_VARIABLE, "pt")
|
| 40 |
+
if _frontend not in FRONTENDS:
|
| 41 |
+
raise ValueError(f"{FRONTEND_VARIABLE} must be one of {FRONTENDS}, not {_frontend!r}")
|
| 42 |
+
|
| 43 |
+
PAD, BOS, EOS, SP, UNK = "<pad>", "<bos>", "<eos>", "<sp>", "<unk>"
|
| 44 |
+
SPECIALS = (PAD, BOS, EOS, SP, UNK)
|
| 45 |
+
PUNCTUATION = (",", ".", "?", "!", ";", ":", '"', "'", "(", ")", "—", "…", "-")
|
| 46 |
+
|
| 47 |
+
LETTERS = (
|
| 48 |
+
"a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m",
|
| 49 |
+
"n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z",
|
| 50 |
+
"à", "á", "â", "ã", "ç", "é", "ê", "í", "ó", "ô", "õ", "ú", "ü", "ũ",
|
| 51 |
+
)
|
| 52 |
+
VOWELS = ("a", "e", "i", "o", "u", "à", "á", "â", "ã", "é", "ê", "í", "ó", "ô", "õ", "ú", "ü", "ũ")
|
| 53 |
+
# Kept names of the English front end: the set of tokens the aligner can emit.
|
| 54 |
+
PHONES = LETTERS
|
| 55 |
+
PHONE_SET = frozenset(PHONES)
|
| 56 |
+
VOWEL_SET = frozenset(VOWELS)
|
| 57 |
+
# Unstressed consonants whose frames should not be voiced (quality checks).
|
| 58 |
+
VOICELESS = frozenset(("p", "t", "k", "f", "s", "x"))
|
| 59 |
+
# Append-only: changing the order or removing a symbol invalidates checkpoints.
|
| 60 |
+
SYMBOLS = SPECIALS + PUNCTUATION + PHONES
|
| 61 |
+
SYMBOL_TO_ID = {symbol: index for index, symbol in enumerate(SYMBOLS)}
|
| 62 |
+
PHONE_IDS = frozenset(SYMBOL_TO_ID[p] for p in PHONES) | {SYMBOL_TO_ID[UNK]}
|
| 63 |
+
LETTER_SET = frozenset(LETTERS)
|
| 64 |
+
STRESS_STRESSED = 1
|
| 65 |
+
|
| 66 |
+
_QUOTE_TRANSLATION = str.maketrans({
|
| 67 |
+
"\u2018": "'", "\u2019": "'", "\u201a": "'", "\u201b": "'", "`": "'",
|
| 68 |
+
"\u201c": '"', "\u201d": '"', "\u201e": '"', "\u201f": '"',
|
| 69 |
+
"\u00ab": '"', "\u00bb": '"',
|
| 70 |
+
"\u2013": "\u2014", "\u2015": "\u2014",
|
| 71 |
+
})
|
| 72 |
+
_WORD_CHARS = LETTER_SET | {"'"} # apostrophes stay inside words (d'água)
|
| 73 |
+
|
| 74 |
+
|
| 75 |
+
def frontend():
|
| 76 |
+
"""Name of the program that produces the tokens: ``"pt"``."""
|
| 77 |
+
return _frontend
|
| 78 |
+
|
| 79 |
+
|
| 80 |
+
def set_frontend(name):
|
| 81 |
+
"""Select the front end for this process (only ``"pt"`` exists)."""
|
| 82 |
+
global _frontend
|
| 83 |
+
if name not in FRONTENDS:
|
| 84 |
+
raise ValueError(f"{FRONTEND_VARIABLE} must be one of {FRONTENDS}, not {name!r}")
|
| 85 |
+
_frontend = name
|
| 86 |
+
|
| 87 |
+
|
| 88 |
+
def frontend_identity():
|
| 89 |
+
return {"name": "pt", "version": FRONTEND_VERSION,
|
| 90 |
+
"normalizer_version": NORMALIZER_VERSION, "symbols": list(SYMBOLS)}
|
| 91 |
+
|
| 92 |
+
|
| 93 |
+
def frontend_runtime():
|
| 94 |
+
"""What an annotation run records about the exact program behind its
|
| 95 |
+
tokens. The normaliser is part of this package, so the identity covers it;
|
| 96 |
+
the runtime records nothing extra."""
|
| 97 |
+
return {"normalizer_version": NORMALIZER_VERSION}
|
| 98 |
+
|
| 99 |
+
|
| 100 |
+
def frontend_fingerprint():
|
| 101 |
+
return hashlib.sha256(json.dumps(frontend_identity(), sort_keys=True, ensure_ascii=False).encode()).hexdigest()
|
| 102 |
+
|
| 103 |
+
|
| 104 |
+
# ---------------------------------------------------------------------------
|
| 105 |
+
# Numbers in words (Brazilian conventions)
|
| 106 |
+
# ---------------------------------------------------------------------------
|
| 107 |
+
|
| 108 |
+
_UNITS = ("zero", "um", "dois", "três", "quatro", "cinco", "seis", "sete", "oito",
|
| 109 |
+
"nove", "dez", "onze", "doze", "treze", "quatorze", "quinze", "dezesseis",
|
| 110 |
+
"dezessete", "dezoito", "dezenove")
|
| 111 |
+
_TENS = ("", "dez", "vinte", "trinta", "quarenta", "cinquenta", "sessenta",
|
| 112 |
+
"setenta", "oitenta", "noventa")
|
| 113 |
+
_HUNDREDS = ("", "cento", "duzentos", "trezentos", "quatrocentos", "quinhentos",
|
| 114 |
+
"seiscentos", "setecentos", "oitocentos", "novecentos")
|
| 115 |
+
_ORDINALS = ("primeiro", "segundo", "terceiro", "quarto", "quinto", "sexto",
|
| 116 |
+
"sétimo", "oitavo", "nono", "décimo", "undécimo", "duodécimo", "trezeno")
|
| 117 |
+
_MONTHS = ("janeiro", "fevereiro", "março", "abril", "maio", "junho", "julho",
|
| 118 |
+
"agosto", "setembro", "outubro", "novembro", "dezembro")
|
| 119 |
+
_SCALE = ((10 ** 9, "bilhão", "bilhões"), (10 ** 6, "milhão", "milhões"),
|
| 120 |
+
(10 ** 3, "mil", "mil"))
|
| 121 |
+
|
| 122 |
+
|
| 123 |
+
def _below_thousand(n):
|
| 124 |
+
parts = []
|
| 125 |
+
if n >= 100:
|
| 126 |
+
hundreds, rest = divmod(n, 100)
|
| 127 |
+
parts.append("cem" if n == 100 else _HUNDREDS[hundreds])
|
| 128 |
+
if rest:
|
| 129 |
+
parts.append("e")
|
| 130 |
+
if n % 100:
|
| 131 |
+
tens, unit = divmod(n % 100, 10)
|
| 132 |
+
if tens == 1:
|
| 133 |
+
parts.append(_UNITS[10 + unit]) # dez, onze, ..., dezenove
|
| 134 |
+
elif tens:
|
| 135 |
+
parts.append(_TENS[tens])
|
| 136 |
+
if unit:
|
| 137 |
+
parts.append("e")
|
| 138 |
+
parts.append(_UNITS[unit])
|
| 139 |
+
elif unit:
|
| 140 |
+
parts.append(_UNITS[unit])
|
| 141 |
+
return " ".join(p for p in parts if p)
|
| 142 |
+
|
| 143 |
+
|
| 144 |
+
def number_words(n):
|
| 145 |
+
"""Spell an integer 0..10**12 in Brazilian Portuguese (masculine form)."""
|
| 146 |
+
n = int(abs(n))
|
| 147 |
+
if n == 0:
|
| 148 |
+
return "zero"
|
| 149 |
+
if n < 1000:
|
| 150 |
+
return _below_thousand(n)
|
| 151 |
+
if n % 1000 == 0 and n < 10 ** 6:
|
| 152 |
+
head = _below_thousand(n // 1000)
|
| 153 |
+
return "mil" if head == "um" else head + " mil"
|
| 154 |
+
parts = []
|
| 155 |
+
for scale, singular, plural in _SCALE:
|
| 156 |
+
if n >= scale:
|
| 157 |
+
count, n = divmod(n, scale)
|
| 158 |
+
# Portuguese says "mil", never "um mil".
|
| 159 |
+
head = "" if (count == 1 and scale == 10 ** 3) else (
|
| 160 |
+
_UNITS[count] if count == 1 else number_words(count))
|
| 161 |
+
parts.append((head + " " if head else "") +
|
| 162 |
+
(singular if count == 1 else plural))
|
| 163 |
+
# "e" joins the scales when the rest has no tens part:
|
| 164 |
+
# "quatro mil e noventa", "mil e quinhentos", "mil e cinco", but
|
| 165 |
+
# "mil cento e cinquenta". The larger scales take "e" for any rest
|
| 166 |
+
# ("um milhão e quinhentos mil").
|
| 167 |
+
if n and (scale > 10 ** 3 or n < 100 or n % 100 == 0):
|
| 168 |
+
parts.append("e")
|
| 169 |
+
if n:
|
| 170 |
+
parts.append(_below_thousand(n) if n < 1000 else number_words(n))
|
| 171 |
+
return " ".join(parts)
|
| 172 |
+
|
| 173 |
+
|
| 174 |
+
def ordinal_words(n):
|
| 175 |
+
if n < len(_ORDINALS):
|
| 176 |
+
return _ORDINALS[n - 1]
|
| 177 |
+
decade, unit = divmod(n, 10)
|
| 178 |
+
if decade < 20:
|
| 179 |
+
base = number_words(decade).rstrip("s") if decade > 1 else ""
|
| 180 |
+
return (base + " " if base else "") + number_words(unit).replace("um", "um") + "ésimo" if unit else _ORDINALS[9] if decade == 1 else number_words(n) + "ésimo"
|
| 181 |
+
return number_words(n) + "ésimo"
|
| 182 |
+
|
| 183 |
+
|
| 184 |
+
def digits_words(text):
|
| 185 |
+
return " ".join(_UNITS[int(c)] if int(c) < 10 else "dez" for c in text if c.isdigit())
|
| 186 |
+
|
| 187 |
+
|
| 188 |
+
# ---------------------------------------------------------------------------
|
| 189 |
+
# Text normalisation: digits and symbols -> words
|
| 190 |
+
# ---------------------------------------------------------------------------
|
| 191 |
+
|
| 192 |
+
_MONEY = re.compile(r"\b[rR]\$\s?(\d{1,3}(?:\.\d{3})*|\d+)(?!\d)(?:,(\d{1,2}))?")
|
| 193 |
+
_DATE = re.compile(r"\b(\d{1,2})/(\d{1,2})/(\d{2}|\d{4})\b")
|
| 194 |
+
_TIME = re.compile(r"\b(\d{1,2}):(\d{2})\b")
|
| 195 |
+
_CLOCK = re.compile(r"\b(\d{1,2})h(\d{2})\b")
|
| 196 |
+
_PERCENT = re.compile(r"\b(\d+(?:[.,]\d+)?)\s?%")
|
| 197 |
+
_DEGREE = re.compile(r"\b(\d+(?:[.,]\d+)?)\s?°")
|
| 198 |
+
_PHONE = re.compile(r"\(\d{2}\)\s?\d{5}-\d{4}")
|
| 199 |
+
_GROUPS = re.compile(r"\b\d{1,3}(?:[.-]\d{1,3}){2,}\b") # CPF, CNPJ-like, CEP
|
| 200 |
+
_DECIMAL = re.compile(r"\b(\d{1,3}(?:\.\d{3})*|\d+)[,](\d{1,3})\b")
|
| 201 |
+
_INTEGER = re.compile(r"\b(\d{1,3}(?:\.\d{3})+|\d{1,5})\b")
|
| 202 |
+
_YEAR = re.compile(r"\b(1[0-9]{3}|20\d{2})\b")
|
| 203 |
+
|
| 204 |
+
|
| 205 |
+
def _money(m):
|
| 206 |
+
integer = m.group(1).replace(".", "")
|
| 207 |
+
cents = m.group(2)
|
| 208 |
+
words = number_words(int(integer)) + " real" if int(integer) == 1 else number_words(int(integer)) + " reais"
|
| 209 |
+
if cents and int(cents):
|
| 210 |
+
words += " e " + number_words(int(cents)) + (" centavo" if int(cents) == 1 else " centavos")
|
| 211 |
+
return words
|
| 212 |
+
|
| 213 |
+
|
| 214 |
+
def _date(m):
|
| 215 |
+
day, month, year = int(m.group(1)), int(m.group(2)), m.group(3)
|
| 216 |
+
year = "20" + year if len(year) == 2 else year
|
| 217 |
+
if 1 <= month <= 12:
|
| 218 |
+
return f"{number_words(day)} de {_MONTHS[month - 1]} de {number_words(int(year))}"
|
| 219 |
+
return m.group(0) # not a date: leave the digits (the integer rule reads them)
|
| 220 |
+
|
| 221 |
+
|
| 222 |
+
def _time(m):
|
| 223 |
+
hour, minute = int(m.group(1)), int(m.group(2))
|
| 224 |
+
if not 0 <= hour <= 23 or minute > 59:
|
| 225 |
+
return m.group(0)
|
| 226 |
+
if hour == 12 and minute == 0:
|
| 227 |
+
return "meio dia"
|
| 228 |
+
if hour == 0:
|
| 229 |
+
return "meia noite" if minute == 0 else f"zero hora e {number_words(minute)}"
|
| 230 |
+
if minute == 0:
|
| 231 |
+
return f"{number_words(hour)}{' hora' if hour == 1 else ' horas'}"
|
| 232 |
+
if minute == 30:
|
| 233 |
+
return f"{number_words(hour)} e meia"
|
| 234 |
+
return f"{number_words(hour)} horas e {number_words(minute)}"
|
| 235 |
+
|
| 236 |
+
|
| 237 |
+
def _clock(m):
|
| 238 |
+
hour, minute = int(m.group(1)), int(m.group(2))
|
| 239 |
+
if not 0 <= hour <= 23 or minute > 59:
|
| 240 |
+
return m.group(0)
|
| 241 |
+
if minute == 0:
|
| 242 |
+
return f"{number_words(hour)}{' hora' if hour == 1 else ' horas'}"
|
| 243 |
+
if minute == 30:
|
| 244 |
+
return f"{number_words(hour)} e meia"
|
| 245 |
+
return f"{number_words(hour)} e {number_words(minute)}"
|
| 246 |
+
|
| 247 |
+
|
| 248 |
+
def _decimal(m):
|
| 249 |
+
integer = int(m.group(1).replace(".", ""))
|
| 250 |
+
frac = m.group(2)
|
| 251 |
+
if int(frac) == 0:
|
| 252 |
+
return number_words(integer) # "150,00" -> "cento e cinquenta"
|
| 253 |
+
if len(frac) > 1 and frac[0] == "0":
|
| 254 |
+
frac_words = digits_words(frac) # "3,05" -> "zero cinco"
|
| 255 |
+
else:
|
| 256 |
+
frac_words = number_words(int(frac)) # "3,14" -> "quatorze"
|
| 257 |
+
return f"{number_words(integer)} vírgula {frac_words}"
|
| 258 |
+
|
| 259 |
+
|
| 260 |
+
def _groups(m):
|
| 261 |
+
return ", ".join(digits_words(g) for g in re.split(r"[.-]", m.group(0)))
|
| 262 |
+
|
| 263 |
+
|
| 264 |
+
def normalize_text(text):
|
| 265 |
+
"""NFKC + casefold + quote/dash unification + spelling out digits.
|
| 266 |
+
|
| 267 |
+
Digits follow Brazilian conventions: "1.234" is a thousand and "3,14" a
|
| 268 |
+
decimal; money uses reais and centavos; dates read day-month-year; times
|
| 269 |
+
read in hours and minutes; document identifiers (three-digit groups) read
|
| 270 |
+
digit by digit.
|
| 271 |
+
"""
|
| 272 |
+
if not isinstance(text, str):
|
| 273 |
+
raise TypeError("text must be a string")
|
| 274 |
+
text = unicodedata.normalize("NFKC", text).translate(_QUOTE_TRANSLATION)
|
| 275 |
+
text = text.replace("ª", " a").replace("º", " o").replace("×", " vezes ")
|
| 276 |
+
# Two hyphens and three dots are the ASCII forms of the inventory symbols;
|
| 277 |
+
# without this "..." would become three pause tokens.
|
| 278 |
+
text = text.replace("--", "—").replace("...", "…")
|
| 279 |
+
text = text.lower()
|
| 280 |
+
text = _MONEY.sub(_money, text)
|
| 281 |
+
text = _DATE.sub(_date, text)
|
| 282 |
+
text = _TIME.sub(_time, text)
|
| 283 |
+
text = _CLOCK.sub(_clock, text)
|
| 284 |
+
text = _PERCENT.sub(lambda m: number_words(int(re.sub(r"[^0-9]", "", m.group(1)))) + " por cento", text)
|
| 285 |
+
text = _DEGREE.sub(lambda m: number_words(int(re.sub(r"[^0-9]", "", m.group(1)))) + " graus", text)
|
| 286 |
+
text = _PHONE.sub(lambda m: " ".join(digits_words(g) for g in re.findall(r"\d+", m.group(0))), text)
|
| 287 |
+
text = _GROUPS.sub(_groups, text)
|
| 288 |
+
text = _DECIMAL.sub(_decimal, text)
|
| 289 |
+
text = _YEAR.sub(lambda m: number_words(int(m.group(1))), text)
|
| 290 |
+
text = _INTEGER.sub(lambda m: number_words(int(m.group(1).replace(".", ""))), text)
|
| 291 |
+
text = re.sub(r"\s+", " ", text).strip()
|
| 292 |
+
return text
|
| 293 |
+
|
| 294 |
+
|
| 295 |
+
# For comparing a transcription against its text: numbers are spoken by the
|
| 296 |
+
# teacher but written back as digits by Whisper ("R$ 12,50" is read as "doze
|
| 297 |
+
# vírgula cinquenta"), so a raw word WER would be meaningless.
|
| 298 |
+
_NUMBER_WORDS = frozenset(("zero", "um", "uma", "dois", "duas", "três", "tres", "quatro",
|
| 299 |
+
"cinco", "seis", "sete", "oito", "nove", "dez", "onze", "doze",
|
| 300 |
+
"treze", "quinze", "dezesseis", "dezessete", "dezoito", "dezenove",
|
| 301 |
+
"vinte", "trinta", "quarenta", "cinquenta", "sessenta", "setenta",
|
| 302 |
+
"oitenta", "noventa", "cem", "cento", "mil", "milhão", "milhao",
|
| 303 |
+
"bilhão", "bilhao"))
|
| 304 |
+
_NUM = re.compile(r"\d+(?:[.,]\d+)*")
|
| 305 |
+
|
| 306 |
+
|
| 307 |
+
def wer_normalize(text):
|
| 308 |
+
"""Casefold, strip accents and punctuation, mask numbers and number words."""
|
| 309 |
+
text = unicodedata.normalize("NFKD", text)
|
| 310 |
+
text = "".join(c for c in text if not unicodedata.combining(c))
|
| 311 |
+
text = text.casefold()
|
| 312 |
+
text = re.sub(r"r\s?\$\s?", " <num> ", text)
|
| 313 |
+
text = re.sub(r"%", " <num> ", text)
|
| 314 |
+
text = _NUM.sub(" <num> ", text)
|
| 315 |
+
text = re.sub(r"[^\w\s]", " ", text)
|
| 316 |
+
words = [w for w in text.split() if not w.startswith("<") and w not in _NUMBER_WORDS
|
| 317 |
+
and w.rstrip("s") not in _NUMBER_WORDS]
|
| 318 |
+
return " ".join(words).strip()
|
| 319 |
+
|
| 320 |
+
|
| 321 |
+
_ACCENTED = frozenset(("á", "â", "é", "ê", "í", "ó", "ô", "õ", "ú", "ã", "õ"))
|
| 322 |
+
|
| 323 |
+
|
| 324 |
+
def _syllable_starts(word):
|
| 325 |
+
"""Start indices of the syllables of a word (one per vowel nucleus).
|
| 326 |
+
|
| 327 |
+
A consonant run between two vowels splits so the consonants go with the
|
| 328 |
+
following syllable, the Brazilian convention for single consonants; this
|
| 329 |
+
is an approximation, which is fine for a prosody feature.
|
| 330 |
+
"""
|
| 331 |
+
vowel = lambda c: c in VOWELS
|
| 332 |
+
starts = [0]
|
| 333 |
+
i, n = 0, len(word)
|
| 334 |
+
while i < n:
|
| 335 |
+
if vowel(word[i]) and i + 1 < n and not vowel(word[i + 1]):
|
| 336 |
+
j = i + 1
|
| 337 |
+
while j < n and not vowel(word[j]):
|
| 338 |
+
j += 1
|
| 339 |
+
if j < n and vowel(word[j]): # a consonant run between two vowels
|
| 340 |
+
run = j - i - 1
|
| 341 |
+
starts.append(i + 1 if run == 1 else min(i + 2, j))
|
| 342 |
+
i += 1
|
| 343 |
+
return starts
|
| 344 |
+
|
| 345 |
+
|
| 346 |
+
def _stressed_range(word):
|
| 347 |
+
"""(start, end) of the stressed syllable in a word.
|
| 348 |
+
|
| 349 |
+
An explicit accent (á â é ê í ó ô õ ú ã) wins; otherwise a word ending in
|
| 350 |
+
a vowel is stressed on its penultimate syllable, a word ending in L, N, R
|
| 351 |
+
or X on its last syllable, other endings on the penultimate.
|
| 352 |
+
"""
|
| 353 |
+
for i, c in enumerate(word):
|
| 354 |
+
if c in _ACCENTED:
|
| 355 |
+
starts = _syllable_starts(word)
|
| 356 |
+
start = max((s for s in starts if s <= i), default=0)
|
| 357 |
+
index = starts.index(start)
|
| 358 |
+
end = starts[index + 1] if index + 1 < len(starts) else len(word)
|
| 359 |
+
return start, end
|
| 360 |
+
starts = _syllable_starts(word)
|
| 361 |
+
if word[-1] in ("l", "n", "r", "x"):
|
| 362 |
+
start = starts[-1]
|
| 363 |
+
else:
|
| 364 |
+
start = starts[-2] if len(starts) >= 2 else starts[0]
|
| 365 |
+
index = starts.index(start)
|
| 366 |
+
end = starts[index + 1] if index + 1 < len(starts) else len(word)
|
| 367 |
+
return start, end
|
| 368 |
+
|
| 369 |
+
|
| 370 |
+
@dataclass(frozen=True)
|
| 371 |
+
class Phonemized:
|
| 372 |
+
symbols: tuple
|
| 373 |
+
ids: tuple
|
| 374 |
+
stress: tuple
|
| 375 |
+
unknown: tuple
|
| 376 |
+
|
| 377 |
+
def __len__(self):
|
| 378 |
+
return len(self.ids)
|
| 379 |
+
|
| 380 |
+
|
| 381 |
+
def tokenize(text):
|
| 382 |
+
"""Build the token sequence from normalised text.
|
| 383 |
+
|
| 384 |
+
Returns a :class:`Phonemized` whose symbols are letters, punctuation and
|
| 385 |
+
word spaces, with a stress feature per token (1 on the letters of the
|
| 386 |
+
stressed syllable of each word, 0 elsewhere) and the list of characters
|
| 387 |
+
that fell outside the inventory.
|
| 388 |
+
"""
|
| 389 |
+
symbols = [BOS]
|
| 390 |
+
stress = [0]
|
| 391 |
+
unknown = []
|
| 392 |
+
word = []
|
| 393 |
+
|
| 394 |
+
def flush_word():
|
| 395 |
+
if not word:
|
| 396 |
+
return
|
| 397 |
+
text_ = "".join(word)
|
| 398 |
+
start, end = _stressed_range(text_)
|
| 399 |
+
for i, c in enumerate(word):
|
| 400 |
+
symbols.append(c)
|
| 401 |
+
stress.append(STRESS_STRESSED if start <= i < end else 0)
|
| 402 |
+
word.clear()
|
| 403 |
+
|
| 404 |
+
for c in text:
|
| 405 |
+
if c == " ":
|
| 406 |
+
flush_word()
|
| 407 |
+
if symbols[-1] != SP:
|
| 408 |
+
symbols.append(SP)
|
| 409 |
+
stress.append(0)
|
| 410 |
+
elif c in LETTER_SET or c in _WORD_CHARS:
|
| 411 |
+
word.append(c)
|
| 412 |
+
elif c in SYMBOL_TO_ID:
|
| 413 |
+
flush_word()
|
| 414 |
+
symbols.append(c)
|
| 415 |
+
stress.append(0)
|
| 416 |
+
else:
|
| 417 |
+
flush_word()
|
| 418 |
+
symbols.append(UNK)
|
| 419 |
+
stress.append(0)
|
| 420 |
+
unknown.append(c)
|
| 421 |
+
flush_word()
|
| 422 |
+
symbols.append(EOS)
|
| 423 |
+
stress.append(0)
|
| 424 |
+
return Phonemized(tuple(symbols), tuple(SYMBOL_TO_ID[s] for s in symbols),
|
| 425 |
+
tuple(stress), tuple(unknown))
|
| 426 |
+
|
| 427 |
+
|
| 428 |
+
def phonemize(text):
|
| 429 |
+
if not isinstance(text, str) or not text.strip():
|
| 430 |
+
raise ValueError("empty text")
|
| 431 |
+
return tokenize(normalize_text(text))
|
| 432 |
+
|
| 433 |
+
|
| 434 |
+
def is_phone(token_ids):
|
| 435 |
+
"""Boolean list/tensor helper: tokens that must be realised as audio."""
|
| 436 |
+
return [int(i) in PHONE_IDS for i in token_ids]
|
tiny-broca.pt
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:debd760592d8a98450118efdba5503a3f4e0d9606e067f531054e4966052b447
|
| 3 |
+
size 18195141
|