Commit ·
8f8b0fa
0
Parent(s):
CavaAlign v1
Browse files- .gitattributes +40 -0
- .gitignore +1 -0
- LICENSE +235 -0
- README.md +243 -0
- SHA256SUMS +24 -0
- align.py +81 -0
- align_config.json +92 -0
- assets/compare.png +3 -0
- assets/compare_dark.png +3 -0
- cavaalign.onnx +3 -0
- cavaalign/__init__.py +2 -0
- cavaalign/align.py +1031 -0
- cavaalign/romanize.py +200 -0
- cavaalign/vocab.py +74 -0
- kotlin/CavaAlignModel.kt +79 -0
- kotlin/CavaAligner.kt +638 -0
- kotlin/Romanizer.kt +95 -0
- reference/de_de.3363_2124.00.expected.json +547 -0
- reference/de_de.3363_2124.00.txt +1 -0
- reference/de_de.3363_2124.00.wav +3 -0
- reference/en_en.testclean1089_134686.00.expected.json +504 -0
- reference/en_en.testclean1089_134686.00.txt +1 -0
- reference/en_en.testclean1089_134686.00.wav +3 -0
- reference/ru_ru.ru.00.expected.json +463 -0
- reference/ru_ru.ru.00.txt +1 -0
- reference/ru_ru.ru.00.wav +3 -0
- vocab.json +31 -0
.gitattributes
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
*.7z filter=lfs diff=lfs merge=lfs -text
|
| 2 |
+
*.arrow filter=lfs diff=lfs merge=lfs -text
|
| 3 |
+
*.bin filter=lfs diff=lfs merge=lfs -text
|
| 4 |
+
*.bz2 filter=lfs diff=lfs merge=lfs -text
|
| 5 |
+
*.ckpt filter=lfs diff=lfs merge=lfs -text
|
| 6 |
+
*.ftz filter=lfs diff=lfs merge=lfs -text
|
| 7 |
+
*.gz filter=lfs diff=lfs merge=lfs -text
|
| 8 |
+
*.h5 filter=lfs diff=lfs merge=lfs -text
|
| 9 |
+
*.joblib filter=lfs diff=lfs merge=lfs -text
|
| 10 |
+
*.lfs.* filter=lfs diff=lfs merge=lfs -text
|
| 11 |
+
*.mlmodel filter=lfs diff=lfs merge=lfs -text
|
| 12 |
+
*.model filter=lfs diff=lfs merge=lfs -text
|
| 13 |
+
*.msgpack filter=lfs diff=lfs merge=lfs -text
|
| 14 |
+
*.npy filter=lfs diff=lfs merge=lfs -text
|
| 15 |
+
*.npz filter=lfs diff=lfs merge=lfs -text
|
| 16 |
+
*.onnx filter=lfs diff=lfs merge=lfs -text
|
| 17 |
+
*.ot filter=lfs diff=lfs merge=lfs -text
|
| 18 |
+
*.parquet filter=lfs diff=lfs merge=lfs -text
|
| 19 |
+
*.pb filter=lfs diff=lfs merge=lfs -text
|
| 20 |
+
*.pickle filter=lfs diff=lfs merge=lfs -text
|
| 21 |
+
*.pkl filter=lfs diff=lfs merge=lfs -text
|
| 22 |
+
*.pt filter=lfs diff=lfs merge=lfs -text
|
| 23 |
+
*.pth filter=lfs diff=lfs merge=lfs -text
|
| 24 |
+
*.rar filter=lfs diff=lfs merge=lfs -text
|
| 25 |
+
*.safetensors filter=lfs diff=lfs merge=lfs -text
|
| 26 |
+
saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
| 27 |
+
*.tar.* filter=lfs diff=lfs merge=lfs -text
|
| 28 |
+
*.tar filter=lfs diff=lfs merge=lfs -text
|
| 29 |
+
*.tflite filter=lfs diff=lfs merge=lfs -text
|
| 30 |
+
*.tgz filter=lfs diff=lfs merge=lfs -text
|
| 31 |
+
*.wasm filter=lfs diff=lfs merge=lfs -text
|
| 32 |
+
*.xz 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 |
+
reference/de_de.3363_2124.00.wav filter=lfs diff=lfs merge=lfs -text
|
| 37 |
+
reference/en_en.testclean1089_134686.00.wav filter=lfs diff=lfs merge=lfs -text
|
| 38 |
+
reference/ru_ru.ru.00.wav filter=lfs diff=lfs merge=lfs -text
|
| 39 |
+
assets/compare.png filter=lfs diff=lfs merge=lfs -text
|
| 40 |
+
assets/compare_dark.png filter=lfs diff=lfs merge=lfs -text
|
.gitignore
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
__pycache__/
|
LICENSE
ADDED
|
@@ -0,0 +1,235 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
GNU AFFERO GENERAL PUBLIC LICENSE
|
| 2 |
+
Version 3, 19 November 2007
|
| 3 |
+
|
| 4 |
+
Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
|
| 5 |
+
|
| 6 |
+
Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed.
|
| 7 |
+
|
| 8 |
+
Preamble
|
| 9 |
+
|
| 10 |
+
The GNU Affero General Public License is a free, copyleft license for software and other kinds of works, specifically designed to ensure cooperation with the community in the case of network server software.
|
| 11 |
+
|
| 12 |
+
The licenses for most software and other practical works are designed to take away your freedom to share and change the works. By contrast, our General Public Licenses are intended to guarantee your freedom to share and change all versions of a program--to make sure it remains free software for all its users.
|
| 13 |
+
|
| 14 |
+
When we speak of free software, we are referring to freedom, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for them if you wish), that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs, and that you know you can do these things.
|
| 15 |
+
|
| 16 |
+
Developers that use our General Public Licenses protect your rights with two steps: (1) assert copyright on the software, and (2) offer you this License which gives you legal permission to copy, distribute and/or modify the software.
|
| 17 |
+
|
| 18 |
+
A secondary benefit of defending all users' freedom is that improvements made in alternate versions of the program, if they receive widespread use, become available for other developers to incorporate. Many developers of free software are heartened and encouraged by the resulting cooperation. However, in the case of software used on network servers, this result may fail to come about. The GNU General Public License permits making a modified version and letting the public access it on a server without ever releasing its source code to the public.
|
| 19 |
+
|
| 20 |
+
The GNU Affero General Public License is designed specifically to ensure that, in such cases, the modified source code becomes available to the community. It requires the operator of a network server to provide the source code of the modified version running there to the users of that server. Therefore, public use of a modified version, on a publicly accessible server, gives the public access to the source code of the modified version.
|
| 21 |
+
|
| 22 |
+
An older license, called the Affero General Public License and published by Affero, was designed to accomplish similar goals. This is a different license, not a version of the Affero GPL, but Affero has released a new version of the Affero GPL which permits relicensing under this license.
|
| 23 |
+
|
| 24 |
+
The precise terms and conditions for copying, distribution and modification follow.
|
| 25 |
+
|
| 26 |
+
TERMS AND CONDITIONS
|
| 27 |
+
|
| 28 |
+
0. Definitions.
|
| 29 |
+
|
| 30 |
+
"This License" refers to version 3 of the GNU Affero General Public License.
|
| 31 |
+
|
| 32 |
+
"Copyright" also means copyright-like laws that apply to other kinds of works, such as semiconductor masks.
|
| 33 |
+
|
| 34 |
+
"The Program" refers to any copyrightable work licensed under this License. Each licensee is addressed as "you". "Licensees" and "recipients" may be individuals or organizations.
|
| 35 |
+
|
| 36 |
+
To "modify" a work means to copy from or adapt all or part of the work in a fashion requiring copyright permission, other than the making of an exact copy. The resulting work is called a "modified version" of the earlier work or a work "based on" the earlier work.
|
| 37 |
+
|
| 38 |
+
A "covered work" means either the unmodified Program or a work based on the Program.
|
| 39 |
+
|
| 40 |
+
To "propagate" a work means to do anything with it that, without permission, would make you directly or secondarily liable for infringement under applicable copyright law, except executing it on a computer or modifying a private copy. Propagation includes copying, distribution (with or without modification), making available to the public, and in some countries other activities as well.
|
| 41 |
+
|
| 42 |
+
To "convey" a work means any kind of propagation that enables other parties to make or receive copies. Mere interaction with a user through a computer network, with no transfer of a copy, is not conveying.
|
| 43 |
+
|
| 44 |
+
An interactive user interface displays "Appropriate Legal Notices" to the extent that it includes a convenient and prominently visible feature that (1) displays an appropriate copyright notice, and (2) tells the user that there is no warranty for the work (except to the extent that warranties are provided), that licensees may convey the work under this License, and how to view a copy of this License. If the interface presents a list of user commands or options, such as a menu, a prominent item in the list meets this criterion.
|
| 45 |
+
|
| 46 |
+
1. Source Code.
|
| 47 |
+
The "source code" for a work means the preferred form of the work for making modifications to it. "Object code" means any non-source form of a work.
|
| 48 |
+
|
| 49 |
+
A "Standard Interface" means an interface that either is an official standard defined by a recognized standards body, or, in the case of interfaces specified for a particular programming language, one that is widely used among developers working in that language.
|
| 50 |
+
|
| 51 |
+
The "System Libraries" of an executable work include anything, other than the work as a whole, that (a) is included in the normal form of packaging a Major Component, but which is not part of that Major Component, and (b) serves only to enable use of the work with that Major Component, or to implement a Standard Interface for which an implementation is available to the public in source code form. A "Major Component", in this context, means a major essential component (kernel, window system, and so on) of the specific operating system (if any) on which the executable work runs, or a compiler used to produce the work, or an object code interpreter used to run it.
|
| 52 |
+
|
| 53 |
+
The "Corresponding Source" for a work in object code form means all the source code needed to generate, install, and (for an executable work) run the object code and to modify the work, including scripts to control those activities. However, it does not include the work's System Libraries, or general-purpose tools or generally available free programs which are used unmodified in performing those activities but which are not part of the work. For example, Corresponding Source includes interface definition files associated with source files for the work, and the source code for shared libraries and dynamically linked subprograms that the work is specifically designed to require, such as by intimate data communication or control flow between those
|
| 54 |
+
subprograms and other parts of the work.
|
| 55 |
+
|
| 56 |
+
The Corresponding Source need not include anything that users can regenerate automatically from other parts of the Corresponding Source.
|
| 57 |
+
|
| 58 |
+
The Corresponding Source for a work in source code form is that same work.
|
| 59 |
+
|
| 60 |
+
2. Basic Permissions.
|
| 61 |
+
All rights granted under this License are granted for the term of copyright on the Program, and are irrevocable provided the stated conditions are met. This License explicitly affirms your unlimited permission to run the unmodified Program. The output from running a covered work is covered by this License only if the output, given its content, constitutes a covered work. This License acknowledges your rights of fair use or other equivalent, as provided by copyright law.
|
| 62 |
+
|
| 63 |
+
You may make, run and propagate covered works that you do not convey, without conditions so long as your license otherwise remains in force. You may convey covered works to others for the sole purpose of having them make modifications exclusively for you, or provide you with facilities for running those works, provided that you comply with the terms of this License in conveying all material for which you do not control copyright. Those thus making or running the covered works for you must do so exclusively on your behalf, under your direction and control, on terms that prohibit them from making any copies of your copyrighted material outside their relationship with you.
|
| 64 |
+
|
| 65 |
+
Conveying under any other circumstances is permitted solely under the conditions stated below. Sublicensing is not allowed; section 10 makes it unnecessary.
|
| 66 |
+
|
| 67 |
+
3. Protecting Users' Legal Rights From Anti-Circumvention Law.
|
| 68 |
+
No covered work shall be deemed part of an effective technological measure under any applicable law fulfilling obligations under article 11 of the WIPO copyright treaty adopted on 20 December 1996, or similar laws prohibiting or restricting circumvention of such measures.
|
| 69 |
+
|
| 70 |
+
When you convey a covered work, you waive any legal power to forbid circumvention of technological measures to the extent such circumvention is effected by exercising rights under this License with respect to the covered work, and you disclaim any intention to limit operation or modification of the work as a means of enforcing, against the work's users, your or third parties' legal rights to forbid circumvention of technological measures.
|
| 71 |
+
|
| 72 |
+
4. Conveying Verbatim Copies.
|
| 73 |
+
You may convey verbatim copies of the Program's source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice; keep intact all notices stating that this License and any non-permissive terms added in accord with section 7 apply to the code; keep intact all notices of the absence of any warranty; and give all recipients a copy of this License along with the Program.
|
| 74 |
+
|
| 75 |
+
You may charge any price or no price for each copy that you convey, and you may offer support or warranty protection for a fee.
|
| 76 |
+
|
| 77 |
+
5. Conveying Modified Source Versions.
|
| 78 |
+
You may convey a work based on the Program, or the modifications to produce it from the Program, in the form of source code under the terms of section 4, provided that you also meet all of these conditions:
|
| 79 |
+
|
| 80 |
+
a) The work must carry prominent notices stating that you modified it, and giving a relevant date.
|
| 81 |
+
|
| 82 |
+
b) The work must carry prominent notices stating that it is released under this License and any conditions added under section 7. This requirement modifies the requirement in section 4 to "keep intact all notices".
|
| 83 |
+
|
| 84 |
+
c) You must license the entire work, as a whole, under this License to anyone who comes into possession of a copy. This License will therefore apply, along with any applicable section 7 additional terms, to the whole of the work, and all its parts, regardless of how they are packaged. This License gives no permission to license the work in any other way, but it does not invalidate such permission if you have separately received it.
|
| 85 |
+
|
| 86 |
+
d) If the work has interactive user interfaces, each must display Appropriate Legal Notices; however, if the Program has interactive interfaces that do not display Appropriate Legal Notices, your work need not make them do so.
|
| 87 |
+
|
| 88 |
+
A compilation of a covered work with other separate and independent works, which are not by their nature extensions of the covered work, and which are not combined with it such as to form a larger program, in or on a volume of a storage or distribution medium, is called an "aggregate" if the compilation and its resulting copyright are not used to limit the access or legal rights of the compilation's users beyond what the individual works permit. Inclusion of a covered work in an aggregate does not cause this License to apply to the other parts of the aggregate.
|
| 89 |
+
|
| 90 |
+
6. Conveying Non-Source Forms.
|
| 91 |
+
You may convey a covered work in object code form under the terms of sections 4 and 5, provided that you also convey the machine-readable Corresponding Source under the terms of this License, in one of these ways:
|
| 92 |
+
|
| 93 |
+
a) Convey the object code in, or embodied in, a physical product (including a physical distribution medium), accompanied by the Corresponding Source fixed on a durable physical medium customarily used for software interchange.
|
| 94 |
+
|
| 95 |
+
b) Convey the object code in, or embodied in, a physical product (including a physical distribution medium), accompanied by a written offer, valid for at least three years and valid for as long as you offer spare parts or customer support for that product model, to give anyone who possesses the object code either (1) a copy of the Corresponding Source for all the software in the product that is covered by this License, on a durable physical medium customarily used for software interchange, for a price no more than your reasonable cost of physically performing this conveying of source, or (2) access to copy the Corresponding Source from a network server at no charge.
|
| 96 |
+
|
| 97 |
+
c) Convey individual copies of the object code with a copy of the written offer to provide the Corresponding Source. This alternative is allowed only occasionally and noncommercially, and only if you received the object code with such an offer, in accord with subsection 6b.
|
| 98 |
+
|
| 99 |
+
d) Convey the object code by offering access from a designated place (gratis or for a charge), and offer equivalent access to the Corresponding Source in the same way through the same place at no further charge. You need not require recipients to copy the Corresponding Source along with the object code. If the place to copy the object code is a network server, the Corresponding Source may be on a different server (operated by you or a third party) that supports equivalent copying facilities, provided you maintain clear directions next to the object code saying where to find the Corresponding Source. Regardless of what server hosts the Corresponding Source, you remain obligated to ensure that it is available for as long as needed to satisfy these requirements.
|
| 100 |
+
|
| 101 |
+
e) Convey the object code using peer-to-peer transmission, provided you inform other peers where the object code and Corresponding Source of the work are being offered to the general public at no charge under subsection 6d.
|
| 102 |
+
|
| 103 |
+
A separable portion of the object code, whose source code is excluded from the Corresponding Source as a System Library, need not be included in conveying the object code work.
|
| 104 |
+
|
| 105 |
+
A "User Product" is either (1) a "consumer product", which means any tangible personal property which is normally used for personal, family, or household purposes, or (2) anything designed or sold for incorporation into a dwelling. In determining whether a product is a consumer product, doubtful cases shall be resolved in favor of coverage. For a particular product received by a particular user, "normally used" refers to a typical or common use of that class of product, regardless of the status of the particular user or of the way in which the particular user actually uses, or expects or is expected to use, the product. A product is a consumer product regardless of whether the product has substantial commercial, industrial or non-consumer uses, unless such uses represent the only significant mode of use of the product.
|
| 106 |
+
|
| 107 |
+
"Installation Information" for a User Product means any methods, procedures, authorization keys, or other information required to install and execute modified versions of a covered work in that User Product from a modified version of its Corresponding Source. The information must suffice to ensure that the continued functioning of the modified object code is in no case prevented or interfered with solely because modification has been made.
|
| 108 |
+
|
| 109 |
+
If you convey an object code work under this section in, or with, or specifically for use in, a User Product, and the conveying occurs as part of a transaction in which the right of possession and use of the User Product is transferred to the recipient in perpetuity or for a fixed term (regardless of how the transaction is characterized), the Corresponding Source conveyed under this section must be accompanied by the Installation Information. But this requirement does not apply if neither you nor any third party retains the ability to install modified object code on the User Product (for example, the work has been installed in ROM).
|
| 110 |
+
|
| 111 |
+
The requirement to provide Installation Information does not include a requirement to continue to provide support service, warranty, or updates for a work that has been modified or installed by the recipient, or for the User Product in which it has been modified or installed. Access to a network may be denied when the modification itself materially and adversely affects the operation of the network or violates the rules and protocols for communication across the network.
|
| 112 |
+
|
| 113 |
+
Corresponding Source conveyed, and Installation Information provided, in accord with this section must be in a format that is publicly documented (and with an implementation available to the public in source code form), and must require no special password or key for unpacking, reading or copying.
|
| 114 |
+
|
| 115 |
+
7. Additional Terms.
|
| 116 |
+
"Additional permissions" are terms that supplement the terms of this License by making exceptions from one or more of its conditions. Additional permissions that are applicable to the entire Program shall be treated as though they were included in this License, to the extent that they are valid under applicable law. If additional permissions apply only to part of the Program, that part may be used separately under those permissions, but the entire Program remains governed by this License without regard to the additional permissions.
|
| 117 |
+
|
| 118 |
+
When you convey a copy of a covered work, you may at your option remove any additional permissions from that copy, or from any part of it. (Additional permissions may be written to require their own removal in certain cases when you modify the work.) You may place additional permissions on material, added by you to a covered work, for which you have or can give appropriate copyright permission.
|
| 119 |
+
|
| 120 |
+
Notwithstanding any other provision of this License, for material you add to a covered work, you may (if authorized by the copyright holders of that material) supplement the terms of this License with terms:
|
| 121 |
+
|
| 122 |
+
a) Disclaiming warranty or limiting liability differently from the terms of sections 15 and 16 of this License; or
|
| 123 |
+
|
| 124 |
+
b) Requiring preservation of specified reasonable legal notices or author attributions in that material or in the Appropriate Legal Notices displayed by works containing it; or
|
| 125 |
+
|
| 126 |
+
c) Prohibiting misrepresentation of the origin of that material, or requiring that modified versions of such material be marked in reasonable ways as different from the original version; or
|
| 127 |
+
|
| 128 |
+
d) Limiting the use for publicity purposes of names of licensors or authors of the material; or
|
| 129 |
+
|
| 130 |
+
e) Declining to grant rights under trademark law for use of some trade names, trademarks, or service marks; or
|
| 131 |
+
|
| 132 |
+
f) Requiring indemnification of licensors and authors of that material by anyone who conveys the material (or modified versions of it) with contractual assumptions of liability to the recipient, for any liability that these contractual assumptions directly impose on those licensors and authors.
|
| 133 |
+
|
| 134 |
+
All other non-permissive additional terms are considered "further restrictions" within the meaning of section 10. If the Program as you received it, or any part of it, contains a notice stating that it is governed by this License along with a term that is a further restriction, you may remove that term. If a license document contains a further restriction but permits relicensing or conveying under this License, you may add to a covered work material governed by the terms of that license document, provided that the further restriction does not survive such relicensing or conveying.
|
| 135 |
+
|
| 136 |
+
If you add terms to a covered work in accord with this section, you must place, in the relevant source files, a statement of the additional terms that apply to those files, or a notice indicating where to find the applicable terms.
|
| 137 |
+
|
| 138 |
+
Additional terms, permissive or non-permissive, may be stated in the form of a separately written license, or stated as exceptions; the above requirements apply either way.
|
| 139 |
+
|
| 140 |
+
8. Termination.
|
| 141 |
+
|
| 142 |
+
You may not propagate or modify a covered work except as expressly provided under this License. Any attempt otherwise to propagate or modify it is void, and will automatically terminate your rights under this License (including any patent licenses granted under the third paragraph of section 11).
|
| 143 |
+
|
| 144 |
+
However, if you cease all violation of this License, then your license from a particular copyright holder is reinstated (a) provisionally, unless and until the copyright holder explicitly and finally terminates your license, and (b) permanently, if the copyright holder fails to notify you of the violation by some reasonable means prior to 60 days after the cessation.
|
| 145 |
+
|
| 146 |
+
Moreover, your license from a particular copyright holder is reinstated permanently if the copyright holder notifies you of the violation by some reasonable means, this is the first time you have received notice of violation of this License (for any work) from that copyright holder, and you cure the violation prior to 30 days after your receipt of the notice.
|
| 147 |
+
|
| 148 |
+
Termination of your rights under this section does not terminate the licenses of parties who have received copies or rights from you under this License. If your rights have been terminated and not permanently reinstated, you do not qualify to receive new licenses for the same material under section 10.
|
| 149 |
+
|
| 150 |
+
9. Acceptance Not Required for Having Copies.
|
| 151 |
+
|
| 152 |
+
You are not required to accept this License in order to receive or run a copy of the Program. Ancillary propagation of a covered work occurring solely as a consequence of using peer-to-peer transmission to receive a copy likewise does not require acceptance. However, nothing other than this License grants you permission to propagate or modify any covered work. These actions infringe copyright if you do not accept this License. Therefore, by modifying or propagating a covered work, you indicate your acceptance of this License to do so.
|
| 153 |
+
|
| 154 |
+
10. Automatic Licensing of Downstream Recipients.
|
| 155 |
+
|
| 156 |
+
Each time you convey a covered work, the recipient automatically receives a license from the original licensors, to run, modify and propagate that work, subject to this License. You are not responsible for enforcing compliance by third parties with this License.
|
| 157 |
+
|
| 158 |
+
An "entity transaction" is a transaction transferring control of an organization, or substantially all assets of one, or subdividing an organization, or merging organizations. If propagation of a covered work results from an entity transaction, each party to that transaction who receives a copy of the work also receives whatever licenses to the work the party's predecessor in interest had or could give under the previous paragraph, plus a right to possession of the Corresponding Source of the work from the predecessor in interest, if the predecessor has it or can get it with reasonable efforts.
|
| 159 |
+
|
| 160 |
+
You may not impose any further restrictions on the exercise of the rights granted or affirmed under this License. For example, you may not impose a license fee, royalty, or other charge for exercise of rights granted under this License, and you may not initiate litigation (including a cross-claim or counterclaim in a lawsuit) alleging that any patent claim is infringed by making, using, selling, offering for sale, or importing the Program or any portion of it.
|
| 161 |
+
|
| 162 |
+
11. Patents.
|
| 163 |
+
|
| 164 |
+
A "contributor" is a copyright holder who authorizes use under this License of the Program or a work on which the Program is based. The work thus licensed is called the contributor's "contributor version".
|
| 165 |
+
|
| 166 |
+
A contributor's "essential patent claims" are all patent claims owned or controlled by the contributor, whether already acquired or hereafter acquired, that would be infringed by some manner, permitted by this License, of making, using, or selling its contributor version, but do not include claims that would be infringed only as a consequence of further modification of the contributor version. For purposes of this definition, "control" includes the right to grant patent sublicenses in a manner consistent with the requirements of this License.
|
| 167 |
+
|
| 168 |
+
Each contributor grants you a non-exclusive, worldwide, royalty-free patent license under the contributor's essential patent claims, to make, use, sell, offer for sale, import and otherwise run, modify and propagate the contents of its contributor version.
|
| 169 |
+
|
| 170 |
+
In the following three paragraphs, a "patent license" is any express agreement or commitment, however denominated, not to enforce a patent (such as an express permission to practice a patent or covenant not to sue for patent infringement). To "grant" such a patent license to a party means to make such an agreement or commitment not to enforce a patent against the party.
|
| 171 |
+
|
| 172 |
+
If you convey a covered work, knowingly relying on a patent license, and the Corresponding Source of the work is not available for anyone to copy, free of charge and under the terms of this License, through a publicly available network server or other readily accessible means, then you must either (1) cause the Corresponding Source to be so available, or (2) arrange to deprive yourself of the benefit of the patent license for this particular work, or (3) arrange, in a manner consistent with the requirements of this License, to extend the patent
|
| 173 |
+
license to downstream recipients. "Knowingly relying" means you have actual knowledge that, but for the patent license, your conveying the covered work in a country, or your recipient's use of the covered work in a country, would infringe one or more identifiable patents in that country that you have reason to believe are valid.
|
| 174 |
+
|
| 175 |
+
If, pursuant to or in connection with a single transaction or arrangement, you convey, or propagate by procuring conveyance of, a covered work, and grant a patent license to some of the parties receiving the covered work authorizing them to use, propagate, modify or convey a specific copy of the covered work, then the patent license you grant is automatically extended to all recipients of the covered work and works based on it.
|
| 176 |
+
|
| 177 |
+
A patent license is "discriminatory" if it does not include within the scope of its coverage, prohibits the exercise of, or is conditioned on the non-exercise of one or more of the rights that are specifically granted under this License. You may not convey a covered work if you are a party to an arrangement with a third party that is in the business of distributing software, under which you make payment to the third party based on the extent of your activity of conveying the work, and under which the third party grants, to any of the parties who would receive the covered work from you, a discriminatory patent license (a) in connection with copies of the covered work conveyed by you (or copies made from those copies), or (b) primarily for and in connection with specific products or compilations that contain the covered work, unless you entered into that arrangement, or that patent license was granted, prior to 28 March 2007.
|
| 178 |
+
|
| 179 |
+
Nothing in this License shall be construed as excluding or limiting any implied license or other defenses to infringement that may otherwise be available to you under applicable patent law.
|
| 180 |
+
|
| 181 |
+
12. No Surrender of Others' Freedom.
|
| 182 |
+
|
| 183 |
+
If conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this License, they do not excuse you from the conditions of this License. If you cannot convey a covered work so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may
|
| 184 |
+
not convey it at all. For example, if you agree to terms that obligate you to collect a royalty for further conveying from those to whom you convey the Program, the only way you could satisfy both those terms and this License would be to refrain entirely from conveying the Program.
|
| 185 |
+
|
| 186 |
+
13. Remote Network Interaction; Use with the GNU General Public License.
|
| 187 |
+
|
| 188 |
+
Notwithstanding any other provision of this License, if you modify the Program, your modified version must prominently offer all users interacting with it remotely through a computer network (if your version supports such interaction) an opportunity to receive the Corresponding Source of your version by providing access to the Corresponding Source from a network server at no charge, through some standard or customary means of facilitating copying of software. This Corresponding Source shall include the Corresponding Source for any work covered by version 3 of the GNU General Public License that is incorporated pursuant to the following paragraph.
|
| 189 |
+
|
| 190 |
+
Notwithstanding any other provision of this License, you have permission to link or combine any covered work with a work licensed under version 3 of the GNU General Public License into a single combined work, and to convey the resulting work. The terms of this License will continue to apply to the part which is the covered work, but the work with which it is combined will remain governed by version 3 of the GNU General Public License.
|
| 191 |
+
|
| 192 |
+
14. Revised Versions of this License.
|
| 193 |
+
|
| 194 |
+
The Free Software Foundation may publish revised and/or new versions of the GNU Affero General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns.
|
| 195 |
+
|
| 196 |
+
Each version is given a distinguishing version number. If the Program specifies that a certain numbered version of the GNU Affero General Public License "or any later version" applies to it, you have the option of following the terms and conditions either of that numbered version or of any later version published by the Free Software Foundation. If the Program does not specify a version number of the GNU Affero General Public License, you may choose any version ever published by the Free Software Foundation.
|
| 197 |
+
|
| 198 |
+
If the Program specifies that a proxy can decide which future versions of the GNU Affero General Public License can be used, that proxy's public statement of acceptance of a version permanently authorizes you to choose that version for the Program.
|
| 199 |
+
|
| 200 |
+
Later license versions may give you additional or different permissions. However, no additional obligations are imposed on any author or copyright holder as a result of your choosing to follow a later version.
|
| 201 |
+
|
| 202 |
+
15. Disclaimer of Warranty.
|
| 203 |
+
|
| 204 |
+
THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
|
| 205 |
+
|
| 206 |
+
16. Limitation of Liability.
|
| 207 |
+
|
| 208 |
+
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
|
| 209 |
+
|
| 210 |
+
17. Interpretation of Sections 15 and 16.
|
| 211 |
+
|
| 212 |
+
If the disclaimer of warranty and limitation of liability provided above cannot be given local legal effect according to their terms, reviewing courts shall apply local law that most closely approximates an absolute waiver of all civil liability in connection with the Program, unless a warranty or assumption of liability accompanies a copy of the Program in return for a fee.
|
| 213 |
+
|
| 214 |
+
END OF TERMS AND CONDITIONS
|
| 215 |
+
|
| 216 |
+
How to Apply These Terms to Your New Programs
|
| 217 |
+
|
| 218 |
+
If you develop a new program, and you want it to be of the greatest possible use to the public, the best way to achieve this is to make it free software which everyone can redistribute and change under these terms.
|
| 219 |
+
|
| 220 |
+
To do so, attach the following notices to the program. It is safest to attach them to the start of each source file to most effectively state the exclusion of warranty; and each file should have at least the "copyright" line and a pointer to where the full notice is found.
|
| 221 |
+
|
| 222 |
+
<one line to give the program's name and a brief idea of what it does.>
|
| 223 |
+
Copyright (C) <year> <name of author>
|
| 224 |
+
|
| 225 |
+
This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
|
| 226 |
+
|
| 227 |
+
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details.
|
| 228 |
+
|
| 229 |
+
You should have received a copy of the GNU Affero General Public License along with this program. If not, see <http://www.gnu.org/licenses/>.
|
| 230 |
+
|
| 231 |
+
Also add information on how to contact you by electronic and paper mail.
|
| 232 |
+
|
| 233 |
+
If your software can interact with users remotely through a computer network, you should also make sure that it provides a way for users to get its source. For example, if your program is a web application, its interface could display a "Source" link that leads users to an archive of the code. There are many ways you could offer source, and different solutions will be better for different programs; see section 13 for the specific requirements.
|
| 234 |
+
|
| 235 |
+
You should also get your employer (if you work as a programmer) or school, if any, to sign a "copyright disclaimer" for the program, if necessary. For more information on this, and how to apply and follow the GNU AGPL, see <http://www.gnu.org/licenses/>.
|
README.md
ADDED
|
@@ -0,0 +1,243 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
license: agpl-3.0
|
| 3 |
+
language: [af, be, bs, bg, ca, hr, cs, da, nl, en, et, fi, fr, gl, de, ha, hu, id, it, ky, lv, lt, pl, pt, ro, ru, sr, sk, sl, es, sv, tr, uk, vi, cy]
|
| 4 |
+
library_name: onnxruntime
|
| 5 |
+
pipeline_tag: automatic-speech-recognition
|
| 6 |
+
tags: [forced-alignment, word-timestamps, audiobooks, read-along, ctc, onnx, on-device, multilingual]
|
| 7 |
+
---
|
| 8 |
+
|
| 9 |
+
<div align="center">
|
| 10 |
+
|
| 11 |
+
# CavaAlign v1
|
| 12 |
+
|
| 13 |
+
**Audio + text → word timings, small enough for a phone. 35 languages. 16 MB.**
|
| 14 |
+
|
| 15 |
+
Give a recording and its text; get back when every word is spoken.
|
| 16 |
+
|
| 17 |
+
<a href="#"><img src="https://img.shields.io/badge/size-16%20MB-2a78d6" alt="16 MB"></a>
|
| 18 |
+
<a href="#"><img src="https://img.shields.io/badge/languages-35-2a78d6" alt="35 languages"></a>
|
| 19 |
+
<a href="#"><img src="https://img.shields.io/badge/runtime-ONNX%20Runtime%20CPU-2a78d6" alt="ONNX Runtime"></a>
|
| 20 |
+
<a href="#"><img src="https://img.shields.io/badge/timing-20%20ms%20frames-2a78d6" alt="20 ms frames"></a>
|
| 21 |
+
|
| 22 |
+
</div>
|
| 23 |
+
|
| 24 |
+
<img class="block dark:hidden" src="https://huggingface.co/cava-reader/cavaalign-v1/resolve/main/assets/compare.png" alt="CavaAlign v1: 16 MB, 88.0% of word starts within 50 ms, 0.3% of words more than 250 ms off or untimed, compared with wav2vec2-base, PocketSphinx, Vosk small-en, MMS-300m, NeMo Conformer-CTC S and Whisper small.en">
|
| 25 |
+
<img class="hidden dark:block" src="https://huggingface.co/cava-reader/cavaalign-v1/resolve/main/assets/compare_dark.png" alt="CavaAlign v1: 16 MB, 88.0% of word starts within 50 ms, 0.3% of words more than 250 ms off or untimed, compared with wav2vec2-base, PocketSphinx, Vosk small-en, MMS-300m, NeMo Conformer-CTC S and Whisper small.en">
|
| 26 |
+
|
| 27 |
+
## Highlights
|
| 28 |
+
|
| 29 |
+
- **Precise.** On 70 LibriSpeech test speakers, 88% of word starts land within 50 ms of
|
| 30 |
+
forced-alignment truth. That is close to the 89.5% where two independent references agree
|
| 31 |
+
with each other.
|
| 32 |
+
- **Small and fast.** 16 MB for all thirty-five languages, int8 weights, standard ONNX ops. Five
|
| 33 |
+
minutes of audio align in 12 s on a 4-core laptop CPU, with 0.4 GB peak memory.
|
| 34 |
+
- **Every word timed.** Each word in the text gets a time, and 0.3% are off by more than 250 ms.
|
| 35 |
+
Speech recognisers with word timestamps leave 5–20% of words untimed or far off.
|
| 36 |
+
- **Built for books.** Handles text that starts before the audio (front matter, chapter titles),
|
| 37 |
+
unread footnotes and spoken announcements, without transcribing.
|
| 38 |
+
|
| 39 |
+
## Quick start
|
| 40 |
+
|
| 41 |
+
```bash
|
| 42 |
+
pip install onnxruntime numpy soundfile regex num2words
|
| 43 |
+
hf download cava-reader/cavaalign-v1 --local-dir cavaalign-v1
|
| 44 |
+
python cavaalign-v1/align.py speech.wav speech.txt --lang en
|
| 45 |
+
```
|
| 46 |
+
|
| 47 |
+
```python
|
| 48 |
+
import sys; sys.path.insert(0, "cavaalign-v1")
|
| 49 |
+
import soundfile as sf
|
| 50 |
+
from align import load, align
|
| 51 |
+
|
| 52 |
+
sess, cfg = load()
|
| 53 |
+
audio, sr = sf.read("speech.wav", dtype="float32") # 16 kHz mono
|
| 54 |
+
with open("speech.txt", encoding="utf-8") as f:
|
| 55 |
+
text = f.read()
|
| 56 |
+
for w in align(sess, cfg, audio, text, lang="de")[:5]:
|
| 57 |
+
print(f"{w['start']:7.2f} {w['end']:7.2f} {w['word']}")
|
| 58 |
+
```
|
| 59 |
+
|
| 60 |
+
`pip install numba` is optional and makes long recordings about 4× faster. Audio of any length
|
| 61 |
+
works: `align.py` runs the model in short overlapping windows, so memory stays flat.
|
| 62 |
+
`num2words` is used to read digits in languages other than English; `regex` is optional.
|
| 63 |
+
|
| 64 |
+
## Android (Kotlin)
|
| 65 |
+
|
| 66 |
+
`kotlin/` contains the same romanizer and aligner as the Python code, plus an ONNX Runtime
|
| 67 |
+
wrapper. Given the same model output, the Kotlin and Python aligners produce the same timings.
|
| 68 |
+
|
| 69 |
+
1. Add `com.microsoft.onnxruntime:onnxruntime-android` (1.17 or newer) and copy the three files
|
| 70 |
+
in `kotlin/` into your project (package `dev.micr0.cavaalign`).
|
| 71 |
+
2. Ship `cavaalign.onnx` in your assets or download it on first use.
|
| 72 |
+
3. Align:
|
| 73 |
+
|
| 74 |
+
```kotlin
|
| 75 |
+
val model = CavaAlignModel(context.assets.open("cavaalign.onnx").readBytes())
|
| 76 |
+
val emissions = model.logProbs(audio) // FloatArray, 16 kHz mono, about [-1, 1]
|
| 77 |
+
val result = CavaAligner.fromText(text).align(emissions)
|
| 78 |
+
for (w in result.words) {
|
| 79 |
+
// w.wordIndex, w.startSec, w.endSec, w.measured
|
| 80 |
+
}
|
| 81 |
+
```
|
| 82 |
+
|
| 83 |
+
`wordIndex` counts words in the text you passed in: runs of letters and digits, with
|
| 84 |
+
apostrophes inside a word ("don't" is one word, "well-known" is two). `measured` is false for
|
| 85 |
+
words the audio did not cover. Their times are inherited from the previous word.
|
| 86 |
+
|
| 87 |
+
The aligner's memory grows with the length of the recording. Align long books one chapter or
|
| 88 |
+
section at a time, passing the text for that stretch of audio.
|
| 89 |
+
|
| 90 |
+
## Benchmark
|
| 91 |
+
|
| 92 |
+
English, 70 LibriSpeech test-clean / test-other speakers (about 60 s each, 12,195 words).
|
| 93 |
+
Truth is Montreal Forced Aligner word starts. Every system gets the exact text and runs the way its
|
| 94 |
+
users run it. Words a system leaves untimed count as misses. Systems with a constant timing delay
|
| 95 |
+
are scored with that delay removed, so they are not penalised for a fixed offset.
|
| 96 |
+
|
| 97 |
+
| Model | Size | Words within 50 ms | Off by > 250 ms or untimed |
|
| 98 |
+
|---|---:|---:|---:|
|
| 99 |
+
| **CavaAlign v1** | 16 MB | **88.0%** | **0.3%** |
|
| 100 |
+
| wav2vec2-base (WhisperX) | 378 MB | 84.4% | 0.4% |
|
| 101 |
+
| wav2vec2-large | 1.26 GB | 83.9% | 0.3% |
|
| 102 |
+
| HuBERT-large | 1.26 GB | 83.9% | 0.3% |
|
| 103 |
+
| data2vec-audio-base | 373 MB | 83.8% | 0.4% |
|
| 104 |
+
| PocketSphinx | 10 MB | 83.8% | 8.6% |
|
| 105 |
+
| Vosk en lgraph | 214 MB | 81.4% | 9.7% |
|
| 106 |
+
| Vosk small-en | 71 MB | 80.4% | 12.7% |
|
| 107 |
+
| MMS-300m aligner | 1.26 GB | 77.0% | 7.2% |
|
| 108 |
+
| NeMo Conformer-CTC S | 46 MB | 67.3% | 5.7% |
|
| 109 |
+
| NeMo Conformer-CTC M | 68 MB | 60.5% | 4.8% |
|
| 110 |
+
| Zipformer-CTC | 70 MB | 55.2% | 3.9% |
|
| 111 |
+
| Whisper small.en | 967 MB | 48.3% | 10.8% |
|
| 112 |
+
| Whisper tiny.en | 151 MB | 45.5% | 13.2% |
|
| 113 |
+
| NeMo Citrinet-512 | 38 MB | 44.0% | 7.0% |
|
| 114 |
+
| Whisper base.en | 290 MB | 42.4% | 19.9% |
|
| 115 |
+
|
| 116 |
+
Two independent MFA alignments of the same audio agree on **89.5%** of words within 50 ms, so this
|
| 117 |
+
benchmark cannot separate systems above roughly 90%. On the words where the two references agree
|
| 118 |
+
with each other, CavaAlign v1 is within 50 ms on **95.1%**.
|
| 119 |
+
|
| 120 |
+
## Languages
|
| 121 |
+
|
| 122 |
+
One model covers all thirty-five. Text is romanized per word (Cyrillic, umlauts and accents →
|
| 123 |
+
a–z), so there is no per-language download. Listed: every language tested with 70% or more of
|
| 124 |
+
word starts within 50 ms.
|
| 125 |
+
|
| 126 |
+
| Language | Words within 50 ms | > 250 ms off or untimed |
|
| 127 |
+
|---|---:|---:|
|
| 128 |
+
| Afrikaans † | 79.8% | 5.6% |
|
| 129 |
+
| Belarusian | 74.2% | 11.1% |
|
| 130 |
+
| Bosnian | 92.9% | 1.5% |
|
| 131 |
+
| Bulgarian | 94.9% | 2.0% |
|
| 132 |
+
| Catalan † | 85.8% | 3.4% |
|
| 133 |
+
| Croatian | 82.2% | 3.6% |
|
| 134 |
+
| Czech | 90.8% | 1.9% |
|
| 135 |
+
| Danish † | 82.2% | 3.9% |
|
| 136 |
+
| Dutch | 96.1% | 0.1% |
|
| 137 |
+
| English | 89.7% | 0.1% |
|
| 138 |
+
| Estonian † | 81.1% | 6.2% |
|
| 139 |
+
| Finnish † | 90.9% | 2.6% |
|
| 140 |
+
| French | 97.3% | 0.0% |
|
| 141 |
+
| Galician † | 90.6% | 2.2% |
|
| 142 |
+
| German | 96.0% | 0.0% |
|
| 143 |
+
| Hausa | 79.2% | 3.6% |
|
| 144 |
+
| Hungarian | 81.4% | 7.3% |
|
| 145 |
+
| Indonesian † | 70.6% | 9.6% |
|
| 146 |
+
| Italian | 80.9% | 6.4% |
|
| 147 |
+
| Kyrgyz | 82.5% | 4.3% |
|
| 148 |
+
| Latvian † | 89.4% | 1.9% |
|
| 149 |
+
| Lithuanian † | 85.5% | 4.9% |
|
| 150 |
+
| Polish | 98.9% | 0.0% |
|
| 151 |
+
| Portuguese | 93.7% | 0.0% |
|
| 152 |
+
| Romanian | 79.4% | 7.2% |
|
| 153 |
+
| Russian | 92.6% | 1.1% |
|
| 154 |
+
| Serbian | 85.3% | 1.5% |
|
| 155 |
+
| Slovak † | 87.0% | 1.9% |
|
| 156 |
+
| Slovenian † | 90.2% | 3.9% |
|
| 157 |
+
| Spanish | 95.6% | 0.4% |
|
| 158 |
+
| Swedish | 89.5% | 1.5% |
|
| 159 |
+
| Turkish | 88.1% | 1.7% |
|
| 160 |
+
| Ukrainian | 84.4% | 5.1% |
|
| 161 |
+
| Vietnamese | 82.6% | 5.0% |
|
| 162 |
+
| Welsh † | 75.0% | 7.6% |
|
| 163 |
+
|
| 164 |
+
Average over all thirty-five (plain mean of the rows): **86.7%** of word starts within 50 ms,
|
| 165 |
+
3.4% more than 250 ms off or untimed. Read speech with MFA reference timing; words missing
|
| 166 |
+
from MFA's pronunciation dictionaries get generated pronunciations (G2P), so every word is timed.
|
| 167 |
+
† MFA has no model for these languages, so their reference is an MFA model trained on Common Voice
|
| 168 |
+
audio with spelling-based pronunciations. On Czech, which has both, CavaAlign scores 88.4% against
|
| 169 |
+
that kind of reference and 90.8% against MFA's own.
|
| 170 |
+
|
| 171 |
+
Test audio: FLEURS for Afrikaans, Belarusian, Bosnian, Bulgarian, Catalan, Croatian, Czech, Danish,
|
| 172 |
+
Estonian, Finnish, Galician, Hausa, Hungarian, Indonesian, Kyrgyz, Latvian, Lithuanian, Romanian,
|
| 173 |
+
Serbian, Slovak, Slovenian, Swedish, Turkish, Ukrainian, Vietnamese and Welsh; LibriSpeech,
|
| 174 |
+
Multilingual LibriSpeech and Russian LibriSpeech for Dutch, English, French, German, Italian,
|
| 175 |
+
Polish, Portuguese, Russian and Spanish.
|
| 176 |
+
|
| 177 |
+
## Model
|
| 178 |
+
|
| 179 |
+
| | |
|
| 180 |
+
|---|---|
|
| 181 |
+
| Architecture | raw-waveform front end + 8-layer streaming conformer (d 256), CTC head |
|
| 182 |
+
| Parameters | 14.6 M |
|
| 183 |
+
| Weights | int8 (dynamic quantisation), fp32 compute |
|
| 184 |
+
| Input | `waveform` float32 `[batch, samples]` at 16 kHz mono, `lengths` int64 `[batch]` |
|
| 185 |
+
| Output | `log_probs` `[batch, frames, 29]` at 50 frames/s, `out_lengths` |
|
| 186 |
+
| Vocabulary | blank, a–z, apostrophe, unk (`vocab.json`) |
|
| 187 |
+
| Aligner | monotonic dynamic program with text-skip, audio-skip and front-matter arcs (`cavaalign/`) |
|
| 188 |
+
|
| 189 |
+
**Running it yourself:**
|
| 190 |
+
- Feed the model 6.4 s windows with 3.2 s of preceding context, cut on 0.64 s chunk boundaries
|
| 191 |
+
counted from the start of the audio (`align.py::log_probs`). Attention memory grows with the
|
| 192 |
+
square of the input length, so whole chapters in one pass will not fit.
|
| 193 |
+
- Create the ONNX Runtime session with the CPU memory arena and memory pattern disabled.
|
| 194 |
+
- Romanize the text before tokenizing (`cavaalign/romanize.py`); a space maps to the blank id.
|
| 195 |
+
- Frames are 20 ms (`frame_shift_sec` in `align_config.json`).
|
| 196 |
+
|
| 197 |
+
## Files
|
| 198 |
+
|
| 199 |
+
| file | |
|
| 200 |
+
|---|---|
|
| 201 |
+
| `cavaalign.onnx` | the model |
|
| 202 |
+
| `align.py`, `cavaalign/` | Python reference: romanizer and aligner (numpy) |
|
| 203 |
+
| `align_config.json`, `vocab.json` | aligner settings, vocabulary, frame shift |
|
| 204 |
+
| `kotlin/` | the same romanizer and aligner in Kotlin, plus an ONNX Runtime wrapper, for Android |
|
| 205 |
+
| `reference/` | English, German and Russian clips with expected outputs, to check a port |
|
| 206 |
+
| `SHA256SUMS` | checksums (`sha256sum -c SHA256SUMS`) |
|
| 207 |
+
| `LICENSE` | GNU Affero General Public License v3 |
|
| 208 |
+
|
| 209 |
+
To check a port, run each `reference/*.wav` with its `.txt` and compare with `.expected.json`:
|
| 210 |
+
`romanized_text` must match exactly, `log_probs_frames` must be equal, and word times should match
|
| 211 |
+
to the frame (an occasional one-frame difference from int8 rounding on ARM is normal).
|
| 212 |
+
|
| 213 |
+
## Limitations
|
| 214 |
+
|
| 215 |
+
- It aligns given text; it does not transcribe. Speech that is not in the text is skipped.
|
| 216 |
+
- Built for read speech (audiobooks).
|
| 217 |
+
- Precision drops when the text window is much wider than the audio. Hand it the text for the
|
| 218 |
+
stretch being played, with modest slack.
|
| 219 |
+
- Digits are read with language-specific number words in Python; the Kotlin port uses English
|
| 220 |
+
readings.
|
| 221 |
+
- Latin and Cyrillic scripts only. Turkish ç and ü are romanized approximately (as "s" and "ue"),
|
| 222 |
+
and Hausa's hooked letters (ɓ ɗ ƙ) are dropped; the words still align from their other letters.
|
| 223 |
+
|
| 224 |
+
## Reference clips
|
| 225 |
+
|
| 226 |
+
The clips in `reference/` are 30 s excerpts of LibriVox recordings:
|
| 227 |
+
|
| 228 |
+
- `en_*`: LibriSpeech test-clean, speaker 1089, chapter 134686 ([OpenSLR 12](https://openslr.org/12), CC BY 4.0).
|
| 229 |
+
- `de_*`: Multilingual LibriSpeech German, speaker 3363, book 2124 ([OpenSLR 94](https://openslr.org/94), CC BY 4.0).
|
| 230 |
+
- `ru_*`: Russian LibriSpeech ([OpenSLR 96](https://openslr.org/96), public domain in the USA).
|
| 231 |
+
|
| 232 |
+
## License
|
| 233 |
+
|
| 234 |
+
Copyright (C) 2026 Cava Reader.
|
| 235 |
+
|
| 236 |
+
CavaAlign (the model weights in `cavaalign.onnx` and all code in this repository) is free
|
| 237 |
+
software: you can redistribute it and/or modify it under the terms of the GNU Affero General
|
| 238 |
+
Public License as published by the Free Software Foundation, either version 3 of the License,
|
| 239 |
+
or (at your option) any later version. See `LICENSE`. The reference clips keep their own
|
| 240 |
+
licenses, listed above.
|
| 241 |
+
|
| 242 |
+
It is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the
|
| 243 |
+
implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
SHA256SUMS
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
d8a6cc31abc16b6748c7a21f21611f5a1ec33f67d22ca23d7da1c19b95496bee ./LICENSE
|
| 2 |
+
c3837771cf6a0794b9453e4469ddca6580ea77a874d20c3913b660409a6dce29 ./README.md
|
| 3 |
+
7318a54f7d246fcad8332b22639f4314e123a41c88e0d0fecd2b95bb0bec7f9e ./align.py
|
| 4 |
+
ebc258f7ec8389c4a491fe58ac53492abff44b4ff012897ec8ef9d95892134bb ./align_config.json
|
| 5 |
+
30f5071697a5fa1be478c78b53ff521e33bcfa434c43eb5860fa86e416fabd50 ./assets/compare.png
|
| 6 |
+
0b82348439b96c084041016d8ffcf35daf4ccebf8e89e669a53c0b8f7fc2e626 ./assets/compare_dark.png
|
| 7 |
+
23c16f513ee5bc242d0df41c191f0b297a49ef52761a4c0f1beca10f1f148de1 ./cavaalign/__init__.py
|
| 8 |
+
1b6f64183af5c888d9e8bb680e7f444519476e70c8aff40df3576fc378ccfa28 ./cavaalign/align.py
|
| 9 |
+
cabd8e6c6f907d5a981add25684a3eaad7c6ee7cb2be0ed998d74d51230d8de4 ./cavaalign/romanize.py
|
| 10 |
+
ed20c5b1493e83d83d15cf843ab40d94256fddeeebb38b52e3df8c0ef0e7f9cb ./cavaalign/vocab.py
|
| 11 |
+
79b0aeafd305ba663a399251e61b3f98be608f16edefa40b73b6e67eddc548be ./cavaalign.onnx
|
| 12 |
+
b3e273610e3c3d636043a098b8fe406c813212166d2423e1bccb56013a6cfe09 ./kotlin/CavaAlignModel.kt
|
| 13 |
+
0ff31ca9ffc3a67c5455fe6b5af330b5ae49d09df6dd4359181202d4a49ed958 ./kotlin/CavaAligner.kt
|
| 14 |
+
6af6855f7478d2e61438e43bd703a2317cf04d1a232d729cbf5cc6d82924d0b3 ./kotlin/Romanizer.kt
|
| 15 |
+
6e808bca3ac04f768949cb2e75cf18ed99648a623056399e481640afc41e9f73 ./reference/de_de.3363_2124.00.expected.json
|
| 16 |
+
46bf0b4b9df4dd82efd5ad4163c6ad4a6142658b59ec83dd846941eb76b23308 ./reference/de_de.3363_2124.00.txt
|
| 17 |
+
d21f83b1f999292425c4833d1154dade380499fec27c0de360365c0d61d9a147 ./reference/de_de.3363_2124.00.wav
|
| 18 |
+
c9da619d1deb006ab92fa9d89c4fad04e46c168540d2287abbac25ad5ab4e1eb ./reference/en_en.testclean1089_134686.00.expected.json
|
| 19 |
+
23f4d6cadeb602d94162abdbb5dfbe474f1f9b4c666673cebf88a29e349f8983 ./reference/en_en.testclean1089_134686.00.txt
|
| 20 |
+
66b405bf1c8c8ee2b4231174cf7b319421661338698441a6d54ff54a62fe9534 ./reference/en_en.testclean1089_134686.00.wav
|
| 21 |
+
951f1adafd25e8ae303631d5941720e0d35f587c4e97dafa25be4cf521172faf ./reference/ru_ru.ru.00.expected.json
|
| 22 |
+
24e1c2e1b288ee4e70d28ddc93e00933909b845fb60e76edd0799c79288f1352 ./reference/ru_ru.ru.00.txt
|
| 23 |
+
35bfc42e86731ee243b9a14af8d4692fc33177010ebadfce99f1531590cd332a ./reference/ru_ru.ru.00.wav
|
| 24 |
+
49ec2b7e1547c848e1d32da5820dcba6808bf01e9f17ee4d45771933d0a0fd80 ./vocab.json
|
align.py
ADDED
|
@@ -0,0 +1,81 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env python3
|
| 2 |
+
# SPDX-License-Identifier: AGPL-3.0-or-later
|
| 3 |
+
"""Word timings for an audio file and its text with CavaAlign.
|
| 4 |
+
|
| 5 |
+
pip install onnxruntime numpy soundfile regex num2words
|
| 6 |
+
python align.py speech.wav text.txt --lang en > words.json
|
| 7 |
+
"""
|
| 8 |
+
import argparse
|
| 9 |
+
import json
|
| 10 |
+
import os
|
| 11 |
+
|
| 12 |
+
import numpy as np
|
| 13 |
+
import onnxruntime as ort
|
| 14 |
+
import soundfile as sf
|
| 15 |
+
|
| 16 |
+
import sys
|
| 17 |
+
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
|
| 18 |
+
from cavaalign.align import AlignConfig, expansion_to_tokens, forced_align, linear_band_center, spans_to_words
|
| 19 |
+
from cavaalign.romanize import prepare_text
|
| 20 |
+
from cavaalign.vocab import vocab_for_tokens
|
| 21 |
+
|
| 22 |
+
HERE = os.path.dirname(os.path.abspath(__file__))
|
| 23 |
+
|
| 24 |
+
|
| 25 |
+
def load(model=os.path.join(HERE, "cavaalign.onnx")):
|
| 26 |
+
so = ort.SessionOptions()
|
| 27 |
+
so.enable_cpu_mem_arena = False # keeps memory flat on long recordings
|
| 28 |
+
so.enable_mem_pattern = False
|
| 29 |
+
sess = ort.InferenceSession(model, so, providers=["CPUExecutionProvider"])
|
| 30 |
+
with open(os.path.join(HERE, "align_config.json"), encoding="utf-8") as f:
|
| 31 |
+
cfg = json.load(f)
|
| 32 |
+
return sess, cfg
|
| 33 |
+
|
| 34 |
+
|
| 35 |
+
CHUNK = 32 * 320 # the model's attention chunk: 32 frames of 20 ms = 10,240 samples
|
| 36 |
+
|
| 37 |
+
|
| 38 |
+
def log_probs(sess, audio, window_chunks=10, context_chunks=5):
|
| 39 |
+
"""Model output for any length of audio in bounded memory.
|
| 40 |
+
|
| 41 |
+
Attention memory grows with the square of the input length, so long audio is run in windows
|
| 42 |
+
of `window_chunks` chunks (6.4 s) with `context_chunks` (3.2 s) of preceding audio as
|
| 43 |
+
context, cut on chunk boundaries. Same precision as one pass, about 0.3 GB peak.
|
| 44 |
+
"""
|
| 45 |
+
a = np.asarray(audio, dtype=np.float32)
|
| 46 |
+
out, pos = [], 0
|
| 47 |
+
while pos < len(a):
|
| 48 |
+
st = max(0, pos - context_chunks * CHUNK)
|
| 49 |
+
x = a[st: pos + window_chunks * CHUNK + 80] # +80: the last frame spans 400 samples
|
| 50 |
+
lp, n = sess.run(None, {"waveform": x[None], "lengths": np.array([len(x)], dtype=np.int64)})
|
| 51 |
+
skip = (pos - st) // 320
|
| 52 |
+
out.append(lp[0, skip: min(int(n[0]), skip + window_chunks * 32)])
|
| 53 |
+
pos += window_chunks * CHUNK
|
| 54 |
+
return np.concatenate(out)
|
| 55 |
+
|
| 56 |
+
|
| 57 |
+
def align(sess, cfg, audio, text, lang="en"):
|
| 58 |
+
"""audio: float32 mono 16 kHz. Returns [{word, start, end}] for every word of `text`."""
|
| 59 |
+
lp = log_probs(sess, audio)
|
| 60 |
+
exp = prepare_text(text, lang)
|
| 61 |
+
toks = expansion_to_tokens(exp, vocab_for_tokens(cfg["vocab_tokens"]))
|
| 62 |
+
res = forced_align(lp, toks, AlignConfig(**cfg["align"]), linear_band_center(len(lp), len(toks)))
|
| 63 |
+
words = spans_to_words(text, res.spans, cfg["frame_shift_sec"], expansion=exp, emissions=lp)
|
| 64 |
+
return [{"word": exp.words[i], "start": round(s, 3), "end": round(e, 3)} for i, s, e, _ in words]
|
| 65 |
+
|
| 66 |
+
|
| 67 |
+
if __name__ == "__main__":
|
| 68 |
+
ap = argparse.ArgumentParser()
|
| 69 |
+
ap.add_argument("audio")
|
| 70 |
+
ap.add_argument("text")
|
| 71 |
+
ap.add_argument("--lang", default="en", help="ISO 639-1 code of the text (see README for the 35 languages)")
|
| 72 |
+
a = ap.parse_args()
|
| 73 |
+
audio, sr = sf.read(a.audio, dtype="float32")
|
| 74 |
+
if audio.ndim > 1:
|
| 75 |
+
audio = audio.mean(1)
|
| 76 |
+
if sr != 16000:
|
| 77 |
+
raise SystemExit(f"{a.audio}: expected 16 kHz, got {sr} Hz (resample first, e.g. ffmpeg -ar 16000 -ac 1)")
|
| 78 |
+
sess, cfg = load()
|
| 79 |
+
with open(a.text, encoding="utf-8") as f:
|
| 80 |
+
text = f.read()
|
| 81 |
+
print(json.dumps(align(sess, cfg, audio, text, a.lang), ensure_ascii=False, indent=1))
|
align_config.json
ADDED
|
@@ -0,0 +1,92 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"name": "cavaalign-v1",
|
| 3 |
+
"align": {
|
| 4 |
+
"free_text_prefix": true,
|
| 5 |
+
"log_text_skip": -4.0,
|
| 6 |
+
"log_audio_skip": -5.0,
|
| 7 |
+
"log_prefix_skip": -0.15,
|
| 8 |
+
"max_prefix_tokens": 6000,
|
| 9 |
+
"band": 512,
|
| 10 |
+
"emit_floor": -20.0
|
| 11 |
+
},
|
| 12 |
+
"kotlin_align_params": {
|
| 13 |
+
"freeTextPrefix": true,
|
| 14 |
+
"logTextSkip": -4.0,
|
| 15 |
+
"logAudioSkip": -5.0,
|
| 16 |
+
"logPrefixSkip": -0.15,
|
| 17 |
+
"maxPrefixTokens": 6000,
|
| 18 |
+
"band": 512,
|
| 19 |
+
"emitFloor": -20.0
|
| 20 |
+
},
|
| 21 |
+
"vocab_tokens": [
|
| 22 |
+
"<blank>",
|
| 23 |
+
"a",
|
| 24 |
+
"i",
|
| 25 |
+
"e",
|
| 26 |
+
"n",
|
| 27 |
+
"o",
|
| 28 |
+
"u",
|
| 29 |
+
"t",
|
| 30 |
+
"s",
|
| 31 |
+
"r",
|
| 32 |
+
"m",
|
| 33 |
+
"k",
|
| 34 |
+
"l",
|
| 35 |
+
"d",
|
| 36 |
+
"g",
|
| 37 |
+
"h",
|
| 38 |
+
"y",
|
| 39 |
+
"b",
|
| 40 |
+
"p",
|
| 41 |
+
"w",
|
| 42 |
+
"c",
|
| 43 |
+
"v",
|
| 44 |
+
"j",
|
| 45 |
+
"z",
|
| 46 |
+
"f",
|
| 47 |
+
"'",
|
| 48 |
+
"q",
|
| 49 |
+
"x",
|
| 50 |
+
"<unk>"
|
| 51 |
+
],
|
| 52 |
+
"frame_shift_sec": 0.02,
|
| 53 |
+
"sample_rate": 16000,
|
| 54 |
+
"languages": [
|
| 55 |
+
"af",
|
| 56 |
+
"be",
|
| 57 |
+
"bs",
|
| 58 |
+
"bg",
|
| 59 |
+
"ca",
|
| 60 |
+
"hr",
|
| 61 |
+
"cs",
|
| 62 |
+
"da",
|
| 63 |
+
"nl",
|
| 64 |
+
"en",
|
| 65 |
+
"et",
|
| 66 |
+
"fi",
|
| 67 |
+
"fr",
|
| 68 |
+
"gl",
|
| 69 |
+
"de",
|
| 70 |
+
"ha",
|
| 71 |
+
"hu",
|
| 72 |
+
"id",
|
| 73 |
+
"it",
|
| 74 |
+
"ky",
|
| 75 |
+
"lv",
|
| 76 |
+
"lt",
|
| 77 |
+
"pl",
|
| 78 |
+
"pt",
|
| 79 |
+
"ro",
|
| 80 |
+
"ru",
|
| 81 |
+
"sr",
|
| 82 |
+
"sk",
|
| 83 |
+
"sl",
|
| 84 |
+
"es",
|
| 85 |
+
"sv",
|
| 86 |
+
"tr",
|
| 87 |
+
"uk",
|
| 88 |
+
"vi",
|
| 89 |
+
"cy"
|
| 90 |
+
],
|
| 91 |
+
"romanizer": "cavaalign/romanize.py (Kotlin: kotlin/Romanizer.kt)"
|
| 92 |
+
}
|
assets/compare.png
ADDED
|
Git LFS Details
|
assets/compare_dark.png
ADDED
|
Git LFS Details
|
cavaalign.onnx
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:79b0aeafd305ba663a399251e61b3f98be608f16edefa40b73b6e67eddc548be
|
| 3 |
+
size 16020441
|
cavaalign/__init__.py
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# SPDX-License-Identifier: AGPL-3.0-or-later
|
| 2 |
+
"""CavaAlign: romanizer and alignment DP for the cavaalign.onnx acoustic model."""
|
cavaalign/align.py
ADDED
|
@@ -0,0 +1,1031 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# SPDX-License-Identifier: AGPL-3.0-or-later
|
| 2 |
+
"""Forced alignment of book text to CTC emissions, with skip arcs.
|
| 3 |
+
|
| 4 |
+
Given a `(T, V)` matrix of per-frame log-probabilities and the text, recover the time span of
|
| 5 |
+
every word. Unlike plain CTC forced alignment, the text does not have to match the audio exactly:
|
| 6 |
+
the DP can skip audio that is not in the text (announcements, music) and text that is never
|
| 7 |
+
spoken (front matter, unread footnotes), each at a penalty.
|
| 8 |
+
|
| 9 |
+
States are `(t, j, b)`: `t` audio frames consumed, `j` text tokens consumed, and `b` says whether
|
| 10 |
+
the path is inside token `j-1` or at a boundary. Arcs:
|
| 11 |
+
|
| 12 |
+
1. blank `(t-1, j, *) -> (t, j, boundary)`, scored by the blank column.
|
| 13 |
+
2. emit `(t-1, j-1, *) -> (t, j, inside)`, scored by token `j-1`'s column.
|
| 14 |
+
3. extend `(t-1, j, inside) -> (t, j, inside)`, token `j-1` continues.
|
| 15 |
+
4. audio skip `(t-1, j, *) -> (t, j, boundary)`, a frame of sound not in the text.
|
| 16 |
+
5. text skip `(t, j-1, *) -> (t, j, boundary)`, a token that is never spoken.
|
| 17 |
+
|
| 18 |
+
Leading text can be skipped at a much lower rate (`free_text_prefix`), up to
|
| 19 |
+
`max_prefix_tokens`. Complexity is `O(T * band)` with a band around the expected diagonal.
|
| 20 |
+
"""
|
| 21 |
+
|
| 22 |
+
from __future__ import annotations
|
| 23 |
+
|
| 24 |
+
import math
|
| 25 |
+
from dataclasses import dataclass, field
|
| 26 |
+
from typing import Sequence
|
| 27 |
+
|
| 28 |
+
import numpy as np
|
| 29 |
+
|
| 30 |
+
NEG_INF = float("-inf")
|
| 31 |
+
BIG_NEG = -1.0e18
|
| 32 |
+
|
| 33 |
+
# backpointer arc ids
|
| 34 |
+
ARC_BLANK, ARC_EMIT, ARC_AUDIO_SKIP, ARC_TEXT_SKIP, ARC_EXTEND = 0, 1, 2, 3, 4
|
| 35 |
+
# bucket ids
|
| 36 |
+
BOUNDARY, INSIDE = 0, 1
|
| 37 |
+
|
| 38 |
+
|
| 39 |
+
@dataclass
|
| 40 |
+
class Token:
|
| 41 |
+
"""One alignable character of the expanded text.
|
| 42 |
+
|
| 43 |
+
Space tokens are scored by the blank column (a word gap is silence) and belong to no word.
|
| 44 |
+
"""
|
| 45 |
+
|
| 46 |
+
text: str
|
| 47 |
+
id: int
|
| 48 |
+
is_space: bool = False
|
| 49 |
+
|
| 50 |
+
|
| 51 |
+
@dataclass
|
| 52 |
+
class Expansion:
|
| 53 |
+
"""Text rewritten into alignable characters, plus the map back to word indices.
|
| 54 |
+
|
| 55 |
+
`char_to_word[i]` is the word index of character `i`, or -1 for an inter-word space.
|
| 56 |
+
`groups` holds `(start, end, readings)` for written forms with several spoken readings
|
| 57 |
+
(numbers), used by [resolve_ambiguous].
|
| 58 |
+
"""
|
| 59 |
+
|
| 60 |
+
text: str
|
| 61 |
+
char_to_word: list[int]
|
| 62 |
+
words: list[str]
|
| 63 |
+
groups: list[tuple[int, int, tuple[str, ...]]] = field(default_factory=list)
|
| 64 |
+
|
| 65 |
+
|
| 66 |
+
@dataclass
|
| 67 |
+
class AlignConfig:
|
| 68 |
+
"""DP settings. The defaults match `align_config.json`."""
|
| 69 |
+
|
| 70 |
+
blank: int = 0
|
| 71 |
+
log_audio_skip: float = -5.0 # added to the frame's best non-blank log-prob
|
| 72 |
+
log_text_skip: float = -4.0 # per text token never spoken
|
| 73 |
+
band: int = 512 # half-width in tokens around the band center; 0 = no band
|
| 74 |
+
emit_floor: float = -20.0 # lower bound on emission scores
|
| 75 |
+
pad_frames: int = 0 # widen each token span by this many frames either side
|
| 76 |
+
free_text_prefix: bool = True # leading text may be skipped at `log_prefix_skip` per token
|
| 77 |
+
log_prefix_skip: float = -0.15
|
| 78 |
+
max_prefix_tokens: int = 6000
|
| 79 |
+
|
| 80 |
+
|
| 81 |
+
@dataclass
|
| 82 |
+
class TokenSpan:
|
| 83 |
+
token_index: int
|
| 84 |
+
text: str
|
| 85 |
+
start_frame: int
|
| 86 |
+
end_frame: int # exclusive
|
| 87 |
+
skipped_text: bool = False
|
| 88 |
+
unmatched: bool = False # never emitted; the span is inherited from the previous token
|
| 89 |
+
|
| 90 |
+
|
| 91 |
+
@dataclass
|
| 92 |
+
class AlignResult:
|
| 93 |
+
spans: list[TokenSpan]
|
| 94 |
+
total_score: float
|
| 95 |
+
frames: int
|
| 96 |
+
audio_skips: int
|
| 97 |
+
text_skips: int
|
| 98 |
+
unmatched: int = 0
|
| 99 |
+
prefix_skipped: int = 0 # leading tokens treated as unspoken front matter
|
| 100 |
+
matched_frames: int = 0 # frames consumed by emit or extend arcs
|
| 101 |
+
|
| 102 |
+
@property
|
| 103 |
+
def skipped_audio_ratio(self) -> float:
|
| 104 |
+
return self.audio_skips / max(1, self.frames)
|
| 105 |
+
|
| 106 |
+
@property
|
| 107 |
+
def skipped_text_ratio(self) -> float:
|
| 108 |
+
return (self.text_skips + self.unmatched) / max(1, len(self.spans))
|
| 109 |
+
|
| 110 |
+
@property
|
| 111 |
+
def spoken_fraction(self) -> float:
|
| 112 |
+
"""Fraction of non-space tokens after the prefix that were matched to audio."""
|
| 113 |
+
ev = self._evidence_spans()
|
| 114 |
+
if not ev:
|
| 115 |
+
return 0.0
|
| 116 |
+
return sum(1 for s in ev if not s.unmatched) / len(ev)
|
| 117 |
+
|
| 118 |
+
@property
|
| 119 |
+
def prefix_ratio(self) -> float:
|
| 120 |
+
"""Fraction of the text treated as unspoken front matter."""
|
| 121 |
+
if not self.spans:
|
| 122 |
+
return 0.0
|
| 123 |
+
return self.prefix_skipped / len(self.spans)
|
| 124 |
+
|
| 125 |
+
@property
|
| 126 |
+
def audio_matched_fraction(self) -> float:
|
| 127 |
+
"""Fraction of audio frames accounted for by the text."""
|
| 128 |
+
return self.matched_frames / max(1, self.frames)
|
| 129 |
+
|
| 130 |
+
@property
|
| 131 |
+
def is_probable_mismatch(self) -> bool:
|
| 132 |
+
"""True when the recording most likely does not correspond to the text."""
|
| 133 |
+
return self.prefix_ratio > 0.25 and self.audio_matched_fraction < 0.5
|
| 134 |
+
|
| 135 |
+
def _evidence_spans(self) -> list[TokenSpan]:
|
| 136 |
+
return [s for s in self.spans[self.prefix_skipped:] if s.text != " "]
|
| 137 |
+
|
| 138 |
+
@property
|
| 139 |
+
def measured_ratio(self) -> float:
|
| 140 |
+
"""Fraction of non-space tokens after the prefix whose span was measured from audio."""
|
| 141 |
+
ev = self._evidence_spans()
|
| 142 |
+
if not ev:
|
| 143 |
+
return 0.0
|
| 144 |
+
return sum(1 for s in ev if not s.unmatched) / len(ev)
|
| 145 |
+
|
| 146 |
+
|
| 147 |
+
# --------------------------------------------------------------------------------------
|
| 148 |
+
# The DP kernel
|
| 149 |
+
# --------------------------------------------------------------------------------------
|
| 150 |
+
|
| 151 |
+
try:
|
| 152 |
+
from numba import njit
|
| 153 |
+
|
| 154 |
+
_HAS_NUMBA = True
|
| 155 |
+
except Exception: # pragma: no cover
|
| 156 |
+
_HAS_NUMBA = False
|
| 157 |
+
|
| 158 |
+
def njit(*a, **k):
|
| 159 |
+
def deco(f):
|
| 160 |
+
return f
|
| 161 |
+
if a and callable(a[0]):
|
| 162 |
+
return a[0]
|
| 163 |
+
return deco
|
| 164 |
+
|
| 165 |
+
|
| 166 |
+
if _HAS_NUMBA:
|
| 167 |
+
@njit(cache=True)
|
| 168 |
+
def _dp_core(lp, tok_ids, is_space, blank_col, speech_col, lo, hi, ts, asp, J, T, W,
|
| 169 |
+
init_in, init_bd, bp_in, bp_bd, final_in, final_bd):
|
| 170 |
+
"""Two-bucket forward DP (compiled). Writes backpointers into `bp_in` / `bp_bd`.
|
| 171 |
+
|
| 172 |
+
`lo`/`hi` (T,): per-frame half-open band over j, both non-decreasing.
|
| 173 |
+
`init_in`/`init_bd` (J+1,): initial DP row. Backpointers are indexed `[t, j - lo[t]]`
|
| 174 |
+
and hold `arc * 2 + source_bucket`. Returns (terminal score, terminal bucket, 0).
|
| 175 |
+
"""
|
| 176 |
+
BIG = np.float32(-1.0e18)
|
| 177 |
+
EMIT_FLOOR = np.float32(-20.0)
|
| 178 |
+
prev_in = init_in.copy()
|
| 179 |
+
prev_bd = init_bd.copy()
|
| 180 |
+
cur_in = np.full(J + 1, BIG, np.float32)
|
| 181 |
+
cur_bd = np.full(J + 1, BIG, np.float32)
|
| 182 |
+
prev_a = 0
|
| 183 |
+
prev_b = 0
|
| 184 |
+
start_j = 0
|
| 185 |
+
# Row buffers are swapped, so slots outside the current band are reset to BIG.
|
| 186 |
+
cur_dlo = 0
|
| 187 |
+
cur_dhi = 0
|
| 188 |
+
prev_dlo = 0
|
| 189 |
+
prev_dhi = J + 1
|
| 190 |
+
|
| 191 |
+
for t in range(T):
|
| 192 |
+
a = lo[t]
|
| 193 |
+
b = hi[t]
|
| 194 |
+
bt = blank_col[t]
|
| 195 |
+
for j in range(prev_a, a):
|
| 196 |
+
prev_in[j] = BIG
|
| 197 |
+
prev_bd[j] = BIG
|
| 198 |
+
for j in range(b, prev_b):
|
| 199 |
+
prev_in[j] = BIG
|
| 200 |
+
prev_bd[j] = BIG
|
| 201 |
+
prev_a = a
|
| 202 |
+
prev_b = b
|
| 203 |
+
for j in range(cur_dlo, min(a, cur_dhi)):
|
| 204 |
+
cur_in[j] = BIG
|
| 205 |
+
cur_bd[j] = BIG
|
| 206 |
+
for j in range(max(b, cur_dlo), cur_dhi):
|
| 207 |
+
cur_in[j] = BIG
|
| 208 |
+
cur_bd[j] = BIG
|
| 209 |
+
cur_dlo = a
|
| 210 |
+
cur_dhi = b
|
| 211 |
+
for j in range(a, b):
|
| 212 |
+
cur_in[j] = BIG
|
| 213 |
+
cur_bd[j] = BIG
|
| 214 |
+
bp_in[t, j - a] = 255
|
| 215 |
+
bp_bd[t, j - a] = 255
|
| 216 |
+
|
| 217 |
+
# boundary bucket: blank, audio skip
|
| 218 |
+
p_in = prev_in[j]
|
| 219 |
+
p_bd = prev_bd[j]
|
| 220 |
+
best = BIG
|
| 221 |
+
choice = np.uint8(255)
|
| 222 |
+
src = np.uint8(0)
|
| 223 |
+
if p_in > BIG / 2.0 or p_bd > BIG / 2.0:
|
| 224 |
+
if p_in >= p_bd:
|
| 225 |
+
best = p_in + bt
|
| 226 |
+
src = np.uint8(1)
|
| 227 |
+
else:
|
| 228 |
+
best = p_bd + bt
|
| 229 |
+
src = np.uint8(0)
|
| 230 |
+
choice = np.uint8(ARC_BLANK * 2) + src
|
| 231 |
+
cand_src = np.uint8(1) if p_in >= p_bd else np.uint8(0)
|
| 232 |
+
cand = (p_in if p_in >= p_bd else p_bd) + speech_col[t] + asp
|
| 233 |
+
if cand > best:
|
| 234 |
+
best = cand
|
| 235 |
+
choice = np.uint8(ARC_AUDIO_SKIP * 2) + cand_src
|
| 236 |
+
cur_bd[j] = best
|
| 237 |
+
bp_bd[t, j - a] = choice
|
| 238 |
+
|
| 239 |
+
# inside bucket: emit token j-1, or extend it
|
| 240 |
+
besti = BIG
|
| 241 |
+
choicei = np.uint8(255)
|
| 242 |
+
if j > 0:
|
| 243 |
+
k = j - 1
|
| 244 |
+
if is_space[k]:
|
| 245 |
+
e = bt
|
| 246 |
+
else:
|
| 247 |
+
e = lp[t, tok_ids[k]]
|
| 248 |
+
if e < EMIT_FLOOR:
|
| 249 |
+
e = EMIT_FLOOR
|
| 250 |
+
q_in = prev_in[j - 1]
|
| 251 |
+
q_bd = prev_bd[j - 1]
|
| 252 |
+
if q_in >= q_bd:
|
| 253 |
+
cand = q_in + e
|
| 254 |
+
csrc = np.uint8(1)
|
| 255 |
+
else:
|
| 256 |
+
cand = q_bd + e
|
| 257 |
+
csrc = np.uint8(0)
|
| 258 |
+
if cand > besti:
|
| 259 |
+
besti = cand
|
| 260 |
+
choicei = np.uint8(ARC_EMIT * 2) + csrc
|
| 261 |
+
cand = p_in + e # extend: only from inside
|
| 262 |
+
if cand > besti:
|
| 263 |
+
besti = cand
|
| 264 |
+
choicei = np.uint8(ARC_EXTEND * 2) + np.uint8(1)
|
| 265 |
+
cur_in[j] = besti
|
| 266 |
+
bp_in[t, j - a] = choicei
|
| 267 |
+
|
| 268 |
+
# text-skip chain into the boundary bucket (same frame, exclusive scan over j)
|
| 269 |
+
run = BIG
|
| 270 |
+
run_bucket = np.uint8(0)
|
| 271 |
+
for j in range(a, b):
|
| 272 |
+
cand = run + np.float32(j) * ts
|
| 273 |
+
if cand > cur_bd[j]:
|
| 274 |
+
cur_bd[j] = cand
|
| 275 |
+
bp_bd[t, j - a] = np.uint8(ARC_TEXT_SKIP * 2) + run_bucket
|
| 276 |
+
v_in = cur_in[j]
|
| 277 |
+
v_bd = cur_bd[j]
|
| 278 |
+
if v_in >= v_bd:
|
| 279 |
+
v = v_in
|
| 280 |
+
vb = np.uint8(1)
|
| 281 |
+
else:
|
| 282 |
+
v = v_bd
|
| 283 |
+
vb = np.uint8(0)
|
| 284 |
+
v = v - np.float32(j) * ts
|
| 285 |
+
if v > run:
|
| 286 |
+
run = v
|
| 287 |
+
run_bucket = vb
|
| 288 |
+
|
| 289 |
+
prev_in, cur_in = cur_in, prev_in
|
| 290 |
+
prev_bd, cur_bd = cur_bd, prev_bd
|
| 291 |
+
prev_dlo, cur_dlo = cur_dlo, prev_dlo
|
| 292 |
+
prev_dhi, cur_dhi = cur_dhi, prev_dhi
|
| 293 |
+
for j in range(prev_b, J + 1):
|
| 294 |
+
prev_in[j] = BIG
|
| 295 |
+
prev_bd[j] = BIG
|
| 296 |
+
for j in range(0, min(prev_dlo, J + 1)):
|
| 297 |
+
prev_in[j] = BIG
|
| 298 |
+
prev_bd[j] = BIG
|
| 299 |
+
for j in range(J + 1):
|
| 300 |
+
final_in[j] = prev_in[j]
|
| 301 |
+
final_bd[j] = prev_bd[j]
|
| 302 |
+
|
| 303 |
+
# terminal state is (T, J): every text token accounted for, spoken or skipped
|
| 304 |
+
s_in = prev_in[J]
|
| 305 |
+
s_bd = prev_bd[J]
|
| 306 |
+
if s_in > s_bd:
|
| 307 |
+
return float(s_in), 1, int(start_j)
|
| 308 |
+
return float(s_bd), 0, int(start_j)
|
| 309 |
+
else:
|
| 310 |
+
_dp_core = None
|
| 311 |
+
|
| 312 |
+
|
| 313 |
+
def _dp_core_py(lp, tok_ids, is_space, blank_col, speech_col, lo, hi, ts, asp, J, T, W,
|
| 314 |
+
init_in, init_bd, bp_in, bp_bd, final_in, final_bd):
|
| 315 |
+
"""Same DP as `_dp_core` in numpy, used when numba is not installed."""
|
| 316 |
+
BIG = np.float32(BIG_NEG)
|
| 317 |
+
prev_in = init_in.copy()
|
| 318 |
+
prev_bd = init_bd.copy()
|
| 319 |
+
ts32 = np.float32(ts)
|
| 320 |
+
prev_a, prev_b = 0, 0
|
| 321 |
+
start_j = 0
|
| 322 |
+
|
| 323 |
+
for t in range(T):
|
| 324 |
+
a, b = int(lo[t]), int(hi[t])
|
| 325 |
+
if prev_a < a:
|
| 326 |
+
prev_in[prev_a:a] = BIG
|
| 327 |
+
prev_bd[prev_a:a] = BIG
|
| 328 |
+
if b < prev_b:
|
| 329 |
+
prev_in[b:prev_b] = BIG
|
| 330 |
+
prev_bd[b:prev_b] = BIG
|
| 331 |
+
prev_a, prev_b = a, b
|
| 332 |
+
sl = slice(a, b)
|
| 333 |
+
js = np.arange(a, b, dtype=np.int64)
|
| 334 |
+
n = b - a
|
| 335 |
+
p_in = prev_in[js]
|
| 336 |
+
p_bd = prev_bd[js]
|
| 337 |
+
|
| 338 |
+
# boundary bucket: blank / audio skip
|
| 339 |
+
p_any = np.maximum(p_in, p_bd)
|
| 340 |
+
p_src = np.where(p_in >= p_bd, 1, 0).astype(np.uint8)
|
| 341 |
+
c_blank = p_any + blank_col[t]
|
| 342 |
+
c_audio = p_any + speech_col[t] + asp
|
| 343 |
+
bd = np.maximum(c_blank, c_audio)
|
| 344 |
+
bd_arc = np.where(c_audio > c_blank, ARC_AUDIO_SKIP, ARC_BLANK).astype(np.uint8)
|
| 345 |
+
bd_choice = (bd_arc * 2 + p_src).astype(np.uint8)
|
| 346 |
+
|
| 347 |
+
# inside bucket: emit / extend
|
| 348 |
+
ei = np.full(n, BIG, dtype=np.float32)
|
| 349 |
+
ei_choice = np.full(n, 255, dtype=np.uint8)
|
| 350 |
+
has_prev = js > 0
|
| 351 |
+
if has_prev.any():
|
| 352 |
+
jm = np.where(has_prev, js - 1, 0)
|
| 353 |
+
sp_mask = is_space[jm]
|
| 354 |
+
e = np.where(sp_mask, blank_col[t],
|
| 355 |
+
np.maximum(lp[t, np.where(sp_mask, 0, tok_ids[jm])], -20.0)
|
| 356 |
+
).astype(np.float32)
|
| 357 |
+
q_in = prev_in[jm]
|
| 358 |
+
q_bd = prev_bd[jm]
|
| 359 |
+
q_any = np.maximum(q_in, q_bd)
|
| 360 |
+
q_src = np.where(q_in >= q_bd, 1, 0).astype(np.uint8)
|
| 361 |
+
c_emit = q_any + e
|
| 362 |
+
c_ext = p_in + e
|
| 363 |
+
best = np.maximum(c_emit, c_ext)
|
| 364 |
+
best_choice = np.where(c_ext > c_emit,
|
| 365 |
+
ARC_EXTEND * 2 + 1,
|
| 366 |
+
ARC_EMIT * 2 + q_src).astype(np.uint8)
|
| 367 |
+
ei = np.where(has_prev, best, BIG)
|
| 368 |
+
ei_choice = np.where(has_prev, best_choice, 255).astype(np.uint8)
|
| 369 |
+
|
| 370 |
+
# text-skip exclusive scan, in the same scalar form as the compiled kernel
|
| 371 |
+
bd2 = bd.copy()
|
| 372 |
+
choice2 = bd_choice.copy()
|
| 373 |
+
run = np.float32(BIG)
|
| 374 |
+
run_bucket = np.uint8(0)
|
| 375 |
+
for k in range(n):
|
| 376 |
+
j = k + a
|
| 377 |
+
cand = run + np.float32(j) * ts32
|
| 378 |
+
if cand > bd2[k]:
|
| 379 |
+
bd2[k] = cand
|
| 380 |
+
choice2[k] = np.uint8(ARC_TEXT_SKIP * 2) + run_bucket
|
| 381 |
+
v_in = bd2[k]
|
| 382 |
+
v_i = ei[k]
|
| 383 |
+
if v_i >= v_in:
|
| 384 |
+
v = v_i
|
| 385 |
+
vb = np.uint8(1)
|
| 386 |
+
else:
|
| 387 |
+
v = v_in
|
| 388 |
+
vb = np.uint8(0)
|
| 389 |
+
v_shift = v - np.float32(j) * ts32
|
| 390 |
+
if v_shift > run:
|
| 391 |
+
run = v_shift
|
| 392 |
+
run_bucket = vb
|
| 393 |
+
|
| 394 |
+
cur_bd = np.full(J + 1, BIG, dtype=np.float32)
|
| 395 |
+
cur_in = np.full(J + 1, BIG, dtype=np.float32)
|
| 396 |
+
cur_bd[sl] = bd2
|
| 397 |
+
cur_in[sl] = ei
|
| 398 |
+
bp_bd[t, :] = 255
|
| 399 |
+
bp_in[t, :] = 255
|
| 400 |
+
bp_bd[t, 0:n] = choice2
|
| 401 |
+
bp_in[t, 0:n] = ei_choice
|
| 402 |
+
prev_in, prev_bd = cur_in, cur_bd
|
| 403 |
+
if prev_b < J + 1:
|
| 404 |
+
prev_in[prev_b:J + 1] = BIG
|
| 405 |
+
prev_bd[prev_b:J + 1] = BIG
|
| 406 |
+
final_in[:] = prev_in
|
| 407 |
+
final_bd[:] = prev_bd
|
| 408 |
+
|
| 409 |
+
if prev_in[J] > prev_bd[J]:
|
| 410 |
+
return float(prev_in[J]), 1, start_j
|
| 411 |
+
return float(prev_bd[J]), 0, start_j
|
| 412 |
+
|
| 413 |
+
|
| 414 |
+
_KERNEL = _dp_core if _dp_core is not None else _dp_core_py
|
| 415 |
+
|
| 416 |
+
|
| 417 |
+
def _band_limits(T: int, J: int, cfg: AlignConfig, band_center) -> tuple[np.ndarray, np.ndarray, int]:
|
| 418 |
+
"""Per-frame half-open band [lo, hi) over token index j, non-decreasing in t."""
|
| 419 |
+
if band_center is not None and cfg.band > 0:
|
| 420 |
+
bc = np.asarray(band_center, dtype=np.int64)
|
| 421 |
+
if bc.shape[0] < T:
|
| 422 |
+
bc = np.concatenate([bc, np.full(T - bc.shape[0], bc[-1] if bc.size else 0)])
|
| 423 |
+
bc = bc[:T]
|
| 424 |
+
bc = np.maximum.accumulate(bc)
|
| 425 |
+
lo = np.clip(bc - cfg.band, 0, J).astype(np.int32)
|
| 426 |
+
hi = np.clip(bc + cfg.band + 1, 1, J + 1).astype(np.int32)
|
| 427 |
+
# With a free text prefix the path may start up to `cap` tokens ahead of the diagonal,
|
| 428 |
+
# so the upper edge is widened by that amount, decaying to zero at the last frame.
|
| 429 |
+
if cfg.free_text_prefix:
|
| 430 |
+
cap = max(0, min(cfg.max_prefix_tokens, J))
|
| 431 |
+
frac_left = 1.0 - (np.arange(T, dtype=np.float64) / max(1, T - 1))
|
| 432 |
+
hi = (hi + np.round(cap * frac_left)).astype(np.int32)
|
| 433 |
+
hi = np.minimum(hi, J + 1).astype(np.int32)
|
| 434 |
+
else:
|
| 435 |
+
lo = np.zeros(T, dtype=np.int32)
|
| 436 |
+
hi = np.full(T, J + 1, dtype=np.int32)
|
| 437 |
+
lo = np.maximum.accumulate(lo).astype(np.int32)
|
| 438 |
+
hi = np.maximum.accumulate(hi).astype(np.int32)
|
| 439 |
+
lo[0] = 0
|
| 440 |
+
hi[-1] = J + 1
|
| 441 |
+
lo = np.minimum(lo, J).astype(np.int32)
|
| 442 |
+
hi = np.maximum(hi, lo + 1).astype(np.int32)
|
| 443 |
+
hi = np.minimum(hi, J + 1).astype(np.int32)
|
| 444 |
+
hi_next = np.concatenate([hi[1:], np.array([J + 1], dtype=np.int32)])
|
| 445 |
+
W = int(np.max(hi_next - lo)) + 1
|
| 446 |
+
return lo, hi, W
|
| 447 |
+
|
| 448 |
+
|
| 449 |
+
def _record(starts, ends, k, t):
|
| 450 |
+
"""Record that token `k` was spoken at frame `t`."""
|
| 451 |
+
if k < 0:
|
| 452 |
+
return
|
| 453 |
+
if starts[k] < 0 or t < starts[k]:
|
| 454 |
+
starts[k] = t
|
| 455 |
+
if t + 1 > ends[k]:
|
| 456 |
+
ends[k] = t + 1
|
| 457 |
+
|
| 458 |
+
|
| 459 |
+
def _backtrack(bp_in, bp_bd, lo, T, J, bucket, tokens, _start_hint=0):
|
| 460 |
+
"""Walk the backpointers from (T, J) and build spans.
|
| 461 |
+
|
| 462 |
+
Returns (spans, audio_skips, text_skips, unmatched, prefix_skipped, matched_frames).
|
| 463 |
+
"""
|
| 464 |
+
starts = np.full(J, -1, dtype=np.int64)
|
| 465 |
+
ends = np.zeros(J, dtype=np.int64)
|
| 466 |
+
skipped = np.zeros(J, dtype=bool)
|
| 467 |
+
audio_skips = 0
|
| 468 |
+
text_skips = 0
|
| 469 |
+
matched_frames = 0
|
| 470 |
+
t, j, b = T, J, bucket
|
| 471 |
+
prefix_skipped = 0
|
| 472 |
+
guard = (T + J) * 4 + 64
|
| 473 |
+
while (t > 0 or j > 0) and guard > 0:
|
| 474 |
+
guard -= 1
|
| 475 |
+
if t == 0:
|
| 476 |
+
# audio exhausted: the remaining leading text is unspoken front matter
|
| 477 |
+
j -= 1
|
| 478 |
+
if j >= 0:
|
| 479 |
+
prefix_skipped += 1
|
| 480 |
+
skipped[j] = True
|
| 481 |
+
b = BOUNDARY
|
| 482 |
+
continue
|
| 483 |
+
off = j - int(lo[t - 1])
|
| 484 |
+
if off < 0 or off >= bp_in.shape[1]:
|
| 485 |
+
raise IndexError(
|
| 486 |
+
f"backtrack out of band at t={t} j={j} lo={int(lo[t-1])} W={bp_in.shape[1]}")
|
| 487 |
+
raw = int(bp_in[t - 1, off]) if b == INSIDE else int(bp_bd[t - 1, off])
|
| 488 |
+
if raw == 255:
|
| 489 |
+
break
|
| 490 |
+
arc, src = raw // 2, raw % 2
|
| 491 |
+
if arc == ARC_BLANK:
|
| 492 |
+
t -= 1
|
| 493 |
+
b = src
|
| 494 |
+
elif arc == ARC_AUDIO_SKIP:
|
| 495 |
+
t -= 1
|
| 496 |
+
audio_skips += 1
|
| 497 |
+
b = src
|
| 498 |
+
elif arc == ARC_EMIT:
|
| 499 |
+
t -= 1
|
| 500 |
+
j -= 1
|
| 501 |
+
_record(starts, ends, j, t)
|
| 502 |
+
matched_frames += 1
|
| 503 |
+
b = src
|
| 504 |
+
elif arc == ARC_EXTEND:
|
| 505 |
+
t -= 1
|
| 506 |
+
_record(starts, ends, j - 1, t)
|
| 507 |
+
matched_frames += 1
|
| 508 |
+
b = src
|
| 509 |
+
else: # ARC_TEXT_SKIP
|
| 510 |
+
j -= 1
|
| 511 |
+
text_skips += 1
|
| 512 |
+
if j >= 0:
|
| 513 |
+
skipped[j] = True
|
| 514 |
+
b = src
|
| 515 |
+
|
| 516 |
+
spans: list[TokenSpan] = []
|
| 517 |
+
unmatched = 0
|
| 518 |
+
last_end = 0
|
| 519 |
+
for j in range(J):
|
| 520 |
+
if starts[j] >= 0:
|
| 521 |
+
last_end = int(ends[j])
|
| 522 |
+
spans.append(TokenSpan(j, tokens[j].text, int(starts[j]), int(ends[j]),
|
| 523 |
+
skipped_text=bool(skipped[j])))
|
| 524 |
+
else:
|
| 525 |
+
unmatched += 1
|
| 526 |
+
spans.append(TokenSpan(j, tokens[j].text, last_end, last_end,
|
| 527 |
+
skipped_text=bool(skipped[j]), unmatched=True))
|
| 528 |
+
return spans, audio_skips, text_skips, unmatched, prefix_skipped, matched_frames
|
| 529 |
+
|
| 530 |
+
|
| 531 |
+
def forced_align_dp(
|
| 532 |
+
logp,
|
| 533 |
+
tokens: Sequence[Token],
|
| 534 |
+
cfg: AlignConfig = AlignConfig(),
|
| 535 |
+
band_center=None,
|
| 536 |
+
init_state=None,
|
| 537 |
+
):
|
| 538 |
+
"""Run the DP and return (result, final_state). `final_state` is the last DP row."""
|
| 539 |
+
lp = np.asarray(logp.detach().cpu().numpy() if hasattr(logp, "detach") else logp,
|
| 540 |
+
dtype=np.float32)
|
| 541 |
+
if lp.ndim != 2:
|
| 542 |
+
raise ValueError(f"logp must be (T, V), got shape {lp.shape}")
|
| 543 |
+
T, V = lp.shape
|
| 544 |
+
J = len(tokens)
|
| 545 |
+
if T == 0 or J == 0:
|
| 546 |
+
empty = AlignResult([], 0.0, T, 0, 0, J)
|
| 547 |
+
return empty, None
|
| 548 |
+
|
| 549 |
+
blank_col = lp[:, cfg.blank].astype(np.float32)
|
| 550 |
+
tok_ids = np.fromiter((tk.id for tk in tokens), dtype=np.int64, count=J)
|
| 551 |
+
is_space = np.fromiter((tk.is_space for tk in tokens), dtype=bool, count=J)
|
| 552 |
+
lo, hi, W = _band_limits(T, J, cfg, band_center)
|
| 553 |
+
|
| 554 |
+
if init_state is None:
|
| 555 |
+
init_in = np.full(J + 1, BIG_NEG, dtype=np.float32)
|
| 556 |
+
init_bd = np.full(J + 1, BIG_NEG, dtype=np.float32)
|
| 557 |
+
if cfg.free_text_prefix:
|
| 558 |
+
cap = max(0, min(cfg.max_prefix_tokens, J))
|
| 559 |
+
init_bd[:cap + 1] = (np.arange(cap + 1, dtype=np.float32)
|
| 560 |
+
* np.float32(cfg.log_prefix_skip))
|
| 561 |
+
else:
|
| 562 |
+
init_bd[0] = 0.0
|
| 563 |
+
else:
|
| 564 |
+
init_in, init_bd = init_state
|
| 565 |
+
|
| 566 |
+
bp_in = np.full((T, W), 255, dtype=np.uint8)
|
| 567 |
+
bp_bd = np.full((T, W), 255, dtype=np.uint8)
|
| 568 |
+
|
| 569 |
+
# best non-blank log-prob per frame, which prices the audio-skip arc
|
| 570 |
+
nb = np.delete(lp, cfg.blank, axis=1) if lp.shape[1] > 1 else lp
|
| 571 |
+
speech_col = nb.max(axis=1).astype(np.float32)
|
| 572 |
+
np.maximum(speech_col, np.float32(cfg.emit_floor), out=speech_col)
|
| 573 |
+
|
| 574 |
+
final_in = np.full(J + 1, BIG_NEG, dtype=np.float32)
|
| 575 |
+
final_bd = np.full(J + 1, BIG_NEG, dtype=np.float32)
|
| 576 |
+
score, bucket, start_j = _KERNEL(lp, tok_ids, is_space, blank_col, speech_col, lo, hi,
|
| 577 |
+
np.float32(cfg.log_text_skip),
|
| 578 |
+
np.float32(cfg.log_audio_skip),
|
| 579 |
+
J, T, W, init_in, init_bd, bp_in, bp_bd, final_in, final_bd)
|
| 580 |
+
|
| 581 |
+
final_state = (final_in, final_bd)
|
| 582 |
+
if score > BIG_NEG / 2:
|
| 583 |
+
spans, audio_skips, text_skips, unmatched, prefix_skipped, matched_frames = _backtrack(
|
| 584 |
+
bp_in, bp_bd, lo, T, J, bucket, tokens, start_j)
|
| 585 |
+
if cfg.pad_frames:
|
| 586 |
+
for sp in spans:
|
| 587 |
+
if not sp.unmatched:
|
| 588 |
+
sp.start_frame = max(0, sp.start_frame - cfg.pad_frames)
|
| 589 |
+
sp.end_frame = min(T, sp.end_frame + cfg.pad_frames)
|
| 590 |
+
result = AlignResult(spans=spans, total_score=score, frames=T,
|
| 591 |
+
audio_skips=audio_skips, text_skips=text_skips,
|
| 592 |
+
unmatched=unmatched, prefix_skipped=int(prefix_skipped),
|
| 593 |
+
matched_frames=int(matched_frames))
|
| 594 |
+
else:
|
| 595 |
+
result = AlignResult(
|
| 596 |
+
spans=[TokenSpan(j, tokens[j].text, 0, 0, unmatched=True) for j in range(J)],
|
| 597 |
+
total_score=NEG_INF, frames=T, audio_skips=0, text_skips=0, unmatched=J)
|
| 598 |
+
return result, final_state
|
| 599 |
+
|
| 600 |
+
|
| 601 |
+
def forced_align(logp, tokens: Sequence[Token], cfg: AlignConfig = AlignConfig(),
|
| 602 |
+
band_center=None) -> AlignResult:
|
| 603 |
+
"""One-shot alignment of `logp` against `tokens`."""
|
| 604 |
+
result, _ = forced_align_dp(logp, tokens, cfg, band_center)
|
| 605 |
+
return result
|
| 606 |
+
|
| 607 |
+
|
| 608 |
+
def linear_band_center(T: int, J: int) -> np.ndarray:
|
| 609 |
+
"""The straight diagonal from (0, 0) to (T, J), used as the band center."""
|
| 610 |
+
if T <= 1:
|
| 611 |
+
return np.zeros(max(T, 1), dtype=np.int64)
|
| 612 |
+
return np.linspace(0, J, T).astype(np.int64)
|
| 613 |
+
|
| 614 |
+
|
| 615 |
+
# --------------------------------------------------------------------------------------
|
| 616 |
+
# Text -> tokens
|
| 617 |
+
# --------------------------------------------------------------------------------------
|
| 618 |
+
|
| 619 |
+
_ONES = ("zero one two three four five six seven eight nine ten eleven twelve thirteen "
|
| 620 |
+
"fourteen fifteen sixteen seventeen eighteen nineteen").split()
|
| 621 |
+
_TENS = ["", "", "twenty", "thirty", "forty", "fifty", "sixty", "seventy", "eighty", "ninety"]
|
| 622 |
+
|
| 623 |
+
def number_to_words(n: int) -> str:
|
| 624 |
+
"""Cardinal English for a non-negative integer below one million."""
|
| 625 |
+
if n < 0:
|
| 626 |
+
return "negative " + number_to_words(-n)
|
| 627 |
+
if n < 20:
|
| 628 |
+
return _ONES[n]
|
| 629 |
+
if n < 100:
|
| 630 |
+
t, o = divmod(n, 10)
|
| 631 |
+
return _TENS[t] + ("" if o == 0 else " " + _ONES[o])
|
| 632 |
+
if n < 1000:
|
| 633 |
+
h, r = divmod(n, 100)
|
| 634 |
+
s = _ONES[h] + " hundred"
|
| 635 |
+
return s + ("" if r == 0 else " " + number_to_words(r))
|
| 636 |
+
if n < 1_000_000:
|
| 637 |
+
th, r = divmod(n, 1000)
|
| 638 |
+
s = number_to_words(th) + " thousand"
|
| 639 |
+
return s + ("" if r == 0 else " " + number_to_words(r))
|
| 640 |
+
return str(n)
|
| 641 |
+
|
| 642 |
+
|
| 643 |
+
def number_readings(digits: str, style: str = "auto") -> list[str]:
|
| 644 |
+
"""Plausible English spoken forms of a digit run, likeliest first.
|
| 645 |
+
|
| 646 |
+
"1812" -> ["eighteen twelve", "one thousand eight hundred twelve", "one eight one two"].
|
| 647 |
+
"""
|
| 648 |
+
if not digits or not digits.isdigit():
|
| 649 |
+
return [digits]
|
| 650 |
+
n = int(digits)
|
| 651 |
+
cardinal = number_to_words(n)
|
| 652 |
+
out: list[str] = []
|
| 653 |
+
if len(digits) == 4:
|
| 654 |
+
hi, lo = int(digits[:2]), int(digits[2:])
|
| 655 |
+
if 10 <= hi <= 99:
|
| 656 |
+
if lo == 0:
|
| 657 |
+
out.append(number_to_words(hi) + " hundred")
|
| 658 |
+
elif lo < 10:
|
| 659 |
+
out.append(number_to_words(hi) + " oh " + _ONES[lo])
|
| 660 |
+
out.append(number_to_words(hi) + " " + number_to_words(lo))
|
| 661 |
+
else:
|
| 662 |
+
out.append(number_to_words(hi) + " " + number_to_words(lo))
|
| 663 |
+
if style == "cardinal":
|
| 664 |
+
out = [cardinal] + [o for o in out if o != cardinal]
|
| 665 |
+
elif style == "year":
|
| 666 |
+
out = out + [cardinal] if out else [cardinal]
|
| 667 |
+
else: # auto: split-year reading for 4 digits that look like a year, cardinal otherwise
|
| 668 |
+
if not (3 <= len(digits) <= 4 and 100 <= n <= 2100 and out):
|
| 669 |
+
out = [cardinal] + [o for o in out if o != cardinal]
|
| 670 |
+
if cardinal not in out:
|
| 671 |
+
out.append(cardinal)
|
| 672 |
+
out.append(" ".join(_ONES[int(d)] for d in digits))
|
| 673 |
+
seen, res = set(), []
|
| 674 |
+
for o in out:
|
| 675 |
+
if o and o not in seen:
|
| 676 |
+
seen.add(o)
|
| 677 |
+
res.append(o)
|
| 678 |
+
return res
|
| 679 |
+
|
| 680 |
+
|
| 681 |
+
# A word is a run of letters/digits, with apostrophe continuations ("don't" is one word,
|
| 682 |
+
# "well-known" and "1,000" are two). Word indices in the output refer to this segmentation.
|
| 683 |
+
try:
|
| 684 |
+
import regex as _regex_mod
|
| 685 |
+
|
| 686 |
+
_WORD_RE = _regex_mod.compile(r"[\p{L}\p{Nd}]+(?:['’][\p{L}]+)*")
|
| 687 |
+
except ImportError: # pragma: no cover
|
| 688 |
+
import unicodedata as _ud
|
| 689 |
+
|
| 690 |
+
class _WordReFallback:
|
| 691 |
+
"""Same segmentation as the regex above, without the `regex` package."""
|
| 692 |
+
|
| 693 |
+
@staticmethod
|
| 694 |
+
def _is_word_char(ch: str) -> bool:
|
| 695 |
+
cat = _ud.category(ch)
|
| 696 |
+
return cat.startswith("L") or cat == "Nd"
|
| 697 |
+
|
| 698 |
+
def finditer(self, text: str):
|
| 699 |
+
out, i, n = [], 0, len(text)
|
| 700 |
+
while i < n:
|
| 701 |
+
while i < n and not self._is_word_char(text[i]):
|
| 702 |
+
i += 1
|
| 703 |
+
if i >= n:
|
| 704 |
+
break
|
| 705 |
+
start = i
|
| 706 |
+
while i < n and self._is_word_char(text[i]):
|
| 707 |
+
i += 1
|
| 708 |
+
while (i + 1 < n and text[i] in "'’"
|
| 709 |
+
and self._is_word_char(text[i + 1])):
|
| 710 |
+
j = i + 1
|
| 711 |
+
while j < n and self._is_word_char(text[j]):
|
| 712 |
+
j += 1
|
| 713 |
+
i = j
|
| 714 |
+
out.append((start, i))
|
| 715 |
+
return [_Match(a, b, text) for a, b in out]
|
| 716 |
+
|
| 717 |
+
class _Match:
|
| 718 |
+
def __init__(self, a: int, b: int, text: str):
|
| 719 |
+
self._a, self._b, self._t = a, b, text
|
| 720 |
+
|
| 721 |
+
def start(self, *_):
|
| 722 |
+
return self._a
|
| 723 |
+
|
| 724 |
+
def end(self, *_):
|
| 725 |
+
return self._b
|
| 726 |
+
|
| 727 |
+
def group(self, *_):
|
| 728 |
+
return self._t[self._a:self._b]
|
| 729 |
+
|
| 730 |
+
_WORD_RE = _WordReFallback()
|
| 731 |
+
|
| 732 |
+
|
| 733 |
+
def _word_spans(text: str) -> list[tuple[int, int]]:
|
| 734 |
+
"""(start, end) character offsets of every word."""
|
| 735 |
+
out: list[tuple[int, int]] = []
|
| 736 |
+
for m in _WORD_RE.finditer(text):
|
| 737 |
+
out.append((m.start(), m.end()))
|
| 738 |
+
return out
|
| 739 |
+
|
| 740 |
+
|
| 741 |
+
def _punct_strip(w: str) -> tuple[str, str, str]:
|
| 742 |
+
"""Split a word into (leading punctuation, alphanumeric core, trailing punctuation)."""
|
| 743 |
+
i, j = 0, len(w)
|
| 744 |
+
while i < j and not w[i].isalnum():
|
| 745 |
+
i += 1
|
| 746 |
+
while j > i and not w[j - 1].isalnum():
|
| 747 |
+
j -= 1
|
| 748 |
+
return w[:i], w[i:j], w[j:]
|
| 749 |
+
|
| 750 |
+
|
| 751 |
+
def expand_text(text: str, *, number_style: str = "auto", lang: str = "en") -> Expansion:
|
| 752 |
+
"""Rewrite text into alignable characters, recording the map back to word indices.
|
| 753 |
+
|
| 754 |
+
One space per inter-word gap (word -1); digit runs replaced by their likeliest reading
|
| 755 |
+
(English readings for `lang="en"`, num2words otherwise), with alternatives in `groups`.
|
| 756 |
+
The output keeps the original script; `romanize.romanize_expansion` maps it to the model's
|
| 757 |
+
alphabet.
|
| 758 |
+
"""
|
| 759 |
+
out: list[str] = []
|
| 760 |
+
char_to_word: list[int] = []
|
| 761 |
+
words: list[str] = []
|
| 762 |
+
groups: list[tuple[int, int, tuple[str, ...]]] = []
|
| 763 |
+
|
| 764 |
+
def put(chars: str, wi: int) -> None:
|
| 765 |
+
for ch in chars:
|
| 766 |
+
out.append(ch)
|
| 767 |
+
char_to_word.append(wi)
|
| 768 |
+
|
| 769 |
+
for wi, (ws, we) in enumerate(_word_spans(text)):
|
| 770 |
+
word = text[ws:we]
|
| 771 |
+
words.append(word)
|
| 772 |
+
if out and out[-1] != " ":
|
| 773 |
+
put(" ", -1)
|
| 774 |
+
|
| 775 |
+
lead, core, _trail = _punct_strip(word)
|
| 776 |
+
if not core:
|
| 777 |
+
put(word, wi)
|
| 778 |
+
continue
|
| 779 |
+
|
| 780 |
+
if core.isdigit():
|
| 781 |
+
if lang == "en":
|
| 782 |
+
readings = number_readings(core, style=number_style)
|
| 783 |
+
else:
|
| 784 |
+
from .romanize import number_readings_lang
|
| 785 |
+
readings = number_readings_lang(core, lang)
|
| 786 |
+
put(lead, wi)
|
| 787 |
+
span_start = len(out)
|
| 788 |
+
put(readings[0], wi)
|
| 789 |
+
if len(readings) > 1:
|
| 790 |
+
groups.append((span_start, len(out), tuple(readings)))
|
| 791 |
+
continue
|
| 792 |
+
|
| 793 |
+
put(lead + core, wi)
|
| 794 |
+
|
| 795 |
+
return Expansion(text="".join(out), char_to_word=char_to_word, words=words, groups=groups)
|
| 796 |
+
|
| 797 |
+
|
| 798 |
+
def expansion_to_tokens(exp: Expansion, vocab) -> list[Token]:
|
| 799 |
+
"""Expanded text -> one [Token] per character, via `vocab.id_for` (case-insensitive)."""
|
| 800 |
+
space_id = vocab.id_for(" ")
|
| 801 |
+
toks: list[Token] = []
|
| 802 |
+
for ch in exp.text:
|
| 803 |
+
if ch == " ":
|
| 804 |
+
toks.append(Token(" ", space_id, is_space=True))
|
| 805 |
+
else:
|
| 806 |
+
toks.append(Token(ch, vocab.id_for(ch)))
|
| 807 |
+
return toks
|
| 808 |
+
|
| 809 |
+
|
| 810 |
+
def resolve_ambiguous(logp, exp: Expansion, vocab, cfg: AlignConfig = AlignConfig(),
|
| 811 |
+
*, window_sec: float = 4.0, frame_shift: float = 0.02,
|
| 812 |
+
max_groups: int = 256) -> Expansion:
|
| 813 |
+
"""For each ambiguous written form, keep the reading that aligns best to the audio.
|
| 814 |
+
|
| 815 |
+
Each candidate reading is aligned against a short window of audio around the word's
|
| 816 |
+
expected position, and the best-scoring one replaces the default.
|
| 817 |
+
"""
|
| 818 |
+
if not exp.groups:
|
| 819 |
+
return exp
|
| 820 |
+
lp = np.asarray(logp.detach().cpu().numpy() if hasattr(logp, "detach") else logp,
|
| 821 |
+
dtype=np.float32)
|
| 822 |
+
T = lp.shape[0]
|
| 823 |
+
win = max(8, int(window_sec / frame_shift))
|
| 824 |
+
|
| 825 |
+
text = list(exp.text)
|
| 826 |
+
c2w = list(exp.char_to_word)
|
| 827 |
+
offset = 0
|
| 828 |
+
for (span_start, span_end, readings) in exp.groups[:max_groups]:
|
| 829 |
+
if len(readings) < 2:
|
| 830 |
+
continue
|
| 831 |
+
gs, ge = span_start + offset, span_end + offset
|
| 832 |
+
if gs < 0 or ge > len(text):
|
| 833 |
+
continue
|
| 834 |
+
f_mid = int(np.clip(gs / max(1, len(text)) * T, 0, max(0, T - 1)))
|
| 835 |
+
f_lo = max(0, f_mid - win // 2)
|
| 836 |
+
f_hi = min(T, f_lo + win)
|
| 837 |
+
if f_hi - f_lo < 4:
|
| 838 |
+
continue
|
| 839 |
+
window = lp[f_lo:f_hi]
|
| 840 |
+
best_chars, best_score = None, None
|
| 841 |
+
for reading in readings:
|
| 842 |
+
cand = list(reading)
|
| 843 |
+
local = "".join(text[:gs] + cand + text[ge:])
|
| 844 |
+
sub = Expansion(text=local, char_to_word=[], words=[], groups=[])
|
| 845 |
+
r = forced_align(window, expansion_to_tokens(sub, vocab), cfg)
|
| 846 |
+
if best_score is None or r.total_score > best_score:
|
| 847 |
+
best_score, best_chars = r.total_score, cand
|
| 848 |
+
if best_chars is not None:
|
| 849 |
+
delta = len(best_chars) - (ge - gs)
|
| 850 |
+
text[gs:ge] = best_chars
|
| 851 |
+
wi = c2w[gs] if gs < len(c2w) else (c2w[-1] if c2w else -1)
|
| 852 |
+
c2w[gs:ge] = [wi] * len(best_chars)
|
| 853 |
+
offset += delta
|
| 854 |
+
return Expansion(text="".join(text), char_to_word=c2w, words=exp.words, groups=[])
|
| 855 |
+
|
| 856 |
+
|
| 857 |
+
def spans_to_words(
|
| 858 |
+
text: str,
|
| 859 |
+
spans: Sequence[TokenSpan],
|
| 860 |
+
frame_shift: float,
|
| 861 |
+
*,
|
| 862 |
+
expansion: Expansion | None = None,
|
| 863 |
+
offset_sec: float = 0.0,
|
| 864 |
+
pad_sec: float = 0.0,
|
| 865 |
+
emissions=None,
|
| 866 |
+
snap_ends: bool = True,
|
| 867 |
+
start_offset_sec: float | None = None,
|
| 868 |
+
start_cluster_frames: int = 0,
|
| 869 |
+
) -> list[tuple[int, float, float, bool]]:
|
| 870 |
+
"""Token spans -> (word_index, start_sec, end_sec, measured) for every word.
|
| 871 |
+
|
| 872 |
+
`frame_shift` is the model's frame duration in seconds (0.02 for cavaalign.onnx).
|
| 873 |
+
With `emissions`, word ends are extended into the following pause (see [snap_word_ends]).
|
| 874 |
+
Starts are moved earlier by `start_offset_sec` (default: one frame), which corrects the lag
|
| 875 |
+
between a sound's onset and its character's posterior peak.
|
| 876 |
+
With `start_cluster_frames` > 0, a first letter separated from the rest of its word by more
|
| 877 |
+
than that many frames is not used as the word's start.
|
| 878 |
+
A word is `measured` when more than half of its characters were matched to audio; other words
|
| 879 |
+
inherit the previous word's position. Times never go backwards.
|
| 880 |
+
"""
|
| 881 |
+
if expansion is None:
|
| 882 |
+
expansion = expand_text(text)
|
| 883 |
+
shift_sec = frame_shift if start_offset_sec is None else float(start_offset_sec)
|
| 884 |
+
c2w = expansion.char_to_word
|
| 885 |
+
n_words = len(expansion.words)
|
| 886 |
+
if len(spans) != len(c2w):
|
| 887 |
+
raise ValueError(f"spans ({len(spans)}) do not match expansion chars ({len(c2w)})")
|
| 888 |
+
|
| 889 |
+
snap_starts = snap_ends_frames = None
|
| 890 |
+
if emissions is not None and snap_ends:
|
| 891 |
+
lp = np.asarray(emissions.detach().cpu().numpy()
|
| 892 |
+
if hasattr(emissions, "detach") else emissions, dtype=np.float32)
|
| 893 |
+
snap_starts, snap_ends_frames = snap_word_ends(lp, spans, c2w, n_words)
|
| 894 |
+
|
| 895 |
+
cluster_start: dict[int, int] = {}
|
| 896 |
+
if start_cluster_frames > 0:
|
| 897 |
+
by_word: dict[int, list] = {}
|
| 898 |
+
for ci, sp in enumerate(spans):
|
| 899 |
+
wi = c2w[ci]
|
| 900 |
+
if wi >= 0 and not sp.unmatched:
|
| 901 |
+
by_word.setdefault(wi, []).append(sp)
|
| 902 |
+
for wi, sps in by_word.items():
|
| 903 |
+
for a, b in zip(sps, sps[1:]):
|
| 904 |
+
if b.start_frame - a.end_frame <= start_cluster_frames:
|
| 905 |
+
if a is not sps[0]:
|
| 906 |
+
cluster_start[wi] = a.start_frame
|
| 907 |
+
break
|
| 908 |
+
starts = [math.inf] * n_words
|
| 909 |
+
ends = [-math.inf] * n_words
|
| 910 |
+
n_chars = [0] * n_words
|
| 911 |
+
n_hit = [0] * n_words
|
| 912 |
+
for ci, sp in enumerate(spans):
|
| 913 |
+
wi = c2w[ci]
|
| 914 |
+
if wi < 0:
|
| 915 |
+
continue
|
| 916 |
+
n_chars[wi] += 1
|
| 917 |
+
if sp.unmatched:
|
| 918 |
+
continue
|
| 919 |
+
n_hit[wi] += 1
|
| 920 |
+
if wi in cluster_start and sp.start_frame < cluster_start[wi]:
|
| 921 |
+
continue
|
| 922 |
+
if snap_starts is not None and snap_starts[wi] >= 0:
|
| 923 |
+
s_frame = snap_starts[wi]
|
| 924 |
+
e_frame = snap_ends_frames[wi]
|
| 925 |
+
else:
|
| 926 |
+
s_frame = sp.start_frame
|
| 927 |
+
e_frame = sp.end_frame
|
| 928 |
+
if wi in cluster_start:
|
| 929 |
+
s_frame = max(s_frame, cluster_start[wi])
|
| 930 |
+
e_rel = e_frame * frame_shift
|
| 931 |
+
s_rel = max(0.0, min(s_frame * frame_shift - shift_sec, e_rel))
|
| 932 |
+
s = s_rel + offset_sec
|
| 933 |
+
e = e_rel + offset_sec
|
| 934 |
+
if s < starts[wi]:
|
| 935 |
+
starts[wi] = s
|
| 936 |
+
if e > ends[wi]:
|
| 937 |
+
ends[wi] = e
|
| 938 |
+
|
| 939 |
+
out: list[tuple[int, float, float, bool]] = []
|
| 940 |
+
last_end = 0.0
|
| 941 |
+
for wi in range(n_words):
|
| 942 |
+
measured = n_chars[wi] > 0 and n_hit[wi] * 2 > n_chars[wi]
|
| 943 |
+
s, e = starts[wi], ends[wi]
|
| 944 |
+
if s == math.inf:
|
| 945 |
+
s = last_end
|
| 946 |
+
if e == -math.inf or e < s:
|
| 947 |
+
e = s + frame_shift
|
| 948 |
+
if last_end > 0 and s < last_end - frame_shift:
|
| 949 |
+
s = last_end - frame_shift
|
| 950 |
+
if e < s:
|
| 951 |
+
e = s
|
| 952 |
+
if measured:
|
| 953 |
+
last_end = max(last_end, e)
|
| 954 |
+
out.append((wi, max(0.0, s - pad_sec), e + pad_sec, measured))
|
| 955 |
+
return out
|
| 956 |
+
|
| 957 |
+
|
| 958 |
+
def snap_word_ends(
|
| 959 |
+
lp: np.ndarray,
|
| 960 |
+
spans: Sequence[TokenSpan],
|
| 961 |
+
char_to_word: Sequence[int],
|
| 962 |
+
n_words: int,
|
| 963 |
+
*,
|
| 964 |
+
blank: int = 0,
|
| 965 |
+
max_expand: int = 8,
|
| 966 |
+
) -> tuple[list[int], list[int]]:
|
| 967 |
+
"""Per-word (starts, ends) in frames, with each end moved to the blank peak that follows.
|
| 968 |
+
|
| 969 |
+
A word's last character peaks before the word finishes, so the end is moved forward to the
|
| 970 |
+
frame with the highest blank log-prob within `max_expand` frames, never past the next word's
|
| 971 |
+
start. Starts are left unchanged. Unmeasured words get -1.
|
| 972 |
+
"""
|
| 973 |
+
T = lp.shape[0]
|
| 974 |
+
blank_col = lp[:, blank]
|
| 975 |
+
starts: list[int] = [-1] * n_words
|
| 976 |
+
ends: list[int] = [-1] * n_words
|
| 977 |
+
for ci, sp in enumerate(spans):
|
| 978 |
+
if ci >= len(char_to_word):
|
| 979 |
+
break
|
| 980 |
+
wi = char_to_word[ci]
|
| 981 |
+
if wi < 0 or sp.unmatched:
|
| 982 |
+
continue
|
| 983 |
+
if starts[wi] < 0 or sp.start_frame < starts[wi]:
|
| 984 |
+
starts[wi] = sp.start_frame
|
| 985 |
+
if ends[wi] < 0 or sp.end_frame > ends[wi]:
|
| 986 |
+
ends[wi] = sp.end_frame
|
| 987 |
+
|
| 988 |
+
for wi in range(n_words):
|
| 989 |
+
if starts[wi] < 0:
|
| 990 |
+
continue
|
| 991 |
+
e = ends[wi]
|
| 992 |
+
next_start = starts[wi + 1] if wi + 1 < n_words else -1
|
| 993 |
+
lo = min(max(e, 0), T)
|
| 994 |
+
hi = T if next_start < 0 else min(T, next_start)
|
| 995 |
+
if hi - lo > 0:
|
| 996 |
+
window = blank_col[lo:min(hi, lo + max_expand)]
|
| 997 |
+
if window.size:
|
| 998 |
+
peak = lo + int(np.argmax(window))
|
| 999 |
+
ends[wi] = max(e, peak)
|
| 1000 |
+
return starts, ends
|
| 1001 |
+
|
| 1002 |
+
|
| 1003 |
+
def align_text(
|
| 1004 |
+
logp,
|
| 1005 |
+
text: str,
|
| 1006 |
+
vocab,
|
| 1007 |
+
cfg: AlignConfig = AlignConfig(),
|
| 1008 |
+
*,
|
| 1009 |
+
lang: str = "en",
|
| 1010 |
+
frame_shift: float = 0.02,
|
| 1011 |
+
offset_sec: float = 0.0,
|
| 1012 |
+
pad_sec: float = 0.0,
|
| 1013 |
+
band_center=None,
|
| 1014 |
+
resolve_numbers: bool = False,
|
| 1015 |
+
) -> tuple[list[tuple[int, float, float, bool]], AlignResult, Expansion]:
|
| 1016 |
+
"""Emissions + text -> word timings. Returns (word_timings, diagnostics, expansion).
|
| 1017 |
+
|
| 1018 |
+
`band_center` defaults to the straight diagonal when `cfg.band` > 0.
|
| 1019 |
+
"""
|
| 1020 |
+
from .romanize import prepare_text
|
| 1021 |
+
exp = prepare_text(text, lang)
|
| 1022 |
+
if resolve_numbers and exp.groups:
|
| 1023 |
+
exp = resolve_ambiguous(logp, exp, vocab, cfg, frame_shift=frame_shift)
|
| 1024 |
+
toks = expansion_to_tokens(exp, vocab)
|
| 1025 |
+
if band_center is None and cfg.band > 0:
|
| 1026 |
+
band_center = linear_band_center(len(logp), len(toks))
|
| 1027 |
+
result = forced_align(logp, toks, cfg, band_center)
|
| 1028 |
+
words = spans_to_words(text, result.spans, frame_shift,
|
| 1029 |
+
expansion=exp, offset_sec=offset_sec, pad_sec=pad_sec,
|
| 1030 |
+
emissions=logp)
|
| 1031 |
+
return words, result, exp
|
cavaalign/romanize.py
ADDED
|
@@ -0,0 +1,200 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# SPDX-License-Identifier: AGPL-3.0-or-later
|
| 2 |
+
"""Any Latin or Cyrillic text -> the model's 29-class romanized alphabet.
|
| 3 |
+
|
| 4 |
+
The model expects uroman's romanization conventions. Three engines are available:
|
| 5 |
+
|
| 6 |
+
* ``table`` (default): a small context-aware table plus Unicode decomposition. Deterministic
|
| 7 |
+
and dependency-free; `kotlin/Romanizer.kt` implements the same table. It matches uroman on
|
| 8 |
+
Latin-script languages and Russian.
|
| 9 |
+
* ``uroman``: the reference convention. Requires the `uroman` package.
|
| 10 |
+
* ``icu``: ICU ``Any-Latin; Latin-ASCII``. Requires PyICU. Output can differ between ICU
|
| 11 |
+
versions, so it is provided for comparison only.
|
| 12 |
+
|
| 13 |
+
Romanization runs per word, after `align.expand_text`, so word indices are unchanged. A word
|
| 14 |
+
that romanizes to nothing (e.g. a lone "—") becomes the `*` wildcard (`<unk>`).
|
| 15 |
+
"""
|
| 16 |
+
from __future__ import annotations
|
| 17 |
+
|
| 18 |
+
import unicodedata
|
| 19 |
+
from functools import lru_cache
|
| 20 |
+
|
| 21 |
+
from .align import Expansion
|
| 22 |
+
|
| 23 |
+
# ISO 639-1 -> the ISO 639-3 code uroman takes.
|
| 24 |
+
LANG3 = {"en": "eng", "de": "deu", "fr": "fra", "es": "spa", "it": "ita", "pt": "por",
|
| 25 |
+
"nl": "nld", "pl": "pol", "ru": "rus"}
|
| 26 |
+
|
| 27 |
+
ALLOWED = set("abcdefghijklmnopqrstuvwxyz'")
|
| 28 |
+
|
| 29 |
+
# Latin letters whose romanization is not "strip the accent" (uroman's values).
|
| 30 |
+
LATIN_SPECIAL = {
|
| 31 |
+
"ä": "ae", "å": "aa", "ö": "oe", "ø": "oe", "ü": "ue", "œ": "oe", "æ": "ae", "ß": "ss",
|
| 32 |
+
"ç": "s", "ş": "sh", "ș": "sh", "ț": "ts", "þ": "th", "ð": "th", "ł": "l", "đ": "d",
|
| 33 |
+
"ı": "i", "ŀ": "l", "ij": "ij",
|
| 34 |
+
}
|
| 35 |
+
|
| 36 |
+
# Cyrillic, following uroman for Russian. `е` depends on context: "ye" at word start and after
|
| 37 |
+
# а/и/о/у/ъ/ь, otherwise "e"; at word start before е/ё it is "e"; after е it alternates
|
| 38 |
+
# ("ее" -> "eye"). Word-final "ий" is "y" ("синий" -> "siny").
|
| 39 |
+
RU = {"а": "a", "б": "b", "в": "v", "г": "g", "д": "d", "е": "e", "ё": "yo", "ж": "zh",
|
| 40 |
+
"з": "z", "и": "i", "й": "y", "к": "k", "л": "l", "м": "m", "н": "n", "о": "o", "п": "p",
|
| 41 |
+
"р": "r", "с": "s", "т": "t", "у": "u", "ф": "f", "х": "kh", "ц": "ts", "ч": "ch",
|
| 42 |
+
"ш": "sh", "щ": "shch", "ъ": "", "ы": "y", "ь": "", "э": "e", "ю": "yu", "я": "ya",
|
| 43 |
+
"і": "i", "ї": "yi", "є": "ye", "ґ": "g", "ў": "w"}
|
| 44 |
+
RU_YE_AFTER = set("аиоуъь")
|
| 45 |
+
|
| 46 |
+
|
| 47 |
+
def _ru_e(prev: str, prev_out: str, nxt: str) -> str:
|
| 48 |
+
if not prev:
|
| 49 |
+
return "e" if nxt in ("е", "ё") else "ye"
|
| 50 |
+
if prev == "е":
|
| 51 |
+
return "e" if prev_out == "ye" else "ye"
|
| 52 |
+
return "ye" if prev in RU_YE_AFTER else "e"
|
| 53 |
+
|
| 54 |
+
|
| 55 |
+
APOSTROPHES = {"’": "'", "‘": "'", "ʼ": "'", "`": "'"}
|
| 56 |
+
|
| 57 |
+
|
| 58 |
+
def _fold_latin(ch: str) -> str:
|
| 59 |
+
if ch in LATIN_SPECIAL:
|
| 60 |
+
return LATIN_SPECIAL[ch]
|
| 61 |
+
# strip combining marks (Unicode category Mn)
|
| 62 |
+
base = "".join(c for c in unicodedata.normalize("NFKD", ch)
|
| 63 |
+
if unicodedata.category(c) != "Mn")
|
| 64 |
+
return base
|
| 65 |
+
|
| 66 |
+
|
| 67 |
+
@lru_cache(maxsize=200_000)
|
| 68 |
+
def _table_word(word: str) -> str:
|
| 69 |
+
w = [APOSTROPHES.get(c, c) for c in word.lower()]
|
| 70 |
+
out = []
|
| 71 |
+
prev = ""
|
| 72 |
+
final_iy = len(w) >= 2 and w[-2] == "и" and w[-1] == "й"
|
| 73 |
+
for i, ch in enumerate(w):
|
| 74 |
+
if final_iy and i == len(w) - 2:
|
| 75 |
+
out.append("") # word-final "ий" -> "y": the й supplies it
|
| 76 |
+
elif ch == "е":
|
| 77 |
+
out.append(_ru_e(prev, out[-1] if out else "", w[i + 1] if i + 1 < len(w) else ""))
|
| 78 |
+
elif ch in RU:
|
| 79 |
+
out.append(RU[ch])
|
| 80 |
+
else:
|
| 81 |
+
out.append(_fold_latin(ch))
|
| 82 |
+
prev = ch
|
| 83 |
+
return "".join(c for c in "".join(out) if c in ALLOWED)
|
| 84 |
+
|
| 85 |
+
|
| 86 |
+
_UROMAN = None
|
| 87 |
+
_ICU = None
|
| 88 |
+
|
| 89 |
+
|
| 90 |
+
def _uroman_word(word: str, lang: str) -> str:
|
| 91 |
+
global _UROMAN
|
| 92 |
+
if _UROMAN is None:
|
| 93 |
+
import uroman
|
| 94 |
+
_UROMAN = uroman.Uroman()
|
| 95 |
+
r = _UROMAN.romanize_string(word, lcode=LANG3.get(lang))
|
| 96 |
+
return "".join(c for c in r.lower() if c in ALLOWED)
|
| 97 |
+
|
| 98 |
+
|
| 99 |
+
def _icu_word(word: str, lang: str) -> str:
|
| 100 |
+
global _ICU
|
| 101 |
+
if _ICU is None:
|
| 102 |
+
import icu
|
| 103 |
+
_ICU = icu.Transliterator.createInstance("Any-Latin; Latin-ASCII")
|
| 104 |
+
return "".join(c for c in _ICU.transliterate(word).lower() if c in ALLOWED)
|
| 105 |
+
|
| 106 |
+
|
| 107 |
+
def romanize_word(word: str, lang: str = "en", engine: str = "table") -> str:
|
| 108 |
+
"""One word (no spaces) -> characters of the romanized alphabet. May return ""."""
|
| 109 |
+
if engine == "table":
|
| 110 |
+
return _table_word(word)
|
| 111 |
+
if engine == "uroman":
|
| 112 |
+
return _uroman_word(word, lang)
|
| 113 |
+
if engine == "icu":
|
| 114 |
+
return _icu_word(word, lang)
|
| 115 |
+
raise ValueError(f"unknown romanizer {engine!r}")
|
| 116 |
+
|
| 117 |
+
|
| 118 |
+
def _romanize_piece(piece: str, lang: str, engine: str) -> str:
|
| 119 |
+
"""A run of one word's expanded characters, possibly with internal spaces ("eighteen twelve")."""
|
| 120 |
+
parts = [romanize_word(p, lang, engine) for p in piece.split(" ")]
|
| 121 |
+
return " ".join(p for p in parts if p)
|
| 122 |
+
|
| 123 |
+
|
| 124 |
+
def number_readings_lang(digits: str, lang: str) -> list[str]:
|
| 125 |
+
"""Spoken forms of a digit run in `lang`, likeliest first (requires num2words).
|
| 126 |
+
|
| 127 |
+
For 4-digit values between 1000 and 2100 the year reading comes first where num2words has one.
|
| 128 |
+
Languages num2words does not support keep the digits, which romanize to the `*` wildcard.
|
| 129 |
+
"""
|
| 130 |
+
from num2words import num2words
|
| 131 |
+
n = int(digits)
|
| 132 |
+
out = []
|
| 133 |
+
try:
|
| 134 |
+
card = num2words(n, lang=lang)
|
| 135 |
+
except NotImplementedError:
|
| 136 |
+
card = digits
|
| 137 |
+
if len(digits) == 4 and 1000 <= n <= 2100:
|
| 138 |
+
try:
|
| 139 |
+
yr = num2words(n, lang=lang, to="year")
|
| 140 |
+
if yr and yr != card:
|
| 141 |
+
out.append(yr)
|
| 142 |
+
except (NotImplementedError, TypeError, AttributeError):
|
| 143 |
+
pass
|
| 144 |
+
out.append(card)
|
| 145 |
+
return [o.replace("-", " ").replace(",", "") for o in out]
|
| 146 |
+
|
| 147 |
+
|
| 148 |
+
def romanize_expansion(exp: Expansion, lang: str = "en", engine: str = "table") -> Expansion:
|
| 149 |
+
"""Map an [Expansion] onto the romanized alphabet, keeping words, word indices and groups.
|
| 150 |
+
|
| 151 |
+
Each word is romanized as one unit (romanization is context-dependent) and `char_to_word`
|
| 152 |
+
is rebuilt so every output character still points at its source word.
|
| 153 |
+
"""
|
| 154 |
+
src, c2w = exp.text, exp.char_to_word
|
| 155 |
+
gstart = {g[0]: g for g in exp.groups}
|
| 156 |
+
out: list[str] = []
|
| 157 |
+
o_c2w: list[int] = []
|
| 158 |
+
groups: list[tuple[int, int, tuple[str, ...]]] = []
|
| 159 |
+
|
| 160 |
+
def put(chars: str, wi: int) -> None:
|
| 161 |
+
out.extend(chars)
|
| 162 |
+
o_c2w.extend([wi] * len(chars))
|
| 163 |
+
|
| 164 |
+
i, n = 0, len(src)
|
| 165 |
+
while i < n:
|
| 166 |
+
wi = c2w[i]
|
| 167 |
+
j = i
|
| 168 |
+
while j < n and c2w[j] == wi:
|
| 169 |
+
j += 1
|
| 170 |
+
if wi < 0:
|
| 171 |
+
put(src[i:j], -1)
|
| 172 |
+
i = j
|
| 173 |
+
continue
|
| 174 |
+
start_len = len(out)
|
| 175 |
+
k = i
|
| 176 |
+
while k < j:
|
| 177 |
+
if k in gstart:
|
| 178 |
+
a, b, readings = gstart[k]
|
| 179 |
+
rom = tuple(r for r in (_romanize_piece(x, lang, engine) for x in readings) if r)
|
| 180 |
+
rom = tuple(dict.fromkeys(rom)) or ("*",)
|
| 181 |
+
s0 = len(out)
|
| 182 |
+
put(rom[0], wi)
|
| 183 |
+
if len(rom) > 1:
|
| 184 |
+
groups.append((s0, len(out), rom))
|
| 185 |
+
k = b
|
| 186 |
+
continue
|
| 187 |
+
nxt = min([g for g in gstart if k < g < j] or [j])
|
| 188 |
+
put(_romanize_piece(src[k:nxt], lang, engine), wi)
|
| 189 |
+
k = nxt
|
| 190 |
+
if len(out) == start_len:
|
| 191 |
+
put("*", wi) # unromanizable word: a wildcard, never a hole
|
| 192 |
+
i = j
|
| 193 |
+
|
| 194 |
+
return Expansion(text="".join(out), char_to_word=o_c2w, words=list(exp.words), groups=groups)
|
| 195 |
+
|
| 196 |
+
|
| 197 |
+
def prepare_text(text: str, lang: str = "en", engine: str = "table") -> Expansion:
|
| 198 |
+
"""Text -> romanized [Expansion] ready for `expansion_to_tokens`."""
|
| 199 |
+
from .align import expand_text
|
| 200 |
+
return romanize_expansion(expand_text(text, lang=lang), lang=lang, engine=engine)
|
cavaalign/vocab.py
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# SPDX-License-Identifier: AGPL-3.0-or-later
|
| 2 |
+
"""Token set for CavaAlign: a 29-class romanized alphabet.
|
| 3 |
+
|
| 4 |
+
Character-level, deliberately: characters align straight onto the book's own orthography, which
|
| 5 |
+
is the text the reader is looking at, with no per-language lexicon or G2P. Every script reaches
|
| 6 |
+
this alphabet through `cavaalign.romanize`, so one model serves every language.
|
| 7 |
+
"""
|
| 8 |
+
from __future__ import annotations
|
| 9 |
+
|
| 10 |
+
BLANK = 0
|
| 11 |
+
|
| 12 |
+
# blank, 26 letters ordered by frequency, apostrophe, and `<unk>` (written `*` in romanized text),
|
| 13 |
+
# a wildcard for anything with no romanization. There is no space class: the DP scores spaces from
|
| 14 |
+
# the blank column (`align.Token.is_space`), so a space maps onto the blank id.
|
| 15 |
+
ROMAN_LETTERS = list("aienoutsrmkldghybpwcvjzf") + ["'"] + list("qx")
|
| 16 |
+
|
| 17 |
+
|
| 18 |
+
class VocabRoman:
|
| 19 |
+
"""The 29-class romanized vocab used by cavaalign.onnx."""
|
| 20 |
+
|
| 21 |
+
name = "roman29"
|
| 22 |
+
|
| 23 |
+
def __init__(self):
|
| 24 |
+
self.chars = list(ROMAN_LETTERS)
|
| 25 |
+
self.specials = ["<unk>"]
|
| 26 |
+
self.tokens = ["<blank>"] + self.chars + self.specials
|
| 27 |
+
self.stoi = {t: i for i, t in enumerate(self.tokens)}
|
| 28 |
+
self.itos = {i: t for t, i in self.stoi.items()}
|
| 29 |
+
self.char_to_id = {c: self.stoi[c] for c in self.chars}
|
| 30 |
+
self.char_to_id["*"] = self.stoi["<unk>"]
|
| 31 |
+
self.unk = self.stoi["<unk>"]
|
| 32 |
+
|
| 33 |
+
def id_for(self, ch: str) -> int:
|
| 34 |
+
"""Token id for one character, case-folded; a space is the blank id."""
|
| 35 |
+
if ch == " ":
|
| 36 |
+
return BLANK
|
| 37 |
+
return self.char_to_id.get(ch.lower(), self.unk)
|
| 38 |
+
|
| 39 |
+
def __len__(self) -> int:
|
| 40 |
+
return len(self.tokens)
|
| 41 |
+
|
| 42 |
+
@property
|
| 43 |
+
def vocab_size(self) -> int:
|
| 44 |
+
return len(self.tokens)
|
| 45 |
+
|
| 46 |
+
def encode(self, text: str) -> list[int]:
|
| 47 |
+
return [self.id_for(c) for c in text]
|
| 48 |
+
|
| 49 |
+
def decode(self, ids: list[int], collapse_repeats: bool = True) -> str:
|
| 50 |
+
out: list[str] = []
|
| 51 |
+
prev = None
|
| 52 |
+
for i in ids:
|
| 53 |
+
if i == BLANK:
|
| 54 |
+
prev = None
|
| 55 |
+
continue
|
| 56 |
+
if collapse_repeats and i == prev:
|
| 57 |
+
continue
|
| 58 |
+
prev = i
|
| 59 |
+
tok = self.itos[i]
|
| 60 |
+
if not tok.startswith("<"):
|
| 61 |
+
out.append(tok)
|
| 62 |
+
return "".join(out)
|
| 63 |
+
|
| 64 |
+
|
| 65 |
+
def vocab_for_tokens(tokens: list[str] | None) -> VocabRoman:
|
| 66 |
+
"""The vocab matching a model's `vocab_tokens` metadata.
|
| 67 |
+
|
| 68 |
+
Raises rather than guessing: a model whose output ids mean different characters from the ones
|
| 69 |
+
the aligner asks for still runs and still produces timings, and they are wrong.
|
| 70 |
+
"""
|
| 71 |
+
v = VocabRoman()
|
| 72 |
+
if tokens is not None and list(tokens) != v.tokens:
|
| 73 |
+
raise RuntimeError(f"unknown vocabulary ({len(tokens)} tokens, e.g. {list(tokens)[1:5]!r})")
|
| 74 |
+
return v
|
kotlin/CavaAlignModel.kt
ADDED
|
@@ -0,0 +1,79 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// SPDX-License-Identifier: AGPL-3.0-or-later
|
| 2 |
+
package dev.micr0.cavaalign
|
| 3 |
+
|
| 4 |
+
import ai.onnxruntime.OnnxTensor
|
| 5 |
+
import ai.onnxruntime.OrtEnvironment
|
| 6 |
+
import ai.onnxruntime.OrtSession
|
| 7 |
+
import java.nio.FloatBuffer
|
| 8 |
+
import java.nio.LongBuffer
|
| 9 |
+
|
| 10 |
+
/**
|
| 11 |
+
* Runs cavaalign.onnx with ONNX Runtime (`com.microsoft.onnxruntime:onnxruntime-android`).
|
| 12 |
+
*
|
| 13 |
+
* Audio is processed in 6.4 s windows with 3.2 s of preceding context, cut on the model's
|
| 14 |
+
* 0.64 s chunk boundaries, so memory stays around 0.3–0.4 GB for any length. This is the same
|
| 15 |
+
* recipe as `log_probs` in `align.py`.
|
| 16 |
+
*/
|
| 17 |
+
class CavaAlignModel private constructor(
|
| 18 |
+
private val env: OrtEnvironment,
|
| 19 |
+
private val session: OrtSession,
|
| 20 |
+
) : AutoCloseable {
|
| 21 |
+
|
| 22 |
+
/** Load the model from a file path. */
|
| 23 |
+
constructor(modelPath: String, threads: Int = 4) :
|
| 24 |
+
this(OrtEnvironment.getEnvironment(), modelPath, threads)
|
| 25 |
+
|
| 26 |
+
/** Load the model from bytes (e.g. read from Android assets). */
|
| 27 |
+
constructor(modelBytes: ByteArray, threads: Int = 4) :
|
| 28 |
+
this(OrtEnvironment.getEnvironment(), modelBytes, threads)
|
| 29 |
+
|
| 30 |
+
private constructor(env: OrtEnvironment, path: String, threads: Int) :
|
| 31 |
+
this(env, env.createSession(path, options(threads)))
|
| 32 |
+
|
| 33 |
+
private constructor(env: OrtEnvironment, bytes: ByteArray, threads: Int) :
|
| 34 |
+
this(env, env.createSession(bytes, options(threads)))
|
| 35 |
+
|
| 36 |
+
/** Log-probabilities for 16 kHz mono float audio in [-1, 1]; 50 frames per second. */
|
| 37 |
+
fun logProbs(audio: FloatArray): Emissions {
|
| 38 |
+
val rows = ArrayList<FloatArray>()
|
| 39 |
+
var pos = 0
|
| 40 |
+
while (pos < audio.size) {
|
| 41 |
+
val st = maxOf(0, pos - CONTEXT_CHUNKS * CHUNK)
|
| 42 |
+
val end = minOf(audio.size, pos + WINDOW_CHUNKS * CHUNK + 80) // last frame spans 400 samples
|
| 43 |
+
val x = audio.copyOfRange(st, end)
|
| 44 |
+
OnnxTensor.createTensor(env, FloatBuffer.wrap(x), longArrayOf(1, x.size.toLong())).use { wav ->
|
| 45 |
+
OnnxTensor.createTensor(env, LongBuffer.wrap(longArrayOf(x.size.toLong())), longArrayOf(1)).use { len ->
|
| 46 |
+
session.run(mapOf("waveform" to wav, "lengths" to len)).use { r ->
|
| 47 |
+
@Suppress("UNCHECKED_CAST")
|
| 48 |
+
val lp = (r[0].value as Array<Array<FloatArray>>)[0]
|
| 49 |
+
val n = when (val v = r[1].value) {
|
| 50 |
+
is LongArray -> v[0].toInt()
|
| 51 |
+
is IntArray -> v[0]
|
| 52 |
+
else -> lp.size
|
| 53 |
+
}
|
| 54 |
+
val skip = (pos - st) / 320
|
| 55 |
+
for (f in skip until minOf(n, skip + WINDOW_CHUNKS * 32)) rows.add(lp[f])
|
| 56 |
+
}
|
| 57 |
+
}
|
| 58 |
+
}
|
| 59 |
+
pos += WINDOW_CHUNKS * CHUNK
|
| 60 |
+
}
|
| 61 |
+
if (rows.isEmpty()) return Emissions(0, VOCAB)
|
| 62 |
+
return Emissions.fromMatrix(rows.toTypedArray())
|
| 63 |
+
}
|
| 64 |
+
|
| 65 |
+
override fun close() = session.close()
|
| 66 |
+
|
| 67 |
+
companion object {
|
| 68 |
+
private const val CHUNK = 32 * 320 // attention chunk: 32 frames of 20 ms
|
| 69 |
+
private const val WINDOW_CHUNKS = 10
|
| 70 |
+
private const val CONTEXT_CHUNKS = 5
|
| 71 |
+
private const val VOCAB = 29
|
| 72 |
+
|
| 73 |
+
private fun options(threads: Int) = OrtSession.SessionOptions().apply {
|
| 74 |
+
setIntraOpNumThreads(threads)
|
| 75 |
+
setCPUArenaAllocator(false) // keeps memory flat on long recordings
|
| 76 |
+
setMemoryPatternOptimization(false)
|
| 77 |
+
}
|
| 78 |
+
}
|
| 79 |
+
}
|
kotlin/CavaAligner.kt
ADDED
|
@@ -0,0 +1,638 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// SPDX-License-Identifier: AGPL-3.0-or-later
|
| 2 |
+
package dev.micr0.cavaalign
|
| 3 |
+
|
| 4 |
+
import kotlin.math.max
|
| 5 |
+
import kotlin.math.min
|
| 6 |
+
|
| 7 |
+
/**
|
| 8 |
+
* CavaAlign forced aligner: model emissions + text -> a start and end time for every word.
|
| 9 |
+
*
|
| 10 |
+
* Kotlin port of `cavaalign/align.py`; given the same emissions it produces the same timings.
|
| 11 |
+
*
|
| 12 |
+
* ```
|
| 13 |
+
* val model = CavaAlignModel(modelPath)
|
| 14 |
+
* val aligner = CavaAligner.fromText(text)
|
| 15 |
+
* val words = aligner.align(model.logProbs(audio16kMono)).words
|
| 16 |
+
* ```
|
| 17 |
+
*/
|
| 18 |
+
|
| 19 |
+
/** Per-frame log-probabilities over the vocabulary, row-major [frames][vocab]. One frame is 20 ms. */
|
| 20 |
+
class Emissions(val frames: Int, val vocab: Int) {
|
| 21 |
+
val data: FloatArray = FloatArray(frames * vocab)
|
| 22 |
+
|
| 23 |
+
operator fun get(t: Int, c: Int): Float = data[t * vocab + c]
|
| 24 |
+
fun row(t: Int): FloatArray = data.copyOfRange(t * vocab, (t + 1) * vocab)
|
| 25 |
+
|
| 26 |
+
companion object {
|
| 27 |
+
fun fromMatrix(m: Array<FloatArray>): Emissions {
|
| 28 |
+
val e = Emissions(m.size, m[0].size)
|
| 29 |
+
for (t in m.indices) System.arraycopy(m[t], 0, e.data, t * e.vocab, e.vocab)
|
| 30 |
+
return e
|
| 31 |
+
}
|
| 32 |
+
}
|
| 33 |
+
}
|
| 34 |
+
|
| 35 |
+
/** Alignment settings. The defaults match `align_config.json`. */
|
| 36 |
+
data class AlignParams(
|
| 37 |
+
val blank: Int = 0,
|
| 38 |
+
/** Added to the frame's best non-blank log-prob for a frame of sound that is not in the text. */
|
| 39 |
+
val logAudioSkip: Float = -5.0f,
|
| 40 |
+
/** Cost per character of text that is never spoken. */
|
| 41 |
+
val logTextSkip: Float = -4.0f,
|
| 42 |
+
/** Cost per character of unspoken leading text (front matter). See [freeTextPrefix]. */
|
| 43 |
+
val logPrefixSkip: Float = -0.15f,
|
| 44 |
+
/** How many leading characters may be skipped at [logPrefixSkip]. */
|
| 45 |
+
val maxPrefixTokens: Int = 6000,
|
| 46 |
+
val freeTextPrefix: Boolean = true,
|
| 47 |
+
/** Lower bound on emission scores. */
|
| 48 |
+
val emitFloor: Float = -20.0f,
|
| 49 |
+
/** Band half-width in characters; 0 disables banding. */
|
| 50 |
+
val band: Int = 512,
|
| 51 |
+
)
|
| 52 |
+
|
| 53 |
+
/** Frame span of one character of the expanded text. [unmatched] means the span is inherited. */
|
| 54 |
+
data class CharSpan(
|
| 55 |
+
val charIndex: Int,
|
| 56 |
+
val startFrame: Int,
|
| 57 |
+
val endFrame: Int, // exclusive
|
| 58 |
+
val skippedText: Boolean = false,
|
| 59 |
+
val unmatched: Boolean = false,
|
| 60 |
+
val space: Boolean = false,
|
| 61 |
+
)
|
| 62 |
+
|
| 63 |
+
/** Start and end of word [wordIndex] in seconds. */
|
| 64 |
+
data class WordTiming(val wordIndex: Int, val startSec: Double, val endSec: Double)
|
| 65 |
+
|
| 66 |
+
/**
|
| 67 |
+
* A word timing plus whether it was measured: more than half of the word's characters were
|
| 68 |
+
* matched to audio. Unmeasured words inherit the previous word's position.
|
| 69 |
+
*/
|
| 70 |
+
data class MeasuredWordTiming(
|
| 71 |
+
val wordIndex: Int,
|
| 72 |
+
val startSec: Double,
|
| 73 |
+
val endSec: Double,
|
| 74 |
+
val measured: Boolean,
|
| 75 |
+
) {
|
| 76 |
+
fun toWordTiming() = WordTiming(wordIndex, startSec, endSec)
|
| 77 |
+
}
|
| 78 |
+
|
| 79 |
+
/** Diagnostics from one alignment. */
|
| 80 |
+
data class AlignReport(
|
| 81 |
+
val chars: List<CharSpan>,
|
| 82 |
+
val totalScore: Double,
|
| 83 |
+
val frames: Int,
|
| 84 |
+
val audioSkips: Int,
|
| 85 |
+
val textSkips: Int,
|
| 86 |
+
val unmatched: Int,
|
| 87 |
+
val prefixSkipped: Int,
|
| 88 |
+
val matchedFrames: Int,
|
| 89 |
+
) {
|
| 90 |
+
/** Fraction of audio frames accounted for by the text. */
|
| 91 |
+
val audioMatchedFraction: Double get() = matchedFrames.toDouble() / max(1, frames)
|
| 92 |
+
|
| 93 |
+
/** Fraction of non-space characters after the prefix that were matched to audio. */
|
| 94 |
+
val spokenFraction: Double
|
| 95 |
+
get() {
|
| 96 |
+
val ev = chars.subList(min(prefixSkipped, chars.size), chars.size).filter { !it.space }
|
| 97 |
+
return if (ev.isEmpty()) 0.0 else ev.count { !it.unmatched }.toDouble() / ev.size
|
| 98 |
+
}
|
| 99 |
+
|
| 100 |
+
/** Fraction of the text treated as unspoken front matter. */
|
| 101 |
+
val prefixRatio: Double get() = prefixSkipped.toDouble() / max(1, chars.size)
|
| 102 |
+
|
| 103 |
+
/** True when the recording most likely does not correspond to the text. */
|
| 104 |
+
val isProbableMismatch: Boolean get() = prefixRatio > 0.25 && audioMatchedFraction < 0.5
|
| 105 |
+
}
|
| 106 |
+
|
| 107 |
+
/**
|
| 108 |
+
* Text expanded into alignable characters, with the map back to word indices.
|
| 109 |
+
*
|
| 110 |
+
* Built by [CavaAligner.expandText] and [Romanizer.expansion].
|
| 111 |
+
*/
|
| 112 |
+
class Expansion(
|
| 113 |
+
val text: String,
|
| 114 |
+
/** Expanded char index -> word index, or -1 for an inter-word space. */
|
| 115 |
+
val charToWord: IntArray,
|
| 116 |
+
val words: List<String>,
|
| 117 |
+
)
|
| 118 |
+
|
| 119 |
+
/** Backpointer arc ids; the same as `cavaalign/align.py`. */
|
| 120 |
+
private const val ARC_BLANK = 0
|
| 121 |
+
private const val ARC_EMIT = 1
|
| 122 |
+
private const val ARC_AUDIO_SKIP = 2
|
| 123 |
+
private const val ARC_TEXT_SKIP = 3
|
| 124 |
+
private const val ARC_EXTEND = 4
|
| 125 |
+
|
| 126 |
+
private const val BIG = -1.0e18f
|
| 127 |
+
|
| 128 |
+
class CavaAligner(
|
| 129 |
+
private val expansion: Expansion,
|
| 130 |
+
private val tokenIds: IntArray,
|
| 131 |
+
private val isSpace: BooleanArray,
|
| 132 |
+
private val params: AlignParams = AlignParams(),
|
| 133 |
+
private val frameShiftSec: Double = FRAME_SHIFT_SEC,
|
| 134 |
+
) {
|
| 135 |
+
private val j = tokenIds.size
|
| 136 |
+
|
| 137 |
+
/**
|
| 138 |
+
* Align [em] against the whole text. [offsetSec] is added to every time.
|
| 139 |
+
*
|
| 140 |
+
* Memory is about `2 * frames * (2 * band + maxPrefixTokens)` bytes for long texts, so align
|
| 141 |
+
* long books a chapter or section at a time, each with its own audio.
|
| 142 |
+
*/
|
| 143 |
+
fun align(em: Emissions, offsetSec: Double = 0.0, padSec: Double = 0.0): AlignResult {
|
| 144 |
+
val t = em.frames
|
| 145 |
+
if (t == 0 || j == 0) {
|
| 146 |
+
return AlignResult(emptyList(), 0.0, t, 0, 0, j, 0, emptyList())
|
| 147 |
+
}
|
| 148 |
+
val (lo, hi, width) = bandLimits(t)
|
| 149 |
+
val bpIn = ByteArray(t * width) { 255.toByte() }
|
| 150 |
+
val bpBd = ByteArray(t * width) { 255.toByte() }
|
| 151 |
+
val (sIn, sBd) = forward(em, lo, hi, width, bpIn, bpBd)
|
| 152 |
+
val bucket = if (sIn > sBd) 1 else 0
|
| 153 |
+
val score = max(sIn, sBd).toDouble()
|
| 154 |
+
if (score <= BIG / 2f) {
|
| 155 |
+
val chars = (0 until j).map { CharSpan(it, 0, 0, unmatched = true, space = isSpace[it]) }
|
| 156 |
+
val report = AlignReport(chars, Double.NEGATIVE_INFINITY, t, 0, 0, j, 0, 0)
|
| 157 |
+
return AlignResult(chars, report.totalScore, t, 0, 0, j, 0,
|
| 158 |
+
toWords(chars, offsetSec, padSec), report)
|
| 159 |
+
}
|
| 160 |
+
val (chars, report) = backtrack(lo, t, width, score, bucket, bpIn, bpBd)
|
| 161 |
+
val words = toWords(chars, offsetSec, padSec, em = em)
|
| 162 |
+
return AlignResult(chars, report.totalScore, t, report.audioSkips, report.textSkips,
|
| 163 |
+
report.unmatched, report.prefixSkipped, words, report)
|
| 164 |
+
}
|
| 165 |
+
|
| 166 |
+
data class AlignResult(
|
| 167 |
+
val chars: List<CharSpan>,
|
| 168 |
+
val score: Double,
|
| 169 |
+
val frames: Int,
|
| 170 |
+
val audioSkips: Int,
|
| 171 |
+
val textSkips: Int,
|
| 172 |
+
val unmatched: Int,
|
| 173 |
+
val prefixSkipped: Int,
|
| 174 |
+
val words: List<MeasuredWordTiming>,
|
| 175 |
+
val report: AlignReport? = null,
|
| 176 |
+
)
|
| 177 |
+
|
| 178 |
+
// --------------------------------------------------------------------- DP
|
| 179 |
+
|
| 180 |
+
private fun emissionAt(em: Emissions, t: Int, k: Int, blankLogp: Float): Float {
|
| 181 |
+
if (isSpace[k]) return blankLogp // a word gap is silence: scored by blank
|
| 182 |
+
return max(em[t, tokenIds[k]], params.emitFloor)
|
| 183 |
+
}
|
| 184 |
+
|
| 185 |
+
/** Runs the forward pass and returns the terminal (inside, boundary) scores. */
|
| 186 |
+
private fun forward(
|
| 187 |
+
em: Emissions, lo: IntArray, hi: IntArray, width: Int,
|
| 188 |
+
bpIn: ByteArray, bpBd: ByteArray,
|
| 189 |
+
): Pair<Float, Float> {
|
| 190 |
+
// Best non-blank log-prob per frame; prices the audio-skip arc.
|
| 191 |
+
val speechCol = FloatArray(em.frames) { t ->
|
| 192 |
+
var best = Float.NEGATIVE_INFINITY
|
| 193 |
+
for (c in 0 until em.vocab) {
|
| 194 |
+
if (c == params.blank) continue
|
| 195 |
+
val v = em[t, c]
|
| 196 |
+
if (v > best) best = v
|
| 197 |
+
}
|
| 198 |
+
if (best < params.emitFloor) params.emitFloor else best
|
| 199 |
+
}
|
| 200 |
+
var pIn = FloatArray(j + 1) { BIG }
|
| 201 |
+
var pBd = FloatArray(j + 1) { BIG }
|
| 202 |
+
var cIn = FloatArray(j + 1) { BIG }
|
| 203 |
+
var cBd = FloatArray(j + 1) { BIG }
|
| 204 |
+
// Initial row: unspoken leading text is nearly free.
|
| 205 |
+
if (params.freeTextPrefix) {
|
| 206 |
+
val cap = min(params.maxPrefixTokens, j)
|
| 207 |
+
for (k in 0..cap) pBd[k] = k * params.logPrefixSkip
|
| 208 |
+
} else {
|
| 209 |
+
pBd[0] = 0f
|
| 210 |
+
}
|
| 211 |
+
|
| 212 |
+
// Row buffers are swapped, so slots outside the current band are reset to BIG.
|
| 213 |
+
var prevA = 0
|
| 214 |
+
var prevB = 0
|
| 215 |
+
var cDlo = 0
|
| 216 |
+
var cDhi = j + 1
|
| 217 |
+
var pDlo = 0
|
| 218 |
+
var pDhi = j + 1
|
| 219 |
+
for (t in 0 until em.frames) {
|
| 220 |
+
val a = lo[t]
|
| 221 |
+
val b = hi[t]
|
| 222 |
+
for (k in prevA until a) { pIn[k] = BIG; pBd[k] = BIG }
|
| 223 |
+
for (k in b until prevB) { pIn[k] = BIG; pBd[k] = BIG }
|
| 224 |
+
prevA = a
|
| 225 |
+
prevB = b
|
| 226 |
+
for (k in cDlo until min(a, cDhi)) { cIn[k] = BIG; cBd[k] = BIG }
|
| 227 |
+
for (k in max(b, cDlo) until cDhi) { cIn[k] = BIG; cBd[k] = BIG }
|
| 228 |
+
cDlo = a
|
| 229 |
+
cDhi = b
|
| 230 |
+
val bt = em[t, params.blank]
|
| 231 |
+
val rowIn = t * width
|
| 232 |
+
for (k in a until b) {
|
| 233 |
+
cIn[k] = BIG
|
| 234 |
+
cBd[k] = BIG
|
| 235 |
+
val off = rowIn + (k - a)
|
| 236 |
+
val pInK = pIn[k]
|
| 237 |
+
val pBdK = pBd[k]
|
| 238 |
+
val pAny = max(pInK, pBdK)
|
| 239 |
+
var best = BIG
|
| 240 |
+
var choice = 255
|
| 241 |
+
if (pAny > BIG / 2f) {
|
| 242 |
+
val srcK = if (pInK >= pBdK) 1 else 0
|
| 243 |
+
best = pAny + bt // blank
|
| 244 |
+
choice = ARC_BLANK * 2 + srcK
|
| 245 |
+
val cand = pAny + speechCol[t] + params.logAudioSkip // audio skip
|
| 246 |
+
if (cand > best) {
|
| 247 |
+
best = cand
|
| 248 |
+
choice = ARC_AUDIO_SKIP * 2 + srcK
|
| 249 |
+
}
|
| 250 |
+
}
|
| 251 |
+
cBd[k] = best
|
| 252 |
+
bpBd[off] = choice.toByte()
|
| 253 |
+
|
| 254 |
+
var besti = BIG
|
| 255 |
+
var choicei = 255
|
| 256 |
+
if (k > 0) {
|
| 257 |
+
val e = emissionAt(em, t, k - 1, bt)
|
| 258 |
+
val qIn = pIn[k - 1]
|
| 259 |
+
val qBd = pBd[k - 1]
|
| 260 |
+
val qAny = max(qIn, qBd)
|
| 261 |
+
var cand = qAny + e // emit char k-1
|
| 262 |
+
if (cand > besti) {
|
| 263 |
+
besti = cand
|
| 264 |
+
choicei = ARC_EMIT * 2 + if (qIn >= qBd) 1 else 0
|
| 265 |
+
}
|
| 266 |
+
cand = pInK + e // extend char k-1
|
| 267 |
+
if (cand > besti) {
|
| 268 |
+
besti = cand
|
| 269 |
+
choicei = ARC_EXTEND * 2 + 1
|
| 270 |
+
}
|
| 271 |
+
}
|
| 272 |
+
cIn[k] = besti
|
| 273 |
+
bpIn[off] = choicei.toByte()
|
| 274 |
+
}
|
| 275 |
+
// text skip: exclusive running max over k within this frame
|
| 276 |
+
var run = BIG
|
| 277 |
+
var runBucket = 0
|
| 278 |
+
for (k in a until b) {
|
| 279 |
+
val cand = run + k * params.logTextSkip
|
| 280 |
+
if (cand > cBd[k]) {
|
| 281 |
+
cBd[k] = cand
|
| 282 |
+
bpBd[rowIn + (k - a)] = (ARC_TEXT_SKIP * 2 + runBucket).toByte()
|
| 283 |
+
}
|
| 284 |
+
val v: Float
|
| 285 |
+
val vb: Int
|
| 286 |
+
if (cIn[k] >= cBd[k]) { v = cIn[k]; vb = 1 } else { v = cBd[k]; vb = 0 }
|
| 287 |
+
val shifted = v - k * params.logTextSkip
|
| 288 |
+
if (shifted > run) { run = shifted; runBucket = vb }
|
| 289 |
+
}
|
| 290 |
+
val tIn = pIn; pIn = cIn; cIn = tIn
|
| 291 |
+
val tBd = pBd; pBd = cBd; cBd = tBd
|
| 292 |
+
val tLo = pDlo; pDlo = cDlo; cDlo = tLo
|
| 293 |
+
val tHi = pDhi; pDhi = cDhi; cDhi = tHi
|
| 294 |
+
}
|
| 295 |
+
for (k in prevB..j) { pIn[k] = BIG; pBd[k] = BIG }
|
| 296 |
+
for (k in 0 until min(pDlo, j + 1)) { pIn[k] = BIG; pBd[k] = BIG }
|
| 297 |
+
return pIn[j] to pBd[j]
|
| 298 |
+
}
|
| 299 |
+
|
| 300 |
+
/** Per-frame half-open band [lo, hi) over character index, non-decreasing in t. */
|
| 301 |
+
private fun bandLimits(t: Int): Triple<IntArray, IntArray, Int> {
|
| 302 |
+
val lo = IntArray(t)
|
| 303 |
+
val hi = IntArray(t)
|
| 304 |
+
if (params.band > 0) {
|
| 305 |
+
// Band center: straight line from (0, 0) to (t-1, j).
|
| 306 |
+
val span = max(1, t - 1)
|
| 307 |
+
val slope = j.toDouble() / span.toDouble()
|
| 308 |
+
for (k in 0 until t) {
|
| 309 |
+
val c = if (t > 1 && k == t - 1) j else (k * slope).toInt()
|
| 310 |
+
lo[k] = min(j, max(0, c - params.band))
|
| 311 |
+
hi[k] = min(j + 1, max(1, c + params.band + 1))
|
| 312 |
+
}
|
| 313 |
+
// With a free prefix the path may start up to `cap` characters ahead of the center,
|
| 314 |
+
// so the upper edge is widened by that amount, decaying to zero at the last frame.
|
| 315 |
+
if (params.freeTextPrefix) {
|
| 316 |
+
val cap = min(params.maxPrefixTokens, j)
|
| 317 |
+
for (k in 0 until t) {
|
| 318 |
+
val fracLeft = 1.0 - k.toDouble() / span.toDouble()
|
| 319 |
+
hi[k] = min(j + 1, hi[k] + Math.rint(cap * fracLeft).toInt())
|
| 320 |
+
}
|
| 321 |
+
}
|
| 322 |
+
} else {
|
| 323 |
+
for (k in 0 until t) { lo[k] = 0; hi[k] = j + 1 }
|
| 324 |
+
}
|
| 325 |
+
for (k in 1 until t) {
|
| 326 |
+
if (lo[k] < lo[k - 1]) lo[k] = lo[k - 1]
|
| 327 |
+
if (hi[k] < hi[k - 1]) hi[k] = hi[k - 1]
|
| 328 |
+
}
|
| 329 |
+
lo[0] = 0
|
| 330 |
+
hi[t - 1] = j + 1
|
| 331 |
+
for (k in 0 until t) {
|
| 332 |
+
lo[k] = min(lo[k], j)
|
| 333 |
+
hi[k] = max(hi[k], lo[k] + 1)
|
| 334 |
+
hi[k] = min(hi[k], j + 1)
|
| 335 |
+
}
|
| 336 |
+
var width = 0
|
| 337 |
+
for (k in 0 until t) {
|
| 338 |
+
val hiNext = if (k + 1 < t) hi[k + 1] else j + 1
|
| 339 |
+
width = max(width, hiNext - lo[k])
|
| 340 |
+
}
|
| 341 |
+
return Triple(lo, hi, width + 1)
|
| 342 |
+
}
|
| 343 |
+
|
| 344 |
+
private fun backtrack(
|
| 345 |
+
lo: IntArray, t: Int, width: Int, score: Double, startBucket: Int,
|
| 346 |
+
bpIn: ByteArray, bpBd: ByteArray,
|
| 347 |
+
): Pair<List<CharSpan>, AlignReport> {
|
| 348 |
+
val starts = IntArray(j) { -1 }
|
| 349 |
+
val ends = IntArray(j)
|
| 350 |
+
val skipped = BooleanArray(j)
|
| 351 |
+
var audioSkips = 0
|
| 352 |
+
var textSkips = 0
|
| 353 |
+
var matchedFrames = 0
|
| 354 |
+
var prefixSkipped = 0
|
| 355 |
+
var tt = t
|
| 356 |
+
var jj = j
|
| 357 |
+
var bucket = startBucket
|
| 358 |
+
var guard = (t + j) * 4L + 64
|
| 359 |
+
while ((tt > 0 || jj > 0) && guard-- > 0) {
|
| 360 |
+
if (tt == 0) {
|
| 361 |
+
// audio exhausted: the remaining leading text is unspoken front matter
|
| 362 |
+
jj--
|
| 363 |
+
if (jj >= 0) { prefixSkipped++; skipped[jj] = true }
|
| 364 |
+
bucket = 0
|
| 365 |
+
continue
|
| 366 |
+
}
|
| 367 |
+
val col = jj - lo[tt - 1]
|
| 368 |
+
check(col in 0 until width) { "backtrack out of band at t=$tt j=$jj" }
|
| 369 |
+
val off = (tt - 1) * width + col
|
| 370 |
+
val raw = (if (bucket == 1) bpIn[off] else bpBd[off]).toInt() and 0xFF
|
| 371 |
+
if (raw == 255) break
|
| 372 |
+
val arc = raw / 2
|
| 373 |
+
val src = raw % 2
|
| 374 |
+
when (arc) {
|
| 375 |
+
ARC_BLANK -> { tt--; bucket = src }
|
| 376 |
+
ARC_AUDIO_SKIP -> { tt--; audioSkips++; bucket = src }
|
| 377 |
+
ARC_EMIT -> {
|
| 378 |
+
tt--; jj--
|
| 379 |
+
record(starts, ends, jj, tt)
|
| 380 |
+
matchedFrames++
|
| 381 |
+
bucket = src
|
| 382 |
+
}
|
| 383 |
+
ARC_EXTEND -> {
|
| 384 |
+
tt--
|
| 385 |
+
record(starts, ends, jj - 1, tt)
|
| 386 |
+
matchedFrames++
|
| 387 |
+
bucket = src
|
| 388 |
+
}
|
| 389 |
+
else -> {
|
| 390 |
+
jj--; textSkips++
|
| 391 |
+
if (jj >= 0) skipped[jj] = true
|
| 392 |
+
bucket = src
|
| 393 |
+
}
|
| 394 |
+
}
|
| 395 |
+
}
|
| 396 |
+
val chars = ArrayList<CharSpan>(j)
|
| 397 |
+
var unmatched = 0
|
| 398 |
+
var lastEnd = 0
|
| 399 |
+
for (k in 0 until j) {
|
| 400 |
+
if (starts[k] >= 0) {
|
| 401 |
+
lastEnd = ends[k]
|
| 402 |
+
chars.add(CharSpan(k, starts[k], ends[k], skipped[k], false, isSpace[k]))
|
| 403 |
+
} else {
|
| 404 |
+
unmatched++
|
| 405 |
+
chars.add(CharSpan(k, lastEnd, lastEnd, skipped[k], true, isSpace[k]))
|
| 406 |
+
}
|
| 407 |
+
}
|
| 408 |
+
val report = AlignReport(chars, score, t, audioSkips, textSkips, unmatched,
|
| 409 |
+
prefixSkipped, matchedFrames)
|
| 410 |
+
return chars to report
|
| 411 |
+
}
|
| 412 |
+
|
| 413 |
+
/** Record that character [k] was spoken at frame [t]. */
|
| 414 |
+
private fun record(starts: IntArray, ends: IntArray, k: Int, t: Int) {
|
| 415 |
+
if (k < 0) return
|
| 416 |
+
if (starts[k] < 0 || t < starts[k]) starts[k] = t
|
| 417 |
+
if (t + 1 > ends[k]) ends[k] = t + 1
|
| 418 |
+
}
|
| 419 |
+
|
| 420 |
+
// --------------------------------------------------------------------- words
|
| 421 |
+
|
| 422 |
+
/**
|
| 423 |
+
* Character spans -> word timings.
|
| 424 |
+
*
|
| 425 |
+
* With [em], each word's end is moved to the blank peak within 8 frames after it (never past
|
| 426 |
+
* the next word's start). Starts are moved earlier by [startOffsetSec] (default one frame).
|
| 427 |
+
* Times never go backwards.
|
| 428 |
+
*/
|
| 429 |
+
fun toWords(
|
| 430 |
+
chars: List<CharSpan>, offsetSec: Double = 0.0, padSec: Double = 0.0,
|
| 431 |
+
startOffsetSec: Double? = null, em: Emissions? = null,
|
| 432 |
+
): List<MeasuredWordTiming> {
|
| 433 |
+
val nWords = expansion.words.size
|
| 434 |
+
val c2w = expansion.charToWord
|
| 435 |
+
val shift = startOffsetSec ?: frameShiftSec
|
| 436 |
+
val snap = if (em != null) snapWordEnds(em, chars, nWords) else null
|
| 437 |
+
val nChars = IntArray(nWords)
|
| 438 |
+
val nHit = IntArray(nWords)
|
| 439 |
+
val starts = DoubleArray(nWords) { Double.POSITIVE_INFINITY }
|
| 440 |
+
val ends = DoubleArray(nWords) { Double.NEGATIVE_INFINITY }
|
| 441 |
+
for (sp in chars) {
|
| 442 |
+
if (sp.charIndex >= c2w.size) continue
|
| 443 |
+
val wi = c2w[sp.charIndex]
|
| 444 |
+
if (wi < 0) continue
|
| 445 |
+
nChars[wi]++
|
| 446 |
+
if (sp.unmatched) continue
|
| 447 |
+
nHit[wi]++
|
| 448 |
+
val sFrame: Int
|
| 449 |
+
val eFrame: Int
|
| 450 |
+
if (snap != null && snap.first[wi] >= 0) {
|
| 451 |
+
sFrame = snap.first[wi]; eFrame = snap.second[wi]
|
| 452 |
+
} else {
|
| 453 |
+
sFrame = sp.startFrame; eFrame = sp.endFrame
|
| 454 |
+
}
|
| 455 |
+
val eRel = eFrame * frameShiftSec
|
| 456 |
+
val sRel = max(0.0, min(sFrame * frameShiftSec - shift, eRel))
|
| 457 |
+
val s = sRel + offsetSec
|
| 458 |
+
val e = eRel + offsetSec
|
| 459 |
+
if (s < starts[wi]) starts[wi] = s
|
| 460 |
+
if (e > ends[wi]) ends[wi] = e
|
| 461 |
+
}
|
| 462 |
+
val out = ArrayList<MeasuredWordTiming>(nWords)
|
| 463 |
+
var lastEnd = 0.0
|
| 464 |
+
for (wi in 0 until nWords) {
|
| 465 |
+
val measured = nChars[wi] > 0 && nHit[wi] * 2 > nChars[wi]
|
| 466 |
+
var s = starts[wi]
|
| 467 |
+
var e = ends[wi]
|
| 468 |
+
if (s == Double.POSITIVE_INFINITY) s = lastEnd
|
| 469 |
+
if (e == Double.NEGATIVE_INFINITY || e < s) e = s + frameShiftSec
|
| 470 |
+
if (lastEnd > 0 && s < lastEnd - frameShiftSec) s = lastEnd - frameShiftSec
|
| 471 |
+
if (e < s) e = s
|
| 472 |
+
if (measured) lastEnd = max(lastEnd, e)
|
| 473 |
+
out.add(MeasuredWordTiming(wi, max(0.0, s - padSec), e + padSec, measured))
|
| 474 |
+
}
|
| 475 |
+
return out
|
| 476 |
+
}
|
| 477 |
+
|
| 478 |
+
/** Per-word (start, end) frames with ends moved to the following blank peak; -1 if unmeasured. */
|
| 479 |
+
private fun snapWordEnds(em: Emissions, chars: List<CharSpan>, nWords: Int,
|
| 480 |
+
maxExpand: Int = 8): Pair<IntArray, IntArray> {
|
| 481 |
+
val t = em.frames
|
| 482 |
+
val c2w = expansion.charToWord
|
| 483 |
+
val starts = IntArray(nWords) { -1 }
|
| 484 |
+
val ends = IntArray(nWords) { -1 }
|
| 485 |
+
for (sp in chars) {
|
| 486 |
+
if (sp.charIndex >= c2w.size) break
|
| 487 |
+
val wi = c2w[sp.charIndex]
|
| 488 |
+
if (wi < 0 || sp.unmatched) continue
|
| 489 |
+
if (starts[wi] < 0 || sp.startFrame < starts[wi]) starts[wi] = sp.startFrame
|
| 490 |
+
if (ends[wi] < 0 || sp.endFrame > ends[wi]) ends[wi] = sp.endFrame
|
| 491 |
+
}
|
| 492 |
+
for (wi in 0 until nWords) {
|
| 493 |
+
if (starts[wi] < 0) continue
|
| 494 |
+
val e = ends[wi]
|
| 495 |
+
val nextStart = if (wi + 1 < nWords) starts[wi + 1] else -1
|
| 496 |
+
val lo = min(max(e, 0), t)
|
| 497 |
+
val hi = if (nextStart < 0) t else min(t, nextStart)
|
| 498 |
+
val stop = min(hi, lo + maxExpand)
|
| 499 |
+
if (hi - lo > 0 && stop > lo) {
|
| 500 |
+
var peak = lo
|
| 501 |
+
var best = em[lo, params.blank]
|
| 502 |
+
for (f in lo + 1 until stop) {
|
| 503 |
+
val v = em[f, params.blank]
|
| 504 |
+
if (v > best) { best = v; peak = f }
|
| 505 |
+
}
|
| 506 |
+
ends[wi] = max(e, peak)
|
| 507 |
+
}
|
| 508 |
+
}
|
| 509 |
+
return starts to ends
|
| 510 |
+
}
|
| 511 |
+
|
| 512 |
+
companion object {
|
| 513 |
+
/** Frame duration of cavaalign.onnx (`frame_shift_sec` in align_config.json). */
|
| 514 |
+
const val FRAME_SHIFT_SEC = 0.02
|
| 515 |
+
|
| 516 |
+
/** Output classes of cavaalign.onnx (`vocab_tokens` in align_config.json). */
|
| 517 |
+
val VOCAB_TOKENS: List<String> = listOf("<blank>") +
|
| 518 |
+
"aienoutsrmkldghybpwcvjzf'qx".map { it.toString() } + listOf("<unk>")
|
| 519 |
+
|
| 520 |
+
/** Word segmentation: letter/digit runs with apostrophe continuations. */
|
| 521 |
+
private val WORD_RE = Regex("[\\p{L}\\p{Nd}]+(?:['’][\\p{L}]+)*")
|
| 522 |
+
|
| 523 |
+
/**
|
| 524 |
+
* Rewrite text into alignable characters plus the map back to word indices.
|
| 525 |
+
*
|
| 526 |
+
* One space per inter-word gap (word -1); digit runs are replaced by an English reading.
|
| 527 |
+
* The output keeps the original script; pass it through [Romanizer.expansion].
|
| 528 |
+
*/
|
| 529 |
+
fun expandText(text: String): Expansion {
|
| 530 |
+
val out = StringBuilder()
|
| 531 |
+
val c2w = ArrayList<Int>()
|
| 532 |
+
val words = ArrayList<String>()
|
| 533 |
+
fun put(s: String, wi: Int) {
|
| 534 |
+
for (ch in s) { out.append(ch); c2w.add(wi) }
|
| 535 |
+
}
|
| 536 |
+
for (m in WORD_RE.findAll(text)) {
|
| 537 |
+
val word = m.value
|
| 538 |
+
val wi = words.size
|
| 539 |
+
words.add(word)
|
| 540 |
+
if (out.isNotEmpty() && out[out.length - 1] != ' ') put(" ", -1)
|
| 541 |
+
val core = word.trim { !it.isLetterOrDigit() }
|
| 542 |
+
if (core.isEmpty()) { put(word, wi); continue }
|
| 543 |
+
if (core.all { it.isDigit() }) {
|
| 544 |
+
val readings = numberReadings(core)
|
| 545 |
+
put(readings.firstOrNull { r -> r.any { it.isLetter() } } ?: readings.first(), wi)
|
| 546 |
+
continue
|
| 547 |
+
}
|
| 548 |
+
put(word, wi)
|
| 549 |
+
}
|
| 550 |
+
return Expansion(out.toString(), c2w.toIntArray(), words)
|
| 551 |
+
}
|
| 552 |
+
|
| 553 |
+
/** [expandText] followed by [Romanizer.expansion]: ready for [tokenize]. */
|
| 554 |
+
fun prepareText(text: String): Expansion = Romanizer.expansion(expandText(text))
|
| 555 |
+
|
| 556 |
+
/** Token ids and space flags for a romanized expansion. A space maps to blank (id 0). */
|
| 557 |
+
fun tokenize(exp: Expansion, vocabTokens: List<String> = VOCAB_TOKENS): Pair<IntArray, BooleanArray> {
|
| 558 |
+
val index = HashMap<Char, Int>()
|
| 559 |
+
for ((i, tok) in vocabTokens.withIndex()) if (tok.length == 1) index[tok[0]] = i
|
| 560 |
+
val unk = vocabTokens.indexOf("<unk>")
|
| 561 |
+
require(unk >= 0 && vocabTokens[0] == "<blank>") { "unexpected vocabulary" }
|
| 562 |
+
val ids = IntArray(exp.text.length)
|
| 563 |
+
val space = BooleanArray(exp.text.length)
|
| 564 |
+
for ((i, ch) in exp.text.withIndex()) {
|
| 565 |
+
space[i] = ch == ' '
|
| 566 |
+
ids[i] = if (space[i]) 0 else index[ch.lowercaseChar()] ?: unk
|
| 567 |
+
}
|
| 568 |
+
return ids to space
|
| 569 |
+
}
|
| 570 |
+
|
| 571 |
+
/** Build an aligner for [text]: expand, romanize and tokenize it. */
|
| 572 |
+
fun fromText(
|
| 573 |
+
text: String,
|
| 574 |
+
params: AlignParams = AlignParams(),
|
| 575 |
+
vocabTokens: List<String> = VOCAB_TOKENS,
|
| 576 |
+
frameShiftSec: Double = FRAME_SHIFT_SEC,
|
| 577 |
+
): CavaAligner {
|
| 578 |
+
val exp = prepareText(text)
|
| 579 |
+
val (ids, space) = tokenize(exp, vocabTokens)
|
| 580 |
+
return CavaAligner(exp, ids, space, params, frameShiftSec)
|
| 581 |
+
}
|
| 582 |
+
|
| 583 |
+
/** Plausible English spoken forms of a digit run, likeliest first. */
|
| 584 |
+
fun numberReadings(digits: String): List<String> {
|
| 585 |
+
val n = digits.toLongOrNull()
|
| 586 |
+
?: return listOf(digits, digits.map { ONES[it.digitToInt()] }.joinToString(" "))
|
| 587 |
+
val cardinal = numberToWords(n)
|
| 588 |
+
val out = ArrayList<String>()
|
| 589 |
+
if (digits.length == 4) {
|
| 590 |
+
val hi = digits.substring(0, 2).toInt()
|
| 591 |
+
val lo = digits.substring(2).toInt()
|
| 592 |
+
if (hi in 10..99) {
|
| 593 |
+
when {
|
| 594 |
+
lo == 0 -> out.add("${numberToWords(hi.toLong())} hundred")
|
| 595 |
+
lo < 10 -> {
|
| 596 |
+
out.add("${numberToWords(hi.toLong())} oh ${ONES[lo]}")
|
| 597 |
+
out.add("${numberToWords(hi.toLong())} ${numberToWords(lo.toLong())}")
|
| 598 |
+
}
|
| 599 |
+
else -> out.add("${numberToWords(hi.toLong())} ${numberToWords(lo.toLong())}")
|
| 600 |
+
}
|
| 601 |
+
}
|
| 602 |
+
}
|
| 603 |
+
val yearLike = digits.length in 3..4 && n in 100..2100 && out.isNotEmpty()
|
| 604 |
+
if (!yearLike) {
|
| 605 |
+
out.clear()
|
| 606 |
+
out.add(cardinal)
|
| 607 |
+
}
|
| 608 |
+
if (cardinal !in out) out.add(cardinal)
|
| 609 |
+
out.add(digits.map { ONES[it.digitToInt()] }.joinToString(" "))
|
| 610 |
+
return out.distinct().filter { it.isNotEmpty() }
|
| 611 |
+
}
|
| 612 |
+
|
| 613 |
+
private val ONES = listOf(
|
| 614 |
+
"zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine", "ten",
|
| 615 |
+
"eleven", "twelve", "thirteen", "fourteen", "fifteen", "sixteen", "seventeen",
|
| 616 |
+
"eighteen", "nineteen")
|
| 617 |
+
private val TENS = listOf(
|
| 618 |
+
"", "", "twenty", "thirty", "forty", "fifty", "sixty", "seventy", "eighty", "ninety")
|
| 619 |
+
|
| 620 |
+
fun numberToWords(n: Long): String {
|
| 621 |
+
if (n < 0) return "negative ${numberToWords(-n)}"
|
| 622 |
+
if (n < 20) return ONES[n.toInt()]
|
| 623 |
+
if (n < 100) {
|
| 624 |
+
val t = (n / 10).toInt(); val o = (n % 10).toInt()
|
| 625 |
+
return TENS[t] + (if (o == 0) "" else " ${ONES[o]}")
|
| 626 |
+
}
|
| 627 |
+
if (n < 1000) {
|
| 628 |
+
val h = (n / 100).toInt(); val r = n % 100
|
| 629 |
+
return "${ONES[h]} hundred" + (if (r == 0L) "" else " ${numberToWords(r)}")
|
| 630 |
+
}
|
| 631 |
+
if (n < 1_000_000) {
|
| 632 |
+
val th = n / 1000; val r = n % 1000
|
| 633 |
+
return "${numberToWords(th)} thousand" + (if (r == 0L) "" else " ${numberToWords(r)}")
|
| 634 |
+
}
|
| 635 |
+
return n.toString()
|
| 636 |
+
}
|
| 637 |
+
}
|
| 638 |
+
}
|
kotlin/Romanizer.kt
ADDED
|
@@ -0,0 +1,95 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// SPDX-License-Identifier: AGPL-3.0-or-later
|
| 2 |
+
package dev.micr0.cavaalign
|
| 3 |
+
|
| 4 |
+
import java.text.Normalizer
|
| 5 |
+
|
| 6 |
+
/**
|
| 7 |
+
* Latin or Cyrillic text -> the model's 29-class romanized alphabet.
|
| 8 |
+
*
|
| 9 |
+
* Port of the `table` engine in `cavaalign/romanize.py`, character for character. It does not
|
| 10 |
+
* use `android.icu.text.Transliterator`, whose output can change with the Android version.
|
| 11 |
+
*/
|
| 12 |
+
object Romanizer {
|
| 13 |
+
private const val ALLOWED = "abcdefghijklmnopqrstuvwxyz'"
|
| 14 |
+
|
| 15 |
+
private val LATIN_SPECIAL = mapOf(
|
| 16 |
+
'ä' to "ae", 'å' to "aa", 'ö' to "oe", 'ø' to "oe", 'ü' to "ue", 'œ' to "oe", 'æ' to "ae",
|
| 17 |
+
'ß' to "ss", 'ç' to "s", 'ş' to "sh", 'ș' to "sh", 'ț' to "ts", 'þ' to "th", 'ð' to "th",
|
| 18 |
+
'ł' to "l", 'đ' to "d", 'ı' to "i", 'ŀ' to "l", 'ij' to "ij",
|
| 19 |
+
)
|
| 20 |
+
|
| 21 |
+
private val RU = mapOf(
|
| 22 |
+
'а' to "a", 'б' to "b", 'в' to "v", 'г' to "g", 'д' to "d", 'е' to "e", 'ё' to "yo",
|
| 23 |
+
'ж' to "zh", 'з' to "z", 'и' to "i", 'й' to "y", 'к' to "k", 'л' to "l", 'м' to "m",
|
| 24 |
+
'н' to "n", 'о' to "o", 'п' to "p", 'р' to "r", 'с' to "s", 'т' to "t", 'у' to "u",
|
| 25 |
+
'ф' to "f", 'х' to "kh", 'ц' to "ts", 'ч' to "ch", 'ш' to "sh", 'щ' to "shch", 'ъ' to "",
|
| 26 |
+
'ы' to "y", 'ь' to "", 'э' to "e", 'ю' to "yu", 'я' to "ya", 'і' to "i", 'ї' to "yi",
|
| 27 |
+
'є' to "ye", 'ґ' to "g", 'ў' to "w",
|
| 28 |
+
)
|
| 29 |
+
// `е` is context-dependent; see `_ru_e` in romanize.py.
|
| 30 |
+
private val RU_YE_AFTER = "аиоуъь".toSet()
|
| 31 |
+
|
| 32 |
+
private fun ruE(prev: Char?, prevOut: String, next: Char?): String = when {
|
| 33 |
+
prev == null -> if (next == 'е' || next == 'ё') "e" else "ye"
|
| 34 |
+
prev == 'е' -> if (prevOut == "ye") "e" else "ye"
|
| 35 |
+
prev in RU_YE_AFTER -> "ye"
|
| 36 |
+
else -> "e"
|
| 37 |
+
}
|
| 38 |
+
private val APOSTROPHES = mapOf('’' to '\'', '‘' to '\'', 'ʼ' to '\'', '`' to '\'')
|
| 39 |
+
|
| 40 |
+
private fun foldLatin(ch: Char): String {
|
| 41 |
+
LATIN_SPECIAL[ch]?.let { return it }
|
| 42 |
+
val d = Normalizer.normalize(ch.toString(), Normalizer.Form.NFKD)
|
| 43 |
+
val sb = StringBuilder()
|
| 44 |
+
for (c in d) if (Character.getType(c) != Character.NON_SPACING_MARK.toInt()) sb.append(c)
|
| 45 |
+
return sb.toString()
|
| 46 |
+
}
|
| 47 |
+
|
| 48 |
+
/** One word (no spaces) -> romanized characters. May return "". */
|
| 49 |
+
fun word(word: String): String {
|
| 50 |
+
val w = word.lowercase().map { APOSTROPHES[it] ?: it }
|
| 51 |
+
val out = ArrayList<String>(w.size)
|
| 52 |
+
var prev: Char? = null
|
| 53 |
+
// word-final "ий" -> "y" ("синий" -> "siny"); "ий" elsewhere is "iy"
|
| 54 |
+
val finalIy = w.size >= 2 && w[w.size - 2] == 'и' && w[w.size - 1] == 'й'
|
| 55 |
+
for ((i, ch) in w.withIndex()) {
|
| 56 |
+
out.add(when {
|
| 57 |
+
finalIy && i == w.size - 2 -> ""
|
| 58 |
+
ch == 'е' -> ruE(prev, out.lastOrNull() ?: "", w.getOrNull(i + 1))
|
| 59 |
+
RU.containsKey(ch) -> RU.getValue(ch)
|
| 60 |
+
else -> foldLatin(ch)
|
| 61 |
+
})
|
| 62 |
+
prev = ch
|
| 63 |
+
}
|
| 64 |
+
val res = StringBuilder()
|
| 65 |
+
for (part in out) for (c in part) if (ALLOWED.indexOf(c) >= 0) res.append(c)
|
| 66 |
+
return res.toString()
|
| 67 |
+
}
|
| 68 |
+
|
| 69 |
+
/** A run of one word's characters, possibly with spaces ("eighteen twelve"). */
|
| 70 |
+
private fun piece(s: String): String =
|
| 71 |
+
s.split(' ').map { word(it) }.filter { it.isNotEmpty() }.joinToString(" ")
|
| 72 |
+
|
| 73 |
+
/**
|
| 74 |
+
* Romanize an [Expansion] word by word, keeping its words and word indices.
|
| 75 |
+
*
|
| 76 |
+
* Inter-word spaces are kept; a word that romanizes to nothing becomes `*` (`<unk>`).
|
| 77 |
+
*/
|
| 78 |
+
fun expansion(exp: Expansion): Expansion {
|
| 79 |
+
val src = exp.text
|
| 80 |
+
val c2w = exp.charToWord
|
| 81 |
+
val out = StringBuilder()
|
| 82 |
+
val oc2w = ArrayList<Int>(src.length)
|
| 83 |
+
var i = 0
|
| 84 |
+
while (i < src.length) {
|
| 85 |
+
val wi = c2w[i]
|
| 86 |
+
var j = i
|
| 87 |
+
while (j < src.length && c2w[j] == wi) j++
|
| 88 |
+
val chars = if (wi < 0) src.substring(i, j) else piece(src.substring(i, j)).ifEmpty { "*" }
|
| 89 |
+
out.append(chars)
|
| 90 |
+
repeat(chars.length) { oc2w.add(wi) }
|
| 91 |
+
i = j
|
| 92 |
+
}
|
| 93 |
+
return Expansion(out.toString(), oc2w.toIntArray(), exp.words)
|
| 94 |
+
}
|
| 95 |
+
}
|
reference/de_de.3363_2124.00.expected.json
ADDED
|
@@ -0,0 +1,547 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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| 5 |
+
"romanized_text": "mir persoenlich wie dem allgemeinen interesse entstehen dadurch schwierigkeiten die sich noch gar nicht absehen lassen bieten sie allen einfluss auf um ismas rueckkehr zu ermoeglichen und kommen sie selbst um ihre sache zu fuehren gleich kommen sie mit mir sie muessen in ihr irdisches schwerekaemmerchen die aufregung die sorge und nun die ploetzliche aussicht auf heimkehr hatten ismas widerstandskraft gelaehmt alles blut war aus ihrem gesicht entwichen mit bleichen wangen einer ohnmacht nahe lag sie auf ihrem sessel und doch war es schon",
|
| 6 |
+
"log_probs_frames": 1499,
|
| 7 |
+
"log_probs_sum": -482985.5625,
|
| 8 |
+
"log_probs_first_frame": [
|
| 9 |
+
-0.0012,
|
| 10 |
+
-9.5099,
|
| 11 |
+
-9.5983,
|
| 12 |
+
-9.0198,
|
| 13 |
+
-9.2922,
|
| 14 |
+
-9.1635,
|
| 15 |
+
-9.9557,
|
| 16 |
+
-8.9763,
|
| 17 |
+
-9.1584,
|
| 18 |
+
-9.9063,
|
| 19 |
+
-11.665,
|
| 20 |
+
-10.9525,
|
| 21 |
+
-10.1593,
|
| 22 |
+
-10.3978,
|
| 23 |
+
-11.6884,
|
| 24 |
+
-11.3325,
|
| 25 |
+
-11.0536,
|
| 26 |
+
-11.4799,
|
| 27 |
+
-8.8634,
|
| 28 |
+
-10.994,
|
| 29 |
+
-9.4968,
|
| 30 |
+
-10.6326,
|
| 31 |
+
-12.0819,
|
| 32 |
+
-11.1234,
|
| 33 |
+
-11.0397,
|
| 34 |
+
-12.3874,
|
| 35 |
+
-11.3976,
|
| 36 |
+
-12.3868,
|
| 37 |
+
-21.921
|
| 38 |
+
],
|
| 39 |
+
"words": [
|
| 40 |
+
{
|
| 41 |
+
"word_index": 0,
|
| 42 |
+
"word": "mir",
|
| 43 |
+
"start": 0.36,
|
| 44 |
+
"end": 0.54
|
| 45 |
+
},
|
| 46 |
+
{
|
| 47 |
+
"word_index": 1,
|
| 48 |
+
"word": "persönlich",
|
| 49 |
+
"start": 0.54,
|
| 50 |
+
"end": 1.22
|
| 51 |
+
},
|
| 52 |
+
{
|
| 53 |
+
"word_index": 2,
|
| 54 |
+
"word": "wie",
|
| 55 |
+
"start": 1.26,
|
| 56 |
+
"end": 1.36
|
| 57 |
+
},
|
| 58 |
+
{
|
| 59 |
+
"word_index": 3,
|
| 60 |
+
"word": "dem",
|
| 61 |
+
"start": 1.36,
|
| 62 |
+
"end": 1.52
|
| 63 |
+
},
|
| 64 |
+
{
|
| 65 |
+
"word_index": 4,
|
| 66 |
+
"word": "allgemeinen",
|
| 67 |
+
"start": 1.54,
|
| 68 |
+
"end": 1.96
|
| 69 |
+
},
|
| 70 |
+
{
|
| 71 |
+
"word_index": 5,
|
| 72 |
+
"word": "interesse",
|
| 73 |
+
"start": 1.96,
|
| 74 |
+
"end": 2.46
|
| 75 |
+
},
|
| 76 |
+
{
|
| 77 |
+
"word_index": 6,
|
| 78 |
+
"word": "entstehen",
|
| 79 |
+
"start": 2.5,
|
| 80 |
+
"end": 2.86
|
| 81 |
+
},
|
| 82 |
+
{
|
| 83 |
+
"word_index": 7,
|
| 84 |
+
"word": "dadurch",
|
| 85 |
+
"start": 2.86,
|
| 86 |
+
"end": 3.18
|
| 87 |
+
},
|
| 88 |
+
{
|
| 89 |
+
"word_index": 8,
|
| 90 |
+
"word": "schwierigkeiten",
|
| 91 |
+
"start": 3.18,
|
| 92 |
+
"end": 3.9
|
| 93 |
+
},
|
| 94 |
+
{
|
| 95 |
+
"word_index": 9,
|
| 96 |
+
"word": "die",
|
| 97 |
+
"start": 4.2,
|
| 98 |
+
"end": 4.34
|
| 99 |
+
},
|
| 100 |
+
{
|
| 101 |
+
"word_index": 10,
|
| 102 |
+
"word": "sich",
|
| 103 |
+
"start": 4.34,
|
| 104 |
+
"end": 4.5
|
| 105 |
+
},
|
| 106 |
+
{
|
| 107 |
+
"word_index": 11,
|
| 108 |
+
"word": "noch",
|
| 109 |
+
"start": 4.5,
|
| 110 |
+
"end": 4.68
|
| 111 |
+
},
|
| 112 |
+
{
|
| 113 |
+
"word_index": 12,
|
| 114 |
+
"word": "gar",
|
| 115 |
+
"start": 4.68,
|
| 116 |
+
"end": 4.86
|
| 117 |
+
},
|
| 118 |
+
{
|
| 119 |
+
"word_index": 13,
|
| 120 |
+
"word": "nicht",
|
| 121 |
+
"start": 4.86,
|
| 122 |
+
"end": 5.04
|
| 123 |
+
},
|
| 124 |
+
{
|
| 125 |
+
"word_index": 14,
|
| 126 |
+
"word": "absehen",
|
| 127 |
+
"start": 5.04,
|
| 128 |
+
"end": 5.36
|
| 129 |
+
},
|
| 130 |
+
{
|
| 131 |
+
"word_index": 15,
|
| 132 |
+
"word": "lassen",
|
| 133 |
+
"start": 5.36,
|
| 134 |
+
"end": 5.68
|
| 135 |
+
},
|
| 136 |
+
{
|
| 137 |
+
"word_index": 16,
|
| 138 |
+
"word": "bieten",
|
| 139 |
+
"start": 6.2,
|
| 140 |
+
"end": 6.48
|
| 141 |
+
},
|
| 142 |
+
{
|
| 143 |
+
"word_index": 17,
|
| 144 |
+
"word": "sie",
|
| 145 |
+
"start": 6.48,
|
| 146 |
+
"end": 6.64
|
| 147 |
+
},
|
| 148 |
+
{
|
| 149 |
+
"word_index": 18,
|
| 150 |
+
"word": "allen",
|
| 151 |
+
"start": 6.64,
|
| 152 |
+
"end": 6.9
|
| 153 |
+
},
|
| 154 |
+
{
|
| 155 |
+
"word_index": 19,
|
| 156 |
+
"word": "einfluss",
|
| 157 |
+
"start": 6.9,
|
| 158 |
+
"end": 7.3
|
| 159 |
+
},
|
| 160 |
+
{
|
| 161 |
+
"word_index": 20,
|
| 162 |
+
"word": "auf",
|
| 163 |
+
"start": 7.34,
|
| 164 |
+
"end": 7.7
|
| 165 |
+
},
|
| 166 |
+
{
|
| 167 |
+
"word_index": 21,
|
| 168 |
+
"word": "um",
|
| 169 |
+
"start": 7.88,
|
| 170 |
+
"end": 8.04
|
| 171 |
+
},
|
| 172 |
+
{
|
| 173 |
+
"word_index": 22,
|
| 174 |
+
"word": "ismas",
|
| 175 |
+
"start": 8.04,
|
| 176 |
+
"end": 8.36
|
| 177 |
+
},
|
| 178 |
+
{
|
| 179 |
+
"word_index": 23,
|
| 180 |
+
"word": "rückkehr",
|
| 181 |
+
"start": 8.36,
|
| 182 |
+
"end": 8.68
|
| 183 |
+
},
|
| 184 |
+
{
|
| 185 |
+
"word_index": 24,
|
| 186 |
+
"word": "zu",
|
| 187 |
+
"start": 8.68,
|
| 188 |
+
"end": 8.82
|
| 189 |
+
},
|
| 190 |
+
{
|
| 191 |
+
"word_index": 25,
|
| 192 |
+
"word": "ermöglichen",
|
| 193 |
+
"start": 8.84,
|
| 194 |
+
"end": 9.42
|
| 195 |
+
},
|
| 196 |
+
{
|
| 197 |
+
"word_index": 26,
|
| 198 |
+
"word": "und",
|
| 199 |
+
"start": 9.58,
|
| 200 |
+
"end": 9.74
|
| 201 |
+
},
|
| 202 |
+
{
|
| 203 |
+
"word_index": 27,
|
| 204 |
+
"word": "kommen",
|
| 205 |
+
"start": 9.74,
|
| 206 |
+
"end": 9.96
|
| 207 |
+
},
|
| 208 |
+
{
|
| 209 |
+
"word_index": 28,
|
| 210 |
+
"word": "sie",
|
| 211 |
+
"start": 9.96,
|
| 212 |
+
"end": 10.1
|
| 213 |
+
},
|
| 214 |
+
{
|
| 215 |
+
"word_index": 29,
|
| 216 |
+
"word": "selbst",
|
| 217 |
+
"start": 10.1,
|
| 218 |
+
"end": 10.48
|
| 219 |
+
},
|
| 220 |
+
{
|
| 221 |
+
"word_index": 30,
|
| 222 |
+
"word": "um",
|
| 223 |
+
"start": 10.48,
|
| 224 |
+
"end": 10.62
|
| 225 |
+
},
|
| 226 |
+
{
|
| 227 |
+
"word_index": 31,
|
| 228 |
+
"word": "ihre",
|
| 229 |
+
"start": 10.64,
|
| 230 |
+
"end": 10.84
|
| 231 |
+
},
|
| 232 |
+
{
|
| 233 |
+
"word_index": 32,
|
| 234 |
+
"word": "sache",
|
| 235 |
+
"start": 10.84,
|
| 236 |
+
"end": 11.08
|
| 237 |
+
},
|
| 238 |
+
{
|
| 239 |
+
"word_index": 33,
|
| 240 |
+
"word": "zu",
|
| 241 |
+
"start": 11.08,
|
| 242 |
+
"end": 11.22
|
| 243 |
+
},
|
| 244 |
+
{
|
| 245 |
+
"word_index": 34,
|
| 246 |
+
"word": "führen",
|
| 247 |
+
"start": 11.24,
|
| 248 |
+
"end": 11.64
|
| 249 |
+
},
|
| 250 |
+
{
|
| 251 |
+
"word_index": 35,
|
| 252 |
+
"word": "gleich",
|
| 253 |
+
"start": 12.54,
|
| 254 |
+
"end": 12.82
|
| 255 |
+
},
|
| 256 |
+
{
|
| 257 |
+
"word_index": 36,
|
| 258 |
+
"word": "kommen",
|
| 259 |
+
"start": 12.82,
|
| 260 |
+
"end": 13.06
|
| 261 |
+
},
|
| 262 |
+
{
|
| 263 |
+
"word_index": 37,
|
| 264 |
+
"word": "sie",
|
| 265 |
+
"start": 13.06,
|
| 266 |
+
"end": 13.16
|
| 267 |
+
},
|
| 268 |
+
{
|
| 269 |
+
"word_index": 38,
|
| 270 |
+
"word": "mit",
|
| 271 |
+
"start": 13.16,
|
| 272 |
+
"end": 13.36
|
| 273 |
+
},
|
| 274 |
+
{
|
| 275 |
+
"word_index": 39,
|
| 276 |
+
"word": "mir",
|
| 277 |
+
"start": 13.36,
|
| 278 |
+
"end": 13.7
|
| 279 |
+
},
|
| 280 |
+
{
|
| 281 |
+
"word_index": 40,
|
| 282 |
+
"word": "sie",
|
| 283 |
+
"start": 13.98,
|
| 284 |
+
"end": 14.12
|
| 285 |
+
},
|
| 286 |
+
{
|
| 287 |
+
"word_index": 41,
|
| 288 |
+
"word": "müssen",
|
| 289 |
+
"start": 14.12,
|
| 290 |
+
"end": 14.38
|
| 291 |
+
},
|
| 292 |
+
{
|
| 293 |
+
"word_index": 42,
|
| 294 |
+
"word": "in",
|
| 295 |
+
"start": 14.38,
|
| 296 |
+
"end": 14.5
|
| 297 |
+
},
|
| 298 |
+
{
|
| 299 |
+
"word_index": 43,
|
| 300 |
+
"word": "ihr",
|
| 301 |
+
"start": 14.5,
|
| 302 |
+
"end": 14.6
|
| 303 |
+
},
|
| 304 |
+
{
|
| 305 |
+
"word_index": 44,
|
| 306 |
+
"word": "irdisches",
|
| 307 |
+
"start": 14.62,
|
| 308 |
+
"end": 15.06
|
| 309 |
+
},
|
| 310 |
+
{
|
| 311 |
+
"word_index": 45,
|
| 312 |
+
"word": "schwerekämmerchen",
|
| 313 |
+
"start": 15.06,
|
| 314 |
+
"end": 16.0
|
| 315 |
+
},
|
| 316 |
+
{
|
| 317 |
+
"word_index": 46,
|
| 318 |
+
"word": "die",
|
| 319 |
+
"start": 17.38,
|
| 320 |
+
"end": 17.54
|
| 321 |
+
},
|
| 322 |
+
{
|
| 323 |
+
"word_index": 47,
|
| 324 |
+
"word": "aufregung",
|
| 325 |
+
"start": 17.56,
|
| 326 |
+
"end": 18.12
|
| 327 |
+
},
|
| 328 |
+
{
|
| 329 |
+
"word_index": 48,
|
| 330 |
+
"word": "die",
|
| 331 |
+
"start": 18.14,
|
| 332 |
+
"end": 18.28
|
| 333 |
+
},
|
| 334 |
+
{
|
| 335 |
+
"word_index": 49,
|
| 336 |
+
"word": "sorge",
|
| 337 |
+
"start": 18.28,
|
| 338 |
+
"end": 18.7
|
| 339 |
+
},
|
| 340 |
+
{
|
| 341 |
+
"word_index": 50,
|
| 342 |
+
"word": "und",
|
| 343 |
+
"start": 18.72,
|
| 344 |
+
"end": 18.86
|
| 345 |
+
},
|
| 346 |
+
{
|
| 347 |
+
"word_index": 51,
|
| 348 |
+
"word": "nun",
|
| 349 |
+
"start": 18.86,
|
| 350 |
+
"end": 19.04
|
| 351 |
+
},
|
| 352 |
+
{
|
| 353 |
+
"word_index": 52,
|
| 354 |
+
"word": "die",
|
| 355 |
+
"start": 19.04,
|
| 356 |
+
"end": 19.16
|
| 357 |
+
},
|
| 358 |
+
{
|
| 359 |
+
"word_index": 53,
|
| 360 |
+
"word": "plötzliche",
|
| 361 |
+
"start": 19.16,
|
| 362 |
+
"end": 19.66
|
| 363 |
+
},
|
| 364 |
+
{
|
| 365 |
+
"word_index": 54,
|
| 366 |
+
"word": "aussicht",
|
| 367 |
+
"start": 19.68,
|
| 368 |
+
"end": 20.02
|
| 369 |
+
},
|
| 370 |
+
{
|
| 371 |
+
"word_index": 55,
|
| 372 |
+
"word": "auf",
|
| 373 |
+
"start": 20.02,
|
| 374 |
+
"end": 20.18
|
| 375 |
+
},
|
| 376 |
+
{
|
| 377 |
+
"word_index": 56,
|
| 378 |
+
"word": "heimkehr",
|
| 379 |
+
"start": 20.18,
|
| 380 |
+
"end": 20.66
|
| 381 |
+
},
|
| 382 |
+
{
|
| 383 |
+
"word_index": 57,
|
| 384 |
+
"word": "hatten",
|
| 385 |
+
"start": 20.92,
|
| 386 |
+
"end": 21.22
|
| 387 |
+
},
|
| 388 |
+
{
|
| 389 |
+
"word_index": 58,
|
| 390 |
+
"word": "ismas",
|
| 391 |
+
"start": 21.24,
|
| 392 |
+
"end": 21.58
|
| 393 |
+
},
|
| 394 |
+
{
|
| 395 |
+
"word_index": 59,
|
| 396 |
+
"word": "widerstandskraft",
|
| 397 |
+
"start": 21.58,
|
| 398 |
+
"end": 22.38
|
| 399 |
+
},
|
| 400 |
+
{
|
| 401 |
+
"word_index": 60,
|
| 402 |
+
"word": "gelähmt",
|
| 403 |
+
"start": 22.38,
|
| 404 |
+
"end": 22.88
|
| 405 |
+
},
|
| 406 |
+
{
|
| 407 |
+
"word_index": 61,
|
| 408 |
+
"word": "alles",
|
| 409 |
+
"start": 23.24,
|
| 410 |
+
"end": 23.52
|
| 411 |
+
},
|
| 412 |
+
{
|
| 413 |
+
"word_index": 62,
|
| 414 |
+
"word": "blut",
|
| 415 |
+
"start": 23.52,
|
| 416 |
+
"end": 23.82
|
| 417 |
+
},
|
| 418 |
+
{
|
| 419 |
+
"word_index": 63,
|
| 420 |
+
"word": "war",
|
| 421 |
+
"start": 23.82,
|
| 422 |
+
"end": 24.06
|
| 423 |
+
},
|
| 424 |
+
{
|
| 425 |
+
"word_index": 64,
|
| 426 |
+
"word": "aus",
|
| 427 |
+
"start": 24.06,
|
| 428 |
+
"end": 24.24
|
| 429 |
+
},
|
| 430 |
+
{
|
| 431 |
+
"word_index": 65,
|
| 432 |
+
"word": "ihrem",
|
| 433 |
+
"start": 24.24,
|
| 434 |
+
"end": 24.52
|
| 435 |
+
},
|
| 436 |
+
{
|
| 437 |
+
"word_index": 66,
|
| 438 |
+
"word": "gesicht",
|
| 439 |
+
"start": 24.52,
|
| 440 |
+
"end": 24.92
|
| 441 |
+
},
|
| 442 |
+
{
|
| 443 |
+
"word_index": 67,
|
| 444 |
+
"word": "entwichen",
|
| 445 |
+
"start": 24.92,
|
| 446 |
+
"end": 25.42
|
| 447 |
+
},
|
| 448 |
+
{
|
| 449 |
+
"word_index": 68,
|
| 450 |
+
"word": "mit",
|
| 451 |
+
"start": 25.74,
|
| 452 |
+
"end": 25.92
|
| 453 |
+
},
|
| 454 |
+
{
|
| 455 |
+
"word_index": 69,
|
| 456 |
+
"word": "bleichen",
|
| 457 |
+
"start": 25.92,
|
| 458 |
+
"end": 26.36
|
| 459 |
+
},
|
| 460 |
+
{
|
| 461 |
+
"word_index": 70,
|
| 462 |
+
"word": "wangen",
|
| 463 |
+
"start": 26.36,
|
| 464 |
+
"end": 26.72
|
| 465 |
+
},
|
| 466 |
+
{
|
| 467 |
+
"word_index": 71,
|
| 468 |
+
"word": "einer",
|
| 469 |
+
"start": 26.76,
|
| 470 |
+
"end": 27.0
|
| 471 |
+
},
|
| 472 |
+
{
|
| 473 |
+
"word_index": 72,
|
| 474 |
+
"word": "ohnmacht",
|
| 475 |
+
"start": 27.02,
|
| 476 |
+
"end": 27.38
|
| 477 |
+
},
|
| 478 |
+
{
|
| 479 |
+
"word_index": 73,
|
| 480 |
+
"word": "nahe",
|
| 481 |
+
"start": 27.38,
|
| 482 |
+
"end": 27.66
|
| 483 |
+
},
|
| 484 |
+
{
|
| 485 |
+
"word_index": 74,
|
| 486 |
+
"word": "lag",
|
| 487 |
+
"start": 27.9,
|
| 488 |
+
"end": 28.12
|
| 489 |
+
},
|
| 490 |
+
{
|
| 491 |
+
"word_index": 75,
|
| 492 |
+
"word": "sie",
|
| 493 |
+
"start": 28.12,
|
| 494 |
+
"end": 28.22
|
| 495 |
+
},
|
| 496 |
+
{
|
| 497 |
+
"word_index": 76,
|
| 498 |
+
"word": "auf",
|
| 499 |
+
"start": 28.22,
|
| 500 |
+
"end": 28.38
|
| 501 |
+
},
|
| 502 |
+
{
|
| 503 |
+
"word_index": 77,
|
| 504 |
+
"word": "ihrem",
|
| 505 |
+
"start": 28.38,
|
| 506 |
+
"end": 28.62
|
| 507 |
+
},
|
| 508 |
+
{
|
| 509 |
+
"word_index": 78,
|
| 510 |
+
"word": "sessel",
|
| 511 |
+
"start": 28.62,
|
| 512 |
+
"end": 29.06
|
| 513 |
+
},
|
| 514 |
+
{
|
| 515 |
+
"word_index": 79,
|
| 516 |
+
"word": "und",
|
| 517 |
+
"start": 29.06,
|
| 518 |
+
"end": 29.08
|
| 519 |
+
},
|
| 520 |
+
{
|
| 521 |
+
"word_index": 80,
|
| 522 |
+
"word": "doch",
|
| 523 |
+
"start": 29.06,
|
| 524 |
+
"end": 29.08
|
| 525 |
+
},
|
| 526 |
+
{
|
| 527 |
+
"word_index": 81,
|
| 528 |
+
"word": "war",
|
| 529 |
+
"start": 29.06,
|
| 530 |
+
"end": 29.08
|
| 531 |
+
},
|
| 532 |
+
{
|
| 533 |
+
"word_index": 82,
|
| 534 |
+
"word": "es",
|
| 535 |
+
"start": 29.06,
|
| 536 |
+
"end": 29.08
|
| 537 |
+
},
|
| 538 |
+
{
|
| 539 |
+
"word_index": 83,
|
| 540 |
+
"word": "schon",
|
| 541 |
+
"start": 29.06,
|
| 542 |
+
"end": 29.08
|
| 543 |
+
}
|
| 544 |
+
],
|
| 545 |
+
"book_text": "mir persönlich wie dem allgemeinen interesse entstehen dadurch schwierigkeiten die sich noch gar nicht absehen lassen bieten sie allen einfluss auf um ismas rückkehr zu ermöglichen und kommen sie selbst um ihre sache zu führen gleich kommen sie mit mir sie müssen in ihr irdisches schwerekämmerchen die aufregung die sorge und nun die plötzliche aussicht auf heimkehr hatten ismas widerstandskraft gelähmt alles blut war aus ihrem gesicht entwichen mit bleichen wangen einer ohnmacht nahe lag sie auf ihrem sessel und doch war es schon",
|
| 546 |
+
"inference": "windows of 10 chunks (6.4 s) with 5 chunks (3.2 s) of context, cut on 10,240-sample chunk boundaries"
|
| 547 |
+
}
|
reference/de_de.3363_2124.00.txt
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
mir persönlich wie dem allgemeinen interesse entstehen dadurch schwierigkeiten die sich noch gar nicht absehen lassen bieten sie allen einfluss auf um ismas rückkehr zu ermöglichen und kommen sie selbst um ihre sache zu führen gleich kommen sie mit mir sie müssen in ihr irdisches schwerekämmerchen die aufregung die sorge und nun die plötzliche aussicht auf heimkehr hatten ismas widerstandskraft gelähmt alles blut war aus ihrem gesicht entwichen mit bleichen wangen einer ohnmacht nahe lag sie auf ihrem sessel und doch war es schon
|
reference/de_de.3363_2124.00.wav
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:d21f83b1f999292425c4833d1154dade380499fec27c0de360365c0d61d9a147
|
| 3 |
+
size 960044
|
reference/en_en.testclean1089_134686.00.expected.json
ADDED
|
@@ -0,0 +1,504 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"clip": "en.testclean1089_134686.00",
|
| 3 |
+
"lang": "en",
|
| 4 |
+
"source": "LibriSpeech test-clean (CC BY 4.0)",
|
| 5 |
+
"romanized_text": "he hoped there would be stew for dinner turnips and carrots and bruised potatoes and fat mutton pieces to be ladled out in thick peppered flour fattened sauce stuff it into you his belly counselled him after early nightfall the yellow lamps would light up here and there the squalid quarter of the brothels hello bertie any good in your mind number ten fresh nelly is waiting on you good night husband the music came nearer and",
|
| 6 |
+
"log_probs_frames": 1499,
|
| 7 |
+
"log_probs_sum": -491224.8125,
|
| 8 |
+
"log_probs_first_frame": [
|
| 9 |
+
-0.001,
|
| 10 |
+
-9.7752,
|
| 11 |
+
-9.7942,
|
| 12 |
+
-8.8477,
|
| 13 |
+
-9.0076,
|
| 14 |
+
-9.453,
|
| 15 |
+
-10.1894,
|
| 16 |
+
-9.6669,
|
| 17 |
+
-9.1135,
|
| 18 |
+
-10.6104,
|
| 19 |
+
-10.9302,
|
| 20 |
+
-11.315,
|
| 21 |
+
-10.8853,
|
| 22 |
+
-10.7295,
|
| 23 |
+
-12.2612,
|
| 24 |
+
-11.3769,
|
| 25 |
+
-10.3826,
|
| 26 |
+
-11.4238,
|
| 27 |
+
-9.8309,
|
| 28 |
+
-10.8057,
|
| 29 |
+
-10.5093,
|
| 30 |
+
-11.9025,
|
| 31 |
+
-12.4569,
|
| 32 |
+
-11.991,
|
| 33 |
+
-11.8352,
|
| 34 |
+
-12.6317,
|
| 35 |
+
-12.6911,
|
| 36 |
+
-12.8725,
|
| 37 |
+
-20.3741
|
| 38 |
+
],
|
| 39 |
+
"words": [
|
| 40 |
+
{
|
| 41 |
+
"word_index": 0,
|
| 42 |
+
"word": "he",
|
| 43 |
+
"start": 0.52,
|
| 44 |
+
"end": 0.66
|
| 45 |
+
},
|
| 46 |
+
{
|
| 47 |
+
"word_index": 1,
|
| 48 |
+
"word": "hoped",
|
| 49 |
+
"start": 0.66,
|
| 50 |
+
"end": 0.98
|
| 51 |
+
},
|
| 52 |
+
{
|
| 53 |
+
"word_index": 2,
|
| 54 |
+
"word": "there",
|
| 55 |
+
"start": 0.98,
|
| 56 |
+
"end": 1.14
|
| 57 |
+
},
|
| 58 |
+
{
|
| 59 |
+
"word_index": 3,
|
| 60 |
+
"word": "would",
|
| 61 |
+
"start": 1.14,
|
| 62 |
+
"end": 1.3
|
| 63 |
+
},
|
| 64 |
+
{
|
| 65 |
+
"word_index": 4,
|
| 66 |
+
"word": "be",
|
| 67 |
+
"start": 1.3,
|
| 68 |
+
"end": 1.44
|
| 69 |
+
},
|
| 70 |
+
{
|
| 71 |
+
"word_index": 5,
|
| 72 |
+
"word": "stew",
|
| 73 |
+
"start": 1.46,
|
| 74 |
+
"end": 1.8
|
| 75 |
+
},
|
| 76 |
+
{
|
| 77 |
+
"word_index": 6,
|
| 78 |
+
"word": "for",
|
| 79 |
+
"start": 1.82,
|
| 80 |
+
"end": 2.0
|
| 81 |
+
},
|
| 82 |
+
{
|
| 83 |
+
"word_index": 7,
|
| 84 |
+
"word": "dinner",
|
| 85 |
+
"start": 2.0,
|
| 86 |
+
"end": 2.44
|
| 87 |
+
},
|
| 88 |
+
{
|
| 89 |
+
"word_index": 8,
|
| 90 |
+
"word": "turnips",
|
| 91 |
+
"start": 2.58,
|
| 92 |
+
"end": 3.06
|
| 93 |
+
},
|
| 94 |
+
{
|
| 95 |
+
"word_index": 9,
|
| 96 |
+
"word": "and",
|
| 97 |
+
"start": 3.06,
|
| 98 |
+
"end": 3.22
|
| 99 |
+
},
|
| 100 |
+
{
|
| 101 |
+
"word_index": 10,
|
| 102 |
+
"word": "carrots",
|
| 103 |
+
"start": 3.22,
|
| 104 |
+
"end": 3.76
|
| 105 |
+
},
|
| 106 |
+
{
|
| 107 |
+
"word_index": 11,
|
| 108 |
+
"word": "and",
|
| 109 |
+
"start": 3.76,
|
| 110 |
+
"end": 3.96
|
| 111 |
+
},
|
| 112 |
+
{
|
| 113 |
+
"word_index": 12,
|
| 114 |
+
"word": "bruised",
|
| 115 |
+
"start": 3.96,
|
| 116 |
+
"end": 4.4
|
| 117 |
+
},
|
| 118 |
+
{
|
| 119 |
+
"word_index": 13,
|
| 120 |
+
"word": "potatoes",
|
| 121 |
+
"start": 4.4,
|
| 122 |
+
"end": 5.02
|
| 123 |
+
},
|
| 124 |
+
{
|
| 125 |
+
"word_index": 14,
|
| 126 |
+
"word": "and",
|
| 127 |
+
"start": 5.04,
|
| 128 |
+
"end": 5.24
|
| 129 |
+
},
|
| 130 |
+
{
|
| 131 |
+
"word_index": 15,
|
| 132 |
+
"word": "fat",
|
| 133 |
+
"start": 5.26,
|
| 134 |
+
"end": 5.58
|
| 135 |
+
},
|
| 136 |
+
{
|
| 137 |
+
"word_index": 16,
|
| 138 |
+
"word": "mutton",
|
| 139 |
+
"start": 5.7,
|
| 140 |
+
"end": 6.06
|
| 141 |
+
},
|
| 142 |
+
{
|
| 143 |
+
"word_index": 17,
|
| 144 |
+
"word": "pieces",
|
| 145 |
+
"start": 6.06,
|
| 146 |
+
"end": 6.5
|
| 147 |
+
},
|
| 148 |
+
{
|
| 149 |
+
"word_index": 18,
|
| 150 |
+
"word": "to",
|
| 151 |
+
"start": 6.5,
|
| 152 |
+
"end": 6.62
|
| 153 |
+
},
|
| 154 |
+
{
|
| 155 |
+
"word_index": 19,
|
| 156 |
+
"word": "be",
|
| 157 |
+
"start": 6.62,
|
| 158 |
+
"end": 6.8
|
| 159 |
+
},
|
| 160 |
+
{
|
| 161 |
+
"word_index": 20,
|
| 162 |
+
"word": "ladled",
|
| 163 |
+
"start": 6.82,
|
| 164 |
+
"end": 7.26
|
| 165 |
+
},
|
| 166 |
+
{
|
| 167 |
+
"word_index": 21,
|
| 168 |
+
"word": "out",
|
| 169 |
+
"start": 7.26,
|
| 170 |
+
"end": 7.56
|
| 171 |
+
},
|
| 172 |
+
{
|
| 173 |
+
"word_index": 22,
|
| 174 |
+
"word": "in",
|
| 175 |
+
"start": 7.56,
|
| 176 |
+
"end": 7.76
|
| 177 |
+
},
|
| 178 |
+
{
|
| 179 |
+
"word_index": 23,
|
| 180 |
+
"word": "thick",
|
| 181 |
+
"start": 7.78,
|
| 182 |
+
"end": 8.12
|
| 183 |
+
},
|
| 184 |
+
{
|
| 185 |
+
"word_index": 24,
|
| 186 |
+
"word": "peppered",
|
| 187 |
+
"start": 8.2,
|
| 188 |
+
"end": 8.7
|
| 189 |
+
},
|
| 190 |
+
{
|
| 191 |
+
"word_index": 25,
|
| 192 |
+
"word": "flour",
|
| 193 |
+
"start": 8.74,
|
| 194 |
+
"end": 9.14
|
| 195 |
+
},
|
| 196 |
+
{
|
| 197 |
+
"word_index": 26,
|
| 198 |
+
"word": "fattened",
|
| 199 |
+
"start": 9.16,
|
| 200 |
+
"end": 9.64
|
| 201 |
+
},
|
| 202 |
+
{
|
| 203 |
+
"word_index": 27,
|
| 204 |
+
"word": "sauce",
|
| 205 |
+
"start": 9.64,
|
| 206 |
+
"end": 10.18
|
| 207 |
+
},
|
| 208 |
+
{
|
| 209 |
+
"word_index": 28,
|
| 210 |
+
"word": "stuff",
|
| 211 |
+
"start": 11.14,
|
| 212 |
+
"end": 11.48
|
| 213 |
+
},
|
| 214 |
+
{
|
| 215 |
+
"word_index": 29,
|
| 216 |
+
"word": "it",
|
| 217 |
+
"start": 11.48,
|
| 218 |
+
"end": 11.6
|
| 219 |
+
},
|
| 220 |
+
{
|
| 221 |
+
"word_index": 30,
|
| 222 |
+
"word": "into",
|
| 223 |
+
"start": 11.6,
|
| 224 |
+
"end": 11.88
|
| 225 |
+
},
|
| 226 |
+
{
|
| 227 |
+
"word_index": 31,
|
| 228 |
+
"word": "you",
|
| 229 |
+
"start": 11.88,
|
| 230 |
+
"end": 12.18
|
| 231 |
+
},
|
| 232 |
+
{
|
| 233 |
+
"word_index": 32,
|
| 234 |
+
"word": "his",
|
| 235 |
+
"start": 12.3,
|
| 236 |
+
"end": 12.5
|
| 237 |
+
},
|
| 238 |
+
{
|
| 239 |
+
"word_index": 33,
|
| 240 |
+
"word": "belly",
|
| 241 |
+
"start": 12.52,
|
| 242 |
+
"end": 12.86
|
| 243 |
+
},
|
| 244 |
+
{
|
| 245 |
+
"word_index": 34,
|
| 246 |
+
"word": "counselled",
|
| 247 |
+
"start": 12.88,
|
| 248 |
+
"end": 13.34
|
| 249 |
+
},
|
| 250 |
+
{
|
| 251 |
+
"word_index": 35,
|
| 252 |
+
"word": "him",
|
| 253 |
+
"start": 13.34,
|
| 254 |
+
"end": 13.66
|
| 255 |
+
},
|
| 256 |
+
{
|
| 257 |
+
"word_index": 36,
|
| 258 |
+
"word": "after",
|
| 259 |
+
"start": 14.68,
|
| 260 |
+
"end": 15.06
|
| 261 |
+
},
|
| 262 |
+
{
|
| 263 |
+
"word_index": 37,
|
| 264 |
+
"word": "early",
|
| 265 |
+
"start": 15.08,
|
| 266 |
+
"end": 15.36
|
| 267 |
+
},
|
| 268 |
+
{
|
| 269 |
+
"word_index": 38,
|
| 270 |
+
"word": "nightfall",
|
| 271 |
+
"start": 15.38,
|
| 272 |
+
"end": 16.06
|
| 273 |
+
},
|
| 274 |
+
{
|
| 275 |
+
"word_index": 39,
|
| 276 |
+
"word": "the",
|
| 277 |
+
"start": 16.06,
|
| 278 |
+
"end": 16.22
|
| 279 |
+
},
|
| 280 |
+
{
|
| 281 |
+
"word_index": 40,
|
| 282 |
+
"word": "yellow",
|
| 283 |
+
"start": 16.22,
|
| 284 |
+
"end": 16.5
|
| 285 |
+
},
|
| 286 |
+
{
|
| 287 |
+
"word_index": 41,
|
| 288 |
+
"word": "lamps",
|
| 289 |
+
"start": 16.5,
|
| 290 |
+
"end": 16.86
|
| 291 |
+
},
|
| 292 |
+
{
|
| 293 |
+
"word_index": 42,
|
| 294 |
+
"word": "would",
|
| 295 |
+
"start": 16.86,
|
| 296 |
+
"end": 17.08
|
| 297 |
+
},
|
| 298 |
+
{
|
| 299 |
+
"word_index": 43,
|
| 300 |
+
"word": "light",
|
| 301 |
+
"start": 17.08,
|
| 302 |
+
"end": 17.36
|
| 303 |
+
},
|
| 304 |
+
{
|
| 305 |
+
"word_index": 44,
|
| 306 |
+
"word": "up",
|
| 307 |
+
"start": 17.36,
|
| 308 |
+
"end": 17.58
|
| 309 |
+
},
|
| 310 |
+
{
|
| 311 |
+
"word_index": 45,
|
| 312 |
+
"word": "here",
|
| 313 |
+
"start": 17.58,
|
| 314 |
+
"end": 17.82
|
| 315 |
+
},
|
| 316 |
+
{
|
| 317 |
+
"word_index": 46,
|
| 318 |
+
"word": "and",
|
| 319 |
+
"start": 17.82,
|
| 320 |
+
"end": 17.94
|
| 321 |
+
},
|
| 322 |
+
{
|
| 323 |
+
"word_index": 47,
|
| 324 |
+
"word": "there",
|
| 325 |
+
"start": 17.94,
|
| 326 |
+
"end": 18.38
|
| 327 |
+
},
|
| 328 |
+
{
|
| 329 |
+
"word_index": 48,
|
| 330 |
+
"word": "the",
|
| 331 |
+
"start": 18.38,
|
| 332 |
+
"end": 18.52
|
| 333 |
+
},
|
| 334 |
+
{
|
| 335 |
+
"word_index": 49,
|
| 336 |
+
"word": "squalid",
|
| 337 |
+
"start": 18.54,
|
| 338 |
+
"end": 19.08
|
| 339 |
+
},
|
| 340 |
+
{
|
| 341 |
+
"word_index": 50,
|
| 342 |
+
"word": "quarter",
|
| 343 |
+
"start": 19.1,
|
| 344 |
+
"end": 19.58
|
| 345 |
+
},
|
| 346 |
+
{
|
| 347 |
+
"word_index": 51,
|
| 348 |
+
"word": "of",
|
| 349 |
+
"start": 19.6,
|
| 350 |
+
"end": 19.72
|
| 351 |
+
},
|
| 352 |
+
{
|
| 353 |
+
"word_index": 52,
|
| 354 |
+
"word": "the",
|
| 355 |
+
"start": 19.72,
|
| 356 |
+
"end": 19.82
|
| 357 |
+
},
|
| 358 |
+
{
|
| 359 |
+
"word_index": 53,
|
| 360 |
+
"word": "brothels",
|
| 361 |
+
"start": 19.82,
|
| 362 |
+
"end": 20.56
|
| 363 |
+
},
|
| 364 |
+
{
|
| 365 |
+
"word_index": 54,
|
| 366 |
+
"word": "hello",
|
| 367 |
+
"start": 21.66,
|
| 368 |
+
"end": 21.8
|
| 369 |
+
},
|
| 370 |
+
{
|
| 371 |
+
"word_index": 55,
|
| 372 |
+
"word": "bertie",
|
| 373 |
+
"start": 21.96,
|
| 374 |
+
"end": 22.48
|
| 375 |
+
},
|
| 376 |
+
{
|
| 377 |
+
"word_index": 56,
|
| 378 |
+
"word": "any",
|
| 379 |
+
"start": 22.48,
|
| 380 |
+
"end": 22.72
|
| 381 |
+
},
|
| 382 |
+
{
|
| 383 |
+
"word_index": 57,
|
| 384 |
+
"word": "good",
|
| 385 |
+
"start": 22.74,
|
| 386 |
+
"end": 23.0
|
| 387 |
+
},
|
| 388 |
+
{
|
| 389 |
+
"word_index": 58,
|
| 390 |
+
"word": "in",
|
| 391 |
+
"start": 23.0,
|
| 392 |
+
"end": 23.1
|
| 393 |
+
},
|
| 394 |
+
{
|
| 395 |
+
"word_index": 59,
|
| 396 |
+
"word": "your",
|
| 397 |
+
"start": 23.1,
|
| 398 |
+
"end": 23.22
|
| 399 |
+
},
|
| 400 |
+
{
|
| 401 |
+
"word_index": 60,
|
| 402 |
+
"word": "mind",
|
| 403 |
+
"start": 23.22,
|
| 404 |
+
"end": 23.78
|
| 405 |
+
},
|
| 406 |
+
{
|
| 407 |
+
"word_index": 61,
|
| 408 |
+
"word": "number",
|
| 409 |
+
"start": 24.46,
|
| 410 |
+
"end": 24.92
|
| 411 |
+
},
|
| 412 |
+
{
|
| 413 |
+
"word_index": 62,
|
| 414 |
+
"word": "ten",
|
| 415 |
+
"start": 24.94,
|
| 416 |
+
"end": 25.44
|
| 417 |
+
},
|
| 418 |
+
{
|
| 419 |
+
"word_index": 63,
|
| 420 |
+
"word": "fresh",
|
| 421 |
+
"start": 25.76,
|
| 422 |
+
"end": 26.12
|
| 423 |
+
},
|
| 424 |
+
{
|
| 425 |
+
"word_index": 64,
|
| 426 |
+
"word": "nelly",
|
| 427 |
+
"start": 26.16,
|
| 428 |
+
"end": 26.56
|
| 429 |
+
},
|
| 430 |
+
{
|
| 431 |
+
"word_index": 65,
|
| 432 |
+
"word": "is",
|
| 433 |
+
"start": 26.58,
|
| 434 |
+
"end": 26.74
|
| 435 |
+
},
|
| 436 |
+
{
|
| 437 |
+
"word_index": 66,
|
| 438 |
+
"word": "waiting",
|
| 439 |
+
"start": 26.76,
|
| 440 |
+
"end": 27.12
|
| 441 |
+
},
|
| 442 |
+
{
|
| 443 |
+
"word_index": 67,
|
| 444 |
+
"word": "on",
|
| 445 |
+
"start": 27.12,
|
| 446 |
+
"end": 27.32
|
| 447 |
+
},
|
| 448 |
+
{
|
| 449 |
+
"word_index": 68,
|
| 450 |
+
"word": "you",
|
| 451 |
+
"start": 27.32,
|
| 452 |
+
"end": 27.64
|
| 453 |
+
},
|
| 454 |
+
{
|
| 455 |
+
"word_index": 69,
|
| 456 |
+
"word": "good",
|
| 457 |
+
"start": 28.34,
|
| 458 |
+
"end": 28.52
|
| 459 |
+
},
|
| 460 |
+
{
|
| 461 |
+
"word_index": 70,
|
| 462 |
+
"word": "night",
|
| 463 |
+
"start": 28.52,
|
| 464 |
+
"end": 28.72
|
| 465 |
+
},
|
| 466 |
+
{
|
| 467 |
+
"word_index": 71,
|
| 468 |
+
"word": "husband",
|
| 469 |
+
"start": 28.72,
|
| 470 |
+
"end": 29.38
|
| 471 |
+
},
|
| 472 |
+
{
|
| 473 |
+
"word_index": 72,
|
| 474 |
+
"word": "the",
|
| 475 |
+
"start": 29.38,
|
| 476 |
+
"end": 29.4
|
| 477 |
+
},
|
| 478 |
+
{
|
| 479 |
+
"word_index": 73,
|
| 480 |
+
"word": "music",
|
| 481 |
+
"start": 29.38,
|
| 482 |
+
"end": 29.4
|
| 483 |
+
},
|
| 484 |
+
{
|
| 485 |
+
"word_index": 74,
|
| 486 |
+
"word": "came",
|
| 487 |
+
"start": 29.38,
|
| 488 |
+
"end": 29.4
|
| 489 |
+
},
|
| 490 |
+
{
|
| 491 |
+
"word_index": 75,
|
| 492 |
+
"word": "nearer",
|
| 493 |
+
"start": 29.38,
|
| 494 |
+
"end": 29.4
|
| 495 |
+
},
|
| 496 |
+
{
|
| 497 |
+
"word_index": 76,
|
| 498 |
+
"word": "and",
|
| 499 |
+
"start": 29.38,
|
| 500 |
+
"end": 29.4
|
| 501 |
+
}
|
| 502 |
+
],
|
| 503 |
+
"inference": "windows of 10 chunks (6.4 s) with 5 chunks (3.2 s) of context, cut on 10,240-sample chunk boundaries"
|
| 504 |
+
}
|
reference/en_en.testclean1089_134686.00.txt
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
he hoped there would be stew for dinner turnips and carrots and bruised potatoes and fat mutton pieces to be ladled out in thick peppered flour fattened sauce stuff it into you his belly counselled him after early nightfall the yellow lamps would light up here and there the squalid quarter of the brothels hello bertie any good in your mind number ten fresh nelly is waiting on you good night husband the music came nearer and
|
reference/en_en.testclean1089_134686.00.wav
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:66b405bf1c8c8ee2b4231174cf7b319421661338698441a6d54ff54a62fe9534
|
| 3 |
+
size 960044
|
reference/ru_ru.ru.00.expected.json
ADDED
|
@@ -0,0 +1,463 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"clip": "ru.ru.00",
|
| 3 |
+
"lang": "ru",
|
| 4 |
+
"source": "Russian LibriSpeech (RuLS), public domain in the USA",
|
| 5 |
+
"romanized_text": "dlya vas dushi moyey tsaritsy krasavitsy dlya vas odnikh vremen minuvshikh nebylitsy v chasy dosugov zolotykh pod shepot stariny boltlivoy rukoyu vernoy ya pisal primite zh vy moy trud igrivyy nichikh ne trebuya pokhval schastliv uzh ya nadezhdoy sladkoy chto deva s trepetom lyubvi posmotrit mozhet byt ukradkoy na pesni greshnye moi u lukomorya dub zelenyy zlataya tsep na dube tom i dnem i nochyu kot uchenyy vse khodit po",
|
| 6 |
+
"log_probs_frames": 1499,
|
| 7 |
+
"log_probs_sum": -463829.375,
|
| 8 |
+
"log_probs_first_frame": [
|
| 9 |
+
-1.6869,
|
| 10 |
+
-5.3464,
|
| 11 |
+
-5.4768,
|
| 12 |
+
-5.0612,
|
| 13 |
+
-5.5534,
|
| 14 |
+
-6.0674,
|
| 15 |
+
-7.2536,
|
| 16 |
+
-4.6789,
|
| 17 |
+
-6.0473,
|
| 18 |
+
-6.6982,
|
| 19 |
+
-6.1665,
|
| 20 |
+
-3.6813,
|
| 21 |
+
-7.7487,
|
| 22 |
+
-1.9665,
|
| 23 |
+
-0.8515,
|
| 24 |
+
-6.0202,
|
| 25 |
+
-6.2061,
|
| 26 |
+
-3.6389,
|
| 27 |
+
-5.1141,
|
| 28 |
+
-6.1133,
|
| 29 |
+
-5.5437,
|
| 30 |
+
-1.9826,
|
| 31 |
+
-9.8335,
|
| 32 |
+
-5.6395,
|
| 33 |
+
-6.9651,
|
| 34 |
+
-10.3159,
|
| 35 |
+
-9.0611,
|
| 36 |
+
-9.0724,
|
| 37 |
+
-16.7569
|
| 38 |
+
],
|
| 39 |
+
"words": [
|
| 40 |
+
{
|
| 41 |
+
"word_index": 0,
|
| 42 |
+
"word": "Для",
|
| 43 |
+
"start": 0.0,
|
| 44 |
+
"end": 0.2
|
| 45 |
+
},
|
| 46 |
+
{
|
| 47 |
+
"word_index": 1,
|
| 48 |
+
"word": "вас",
|
| 49 |
+
"start": 0.22,
|
| 50 |
+
"end": 0.58
|
| 51 |
+
},
|
| 52 |
+
{
|
| 53 |
+
"word_index": 2,
|
| 54 |
+
"word": "души",
|
| 55 |
+
"start": 0.62,
|
| 56 |
+
"end": 0.98
|
| 57 |
+
},
|
| 58 |
+
{
|
| 59 |
+
"word_index": 3,
|
| 60 |
+
"word": "моей",
|
| 61 |
+
"start": 0.98,
|
| 62 |
+
"end": 1.26
|
| 63 |
+
},
|
| 64 |
+
{
|
| 65 |
+
"word_index": 4,
|
| 66 |
+
"word": "царицы",
|
| 67 |
+
"start": 1.26,
|
| 68 |
+
"end": 2.0
|
| 69 |
+
},
|
| 70 |
+
{
|
| 71 |
+
"word_index": 5,
|
| 72 |
+
"word": "Красавицы",
|
| 73 |
+
"start": 2.02,
|
| 74 |
+
"end": 2.8
|
| 75 |
+
},
|
| 76 |
+
{
|
| 77 |
+
"word_index": 6,
|
| 78 |
+
"word": "для",
|
| 79 |
+
"start": 2.8,
|
| 80 |
+
"end": 3.0
|
| 81 |
+
},
|
| 82 |
+
{
|
| 83 |
+
"word_index": 7,
|
| 84 |
+
"word": "вас",
|
| 85 |
+
"start": 3.0,
|
| 86 |
+
"end": 3.24
|
| 87 |
+
},
|
| 88 |
+
{
|
| 89 |
+
"word_index": 8,
|
| 90 |
+
"word": "одних",
|
| 91 |
+
"start": 3.24,
|
| 92 |
+
"end": 3.86
|
| 93 |
+
},
|
| 94 |
+
{
|
| 95 |
+
"word_index": 9,
|
| 96 |
+
"word": "Времен",
|
| 97 |
+
"start": 3.98,
|
| 98 |
+
"end": 4.42
|
| 99 |
+
},
|
| 100 |
+
{
|
| 101 |
+
"word_index": 10,
|
| 102 |
+
"word": "минувших",
|
| 103 |
+
"start": 4.46,
|
| 104 |
+
"end": 5.0
|
| 105 |
+
},
|
| 106 |
+
{
|
| 107 |
+
"word_index": 11,
|
| 108 |
+
"word": "небылицы",
|
| 109 |
+
"start": 5.0,
|
| 110 |
+
"end": 5.78
|
| 111 |
+
},
|
| 112 |
+
{
|
| 113 |
+
"word_index": 12,
|
| 114 |
+
"word": "В",
|
| 115 |
+
"start": 5.96,
|
| 116 |
+
"end": 6.04
|
| 117 |
+
},
|
| 118 |
+
{
|
| 119 |
+
"word_index": 13,
|
| 120 |
+
"word": "часы",
|
| 121 |
+
"start": 6.06,
|
| 122 |
+
"end": 6.38
|
| 123 |
+
},
|
| 124 |
+
{
|
| 125 |
+
"word_index": 14,
|
| 126 |
+
"word": "досугов",
|
| 127 |
+
"start": 6.38,
|
| 128 |
+
"end": 6.92
|
| 129 |
+
},
|
| 130 |
+
{
|
| 131 |
+
"word_index": 15,
|
| 132 |
+
"word": "золотых",
|
| 133 |
+
"start": 6.94,
|
| 134 |
+
"end": 7.54
|
| 135 |
+
},
|
| 136 |
+
{
|
| 137 |
+
"word_index": 16,
|
| 138 |
+
"word": "Под",
|
| 139 |
+
"start": 7.54,
|
| 140 |
+
"end": 7.76
|
| 141 |
+
},
|
| 142 |
+
{
|
| 143 |
+
"word_index": 17,
|
| 144 |
+
"word": "шепот",
|
| 145 |
+
"start": 7.76,
|
| 146 |
+
"end": 8.1
|
| 147 |
+
},
|
| 148 |
+
{
|
| 149 |
+
"word_index": 18,
|
| 150 |
+
"word": "старины",
|
| 151 |
+
"start": 8.1,
|
| 152 |
+
"end": 8.56
|
| 153 |
+
},
|
| 154 |
+
{
|
| 155 |
+
"word_index": 19,
|
| 156 |
+
"word": "болтливой",
|
| 157 |
+
"start": 8.58,
|
| 158 |
+
"end": 9.24
|
| 159 |
+
},
|
| 160 |
+
{
|
| 161 |
+
"word_index": 20,
|
| 162 |
+
"word": "Рукою",
|
| 163 |
+
"start": 9.54,
|
| 164 |
+
"end": 9.96
|
| 165 |
+
},
|
| 166 |
+
{
|
| 167 |
+
"word_index": 21,
|
| 168 |
+
"word": "верной",
|
| 169 |
+
"start": 9.96,
|
| 170 |
+
"end": 10.36
|
| 171 |
+
},
|
| 172 |
+
{
|
| 173 |
+
"word_index": 22,
|
| 174 |
+
"word": "я",
|
| 175 |
+
"start": 10.36,
|
| 176 |
+
"end": 10.52
|
| 177 |
+
},
|
| 178 |
+
{
|
| 179 |
+
"word_index": 23,
|
| 180 |
+
"word": "писал",
|
| 181 |
+
"start": 10.52,
|
| 182 |
+
"end": 11.12
|
| 183 |
+
},
|
| 184 |
+
{
|
| 185 |
+
"word_index": 24,
|
| 186 |
+
"word": "Примите",
|
| 187 |
+
"start": 11.66,
|
| 188 |
+
"end": 12.08
|
| 189 |
+
},
|
| 190 |
+
{
|
| 191 |
+
"word_index": 25,
|
| 192 |
+
"word": "ж",
|
| 193 |
+
"start": 12.1,
|
| 194 |
+
"end": 12.2
|
| 195 |
+
},
|
| 196 |
+
{
|
| 197 |
+
"word_index": 26,
|
| 198 |
+
"word": "вы",
|
| 199 |
+
"start": 12.2,
|
| 200 |
+
"end": 12.34
|
| 201 |
+
},
|
| 202 |
+
{
|
| 203 |
+
"word_index": 27,
|
| 204 |
+
"word": "мой",
|
| 205 |
+
"start": 12.34,
|
| 206 |
+
"end": 12.54
|
| 207 |
+
},
|
| 208 |
+
{
|
| 209 |
+
"word_index": 28,
|
| 210 |
+
"word": "труд",
|
| 211 |
+
"start": 12.54,
|
| 212 |
+
"end": 12.84
|
| 213 |
+
},
|
| 214 |
+
{
|
| 215 |
+
"word_index": 29,
|
| 216 |
+
"word": "игривый",
|
| 217 |
+
"start": 12.86,
|
| 218 |
+
"end": 13.46
|
| 219 |
+
},
|
| 220 |
+
{
|
| 221 |
+
"word_index": 30,
|
| 222 |
+
"word": "Ничьих",
|
| 223 |
+
"start": 14.02,
|
| 224 |
+
"end": 14.5
|
| 225 |
+
},
|
| 226 |
+
{
|
| 227 |
+
"word_index": 31,
|
| 228 |
+
"word": "не",
|
| 229 |
+
"start": 14.5,
|
| 230 |
+
"end": 14.62
|
| 231 |
+
},
|
| 232 |
+
{
|
| 233 |
+
"word_index": 32,
|
| 234 |
+
"word": "требуя",
|
| 235 |
+
"start": 14.64,
|
| 236 |
+
"end": 15.04
|
| 237 |
+
},
|
| 238 |
+
{
|
| 239 |
+
"word_index": 33,
|
| 240 |
+
"word": "похвал",
|
| 241 |
+
"start": 15.06,
|
| 242 |
+
"end": 15.68
|
| 243 |
+
},
|
| 244 |
+
{
|
| 245 |
+
"word_index": 34,
|
| 246 |
+
"word": "Счастлив",
|
| 247 |
+
"start": 15.78,
|
| 248 |
+
"end": 16.26
|
| 249 |
+
},
|
| 250 |
+
{
|
| 251 |
+
"word_index": 35,
|
| 252 |
+
"word": "уж",
|
| 253 |
+
"start": 16.28,
|
| 254 |
+
"end": 16.46
|
| 255 |
+
},
|
| 256 |
+
{
|
| 257 |
+
"word_index": 36,
|
| 258 |
+
"word": "я",
|
| 259 |
+
"start": 16.46,
|
| 260 |
+
"end": 16.64
|
| 261 |
+
},
|
| 262 |
+
{
|
| 263 |
+
"word_index": 37,
|
| 264 |
+
"word": "надеждой",
|
| 265 |
+
"start": 16.64,
|
| 266 |
+
"end": 17.14
|
| 267 |
+
},
|
| 268 |
+
{
|
| 269 |
+
"word_index": 38,
|
| 270 |
+
"word": "сладкой",
|
| 271 |
+
"start": 17.14,
|
| 272 |
+
"end": 17.68
|
| 273 |
+
},
|
| 274 |
+
{
|
| 275 |
+
"word_index": 39,
|
| 276 |
+
"word": "Что",
|
| 277 |
+
"start": 17.68,
|
| 278 |
+
"end": 17.88
|
| 279 |
+
},
|
| 280 |
+
{
|
| 281 |
+
"word_index": 40,
|
| 282 |
+
"word": "дева",
|
| 283 |
+
"start": 17.88,
|
| 284 |
+
"end": 18.16
|
| 285 |
+
},
|
| 286 |
+
{
|
| 287 |
+
"word_index": 41,
|
| 288 |
+
"word": "с",
|
| 289 |
+
"start": 18.18,
|
| 290 |
+
"end": 18.24
|
| 291 |
+
},
|
| 292 |
+
{
|
| 293 |
+
"word_index": 42,
|
| 294 |
+
"word": "трепетом",
|
| 295 |
+
"start": 18.24,
|
| 296 |
+
"end": 18.74
|
| 297 |
+
},
|
| 298 |
+
{
|
| 299 |
+
"word_index": 43,
|
| 300 |
+
"word": "л��бви",
|
| 301 |
+
"start": 18.74,
|
| 302 |
+
"end": 19.22
|
| 303 |
+
},
|
| 304 |
+
{
|
| 305 |
+
"word_index": 44,
|
| 306 |
+
"word": "Посмотрит",
|
| 307 |
+
"start": 19.4,
|
| 308 |
+
"end": 20.04
|
| 309 |
+
},
|
| 310 |
+
{
|
| 311 |
+
"word_index": 45,
|
| 312 |
+
"word": "может",
|
| 313 |
+
"start": 20.06,
|
| 314 |
+
"end": 20.34
|
| 315 |
+
},
|
| 316 |
+
{
|
| 317 |
+
"word_index": 46,
|
| 318 |
+
"word": "быть",
|
| 319 |
+
"start": 20.36,
|
| 320 |
+
"end": 20.54
|
| 321 |
+
},
|
| 322 |
+
{
|
| 323 |
+
"word_index": 47,
|
| 324 |
+
"word": "украдкой",
|
| 325 |
+
"start": 20.56,
|
| 326 |
+
"end": 21.16
|
| 327 |
+
},
|
| 328 |
+
{
|
| 329 |
+
"word_index": 48,
|
| 330 |
+
"word": "На",
|
| 331 |
+
"start": 21.16,
|
| 332 |
+
"end": 21.28
|
| 333 |
+
},
|
| 334 |
+
{
|
| 335 |
+
"word_index": 49,
|
| 336 |
+
"word": "песни",
|
| 337 |
+
"start": 21.3,
|
| 338 |
+
"end": 21.68
|
| 339 |
+
},
|
| 340 |
+
{
|
| 341 |
+
"word_index": 50,
|
| 342 |
+
"word": "грешные",
|
| 343 |
+
"start": 21.68,
|
| 344 |
+
"end": 22.2
|
| 345 |
+
},
|
| 346 |
+
{
|
| 347 |
+
"word_index": 51,
|
| 348 |
+
"word": "мои",
|
| 349 |
+
"start": 22.2,
|
| 350 |
+
"end": 22.62
|
| 351 |
+
},
|
| 352 |
+
{
|
| 353 |
+
"word_index": 52,
|
| 354 |
+
"word": "У",
|
| 355 |
+
"start": 23.34,
|
| 356 |
+
"end": 23.4
|
| 357 |
+
},
|
| 358 |
+
{
|
| 359 |
+
"word_index": 53,
|
| 360 |
+
"word": "лукоморья",
|
| 361 |
+
"start": 23.4,
|
| 362 |
+
"end": 24.1
|
| 363 |
+
},
|
| 364 |
+
{
|
| 365 |
+
"word_index": 54,
|
| 366 |
+
"word": "дуб",
|
| 367 |
+
"start": 24.14,
|
| 368 |
+
"end": 24.42
|
| 369 |
+
},
|
| 370 |
+
{
|
| 371 |
+
"word_index": 55,
|
| 372 |
+
"word": "зеленый",
|
| 373 |
+
"start": 24.44,
|
| 374 |
+
"end": 25.08
|
| 375 |
+
},
|
| 376 |
+
{
|
| 377 |
+
"word_index": 56,
|
| 378 |
+
"word": "Златая",
|
| 379 |
+
"start": 25.62,
|
| 380 |
+
"end": 26.16
|
| 381 |
+
},
|
| 382 |
+
{
|
| 383 |
+
"word_index": 57,
|
| 384 |
+
"word": "цепь",
|
| 385 |
+
"start": 26.18,
|
| 386 |
+
"end": 26.58
|
| 387 |
+
},
|
| 388 |
+
{
|
| 389 |
+
"word_index": 58,
|
| 390 |
+
"word": "на",
|
| 391 |
+
"start": 26.64,
|
| 392 |
+
"end": 26.78
|
| 393 |
+
},
|
| 394 |
+
{
|
| 395 |
+
"word_index": 59,
|
| 396 |
+
"word": "дубе",
|
| 397 |
+
"start": 26.8,
|
| 398 |
+
"end": 27.08
|
| 399 |
+
},
|
| 400 |
+
{
|
| 401 |
+
"word_index": 60,
|
| 402 |
+
"word": "том",
|
| 403 |
+
"start": 27.1,
|
| 404 |
+
"end": 27.52
|
| 405 |
+
},
|
| 406 |
+
{
|
| 407 |
+
"word_index": 61,
|
| 408 |
+
"word": "И",
|
| 409 |
+
"start": 27.84,
|
| 410 |
+
"end": 27.9
|
| 411 |
+
},
|
| 412 |
+
{
|
| 413 |
+
"word_index": 62,
|
| 414 |
+
"word": "днем",
|
| 415 |
+
"start": 27.92,
|
| 416 |
+
"end": 28.44
|
| 417 |
+
},
|
| 418 |
+
{
|
| 419 |
+
"word_index": 63,
|
| 420 |
+
"word": "и",
|
| 421 |
+
"start": 28.52,
|
| 422 |
+
"end": 28.6
|
| 423 |
+
},
|
| 424 |
+
{
|
| 425 |
+
"word_index": 64,
|
| 426 |
+
"word": "ночью",
|
| 427 |
+
"start": 28.62,
|
| 428 |
+
"end": 29.14
|
| 429 |
+
},
|
| 430 |
+
{
|
| 431 |
+
"word_index": 65,
|
| 432 |
+
"word": "кот",
|
| 433 |
+
"start": 29.18,
|
| 434 |
+
"end": 29.44
|
| 435 |
+
},
|
| 436 |
+
{
|
| 437 |
+
"word_index": 66,
|
| 438 |
+
"word": "ученый",
|
| 439 |
+
"start": 29.46,
|
| 440 |
+
"end": 29.8
|
| 441 |
+
},
|
| 442 |
+
{
|
| 443 |
+
"word_index": 67,
|
| 444 |
+
"word": "Все",
|
| 445 |
+
"start": 29.8,
|
| 446 |
+
"end": 29.84
|
| 447 |
+
},
|
| 448 |
+
{
|
| 449 |
+
"word_index": 68,
|
| 450 |
+
"word": "ходит",
|
| 451 |
+
"start": 29.84,
|
| 452 |
+
"end": 29.94
|
| 453 |
+
},
|
| 454 |
+
{
|
| 455 |
+
"word_index": 69,
|
| 456 |
+
"word": "по",
|
| 457 |
+
"start": 29.94,
|
| 458 |
+
"end": 29.98
|
| 459 |
+
}
|
| 460 |
+
],
|
| 461 |
+
"book_text": "Для вас, души моей царицы, Красавицы, для вас одних Времен минувших небылицы, В часы досугов золотых, Под шепот старины болтливой, Рукою верной я писал Примите ж вы мой труд игривый! Ничьих не требуя похвал, Счастлив уж я надеждой сладкой, Что дева с трепетом любви Посмотрит, может быть украдкой, На песни грешные мои. У лукоморья дуб зеленый Златая цепь на дубе том: И днем и ночью кот ученый Все ходит по",
|
| 462 |
+
"inference": "windows of 10 chunks (6.4 s) with 5 chunks (3.2 s) of context, cut on 10,240-sample chunk boundaries"
|
| 463 |
+
}
|
reference/ru_ru.ru.00.txt
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
Для вас, души моей царицы, Красавицы, для вас одних Времен минувших небылицы, В часы досугов золотых, Под шепот старины болтливой, Рукою верной я писал Примите ж вы мой труд игривый! Ничьих не требуя похвал, Счастлив уж я надеждой сладкой, Что дева с трепетом любви Посмотрит, может быть украдкой, На песни грешные мои. У лукоморья дуб зеленый Златая цепь на дубе том: И днем и ночью кот ученый Все ходит по
|
reference/ru_ru.ru.00.wav
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:35bfc42e86731ee243b9a14af8d4692fc33177010ebadfce99f1531590cd332a
|
| 3 |
+
size 960044
|
vocab.json
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"<blank>": 0,
|
| 3 |
+
"a": 1,
|
| 4 |
+
"i": 2,
|
| 5 |
+
"e": 3,
|
| 6 |
+
"n": 4,
|
| 7 |
+
"o": 5,
|
| 8 |
+
"u": 6,
|
| 9 |
+
"t": 7,
|
| 10 |
+
"s": 8,
|
| 11 |
+
"r": 9,
|
| 12 |
+
"m": 10,
|
| 13 |
+
"k": 11,
|
| 14 |
+
"l": 12,
|
| 15 |
+
"d": 13,
|
| 16 |
+
"g": 14,
|
| 17 |
+
"h": 15,
|
| 18 |
+
"y": 16,
|
| 19 |
+
"b": 17,
|
| 20 |
+
"p": 18,
|
| 21 |
+
"w": 19,
|
| 22 |
+
"c": 20,
|
| 23 |
+
"v": 21,
|
| 24 |
+
"j": 22,
|
| 25 |
+
"z": 23,
|
| 26 |
+
"f": 24,
|
| 27 |
+
"'": 25,
|
| 28 |
+
"q": 26,
|
| 29 |
+
"x": 27,
|
| 30 |
+
"<unk>": 28
|
| 31 |
+
}
|