MAX build: exact bundle 3.2 + kit + compiled runtime (closed source), private staging
Browse files- .gitattributes +3 -0
- LICENSE-CODE-Apache-2.0.txt +0 -202
- NOTICE +4 -14
- Phonon-2.5.mlpackage/Data/com.apple.CoreML/model.mlmodel +1 -1
- Phonon-2.5.mlpackage/Manifest.json +3 -3
- README.md +73 -30
- SHA256SUMS +13 -12
- phonon-coreml-src.tgz → bin/PhononCoreML.xcframework.zip +2 -2
- bin/include/phonon_coreml.h +48 -0
- libphonon_tdt.dylib → bin/libphonon_coreml.dylib +2 -2
- bin/phonon-coreml-cli +3 -0
- build.json +0 -19
- frontend.py +0 -39
- kit/Manifest.json +18 -0
- kit/kit.json +0 -0
- kit/model.mlmodel +3 -0
- kit/skeleton.deflate +3 -0
- manifest.json +5 -2
- phonon_coreml.py +0 -267
- segmenter_np.py +0 -27
.gitattributes
CHANGED
|
@@ -37,3 +37,6 @@ ci/clips/1089-134686-0000.flac filter=lfs diff=lfs merge=lfs -text
|
|
| 37 |
ci/clips/1089-134686-0002.flac filter=lfs diff=lfs merge=lfs -text
|
| 38 |
ci/clips/1089-134686-0011.flac filter=lfs diff=lfs merge=lfs -text
|
| 39 |
libphonon_tdt.dylib filter=lfs diff=lfs merge=lfs -text
|
|
|
|
|
|
|
|
|
|
|
|
| 37 |
ci/clips/1089-134686-0002.flac filter=lfs diff=lfs merge=lfs -text
|
| 38 |
ci/clips/1089-134686-0011.flac filter=lfs diff=lfs merge=lfs -text
|
| 39 |
libphonon_tdt.dylib filter=lfs diff=lfs merge=lfs -text
|
| 40 |
+
bin/libphonon_coreml.dylib filter=lfs diff=lfs merge=lfs -text
|
| 41 |
+
bin/phonon-coreml-cli filter=lfs diff=lfs merge=lfs -text
|
| 42 |
+
kit/skeleton.deflate filter=lfs diff=lfs merge=lfs -text
|
LICENSE-CODE-Apache-2.0.txt
DELETED
|
@@ -1,202 +0,0 @@
|
|
| 1 |
-
|
| 2 |
-
Apache License
|
| 3 |
-
Version 2.0, January 2004
|
| 4 |
-
http://www.apache.org/licenses/
|
| 5 |
-
|
| 6 |
-
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
| 7 |
-
|
| 8 |
-
1. Definitions.
|
| 9 |
-
|
| 10 |
-
"License" shall mean the terms and conditions for use, reproduction,
|
| 11 |
-
and distribution as defined by Sections 1 through 9 of this document.
|
| 12 |
-
|
| 13 |
-
"Licensor" shall mean the copyright owner or entity authorized by
|
| 14 |
-
the copyright owner that is granting the License.
|
| 15 |
-
|
| 16 |
-
"Legal Entity" shall mean the union of the acting entity and all
|
| 17 |
-
other entities that control, are controlled by, or are under common
|
| 18 |
-
control with that entity. For the purposes of this definition,
|
| 19 |
-
"control" means (i) the power, direct or indirect, to cause the
|
| 20 |
-
direction or management of such entity, whether by contract or
|
| 21 |
-
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
| 22 |
-
outstanding shares, or (iii) beneficial ownership of such entity.
|
| 23 |
-
|
| 24 |
-
"You" (or "Your") shall mean an individual or Legal Entity
|
| 25 |
-
exercising permissions granted by this License.
|
| 26 |
-
|
| 27 |
-
"Source" form shall mean the preferred form for making modifications,
|
| 28 |
-
including but not limited to software source code, documentation
|
| 29 |
-
source, and configuration files.
|
| 30 |
-
|
| 31 |
-
"Object" form shall mean any form resulting from mechanical
|
| 32 |
-
transformation or translation of a Source form, including but
|
| 33 |
-
not limited to compiled object code, generated documentation,
|
| 34 |
-
and conversions to other media types.
|
| 35 |
-
|
| 36 |
-
"Work" shall mean the work of authorship, whether in Source or
|
| 37 |
-
Object form, made available under the License, as indicated by a
|
| 38 |
-
copyright notice that is included in or attached to the work
|
| 39 |
-
(an example is provided in the Appendix below).
|
| 40 |
-
|
| 41 |
-
"Derivative Works" shall mean any work, whether in Source or Object
|
| 42 |
-
form, that is based on (or derived from) the Work and for which the
|
| 43 |
-
editorial revisions, annotations, elaborations, or other modifications
|
| 44 |
-
represent, as a whole, an original work of authorship. For the purposes
|
| 45 |
-
of this License, Derivative Works shall not include works that remain
|
| 46 |
-
separable from, or merely link (or bind by name) to the interfaces of,
|
| 47 |
-
the Work and Derivative Works thereof.
|
| 48 |
-
|
| 49 |
-
"Contribution" shall mean any work of authorship, including
|
| 50 |
-
the original version of the Work and any modifications or additions
|
| 51 |
-
to that Work or Derivative Works thereof, that is intentionally
|
| 52 |
-
submitted to Licensor for inclusion in the Work by the copyright owner
|
| 53 |
-
or by an individual or Legal Entity authorized to submit on behalf of
|
| 54 |
-
the copyright owner. For the purposes of this definition, "submitted"
|
| 55 |
-
means any form of electronic, verbal, or written communication sent
|
| 56 |
-
to the Licensor or its representatives, including but not limited to
|
| 57 |
-
communication on electronic mailing lists, source code control systems,
|
| 58 |
-
and issue tracking systems that are managed by, or on behalf of, the
|
| 59 |
-
Licensor for the purpose of discussing and improving the Work, but
|
| 60 |
-
excluding communication that is conspicuously marked or otherwise
|
| 61 |
-
designated in writing by the copyright owner as "Not a Contribution."
|
| 62 |
-
|
| 63 |
-
"Contributor" shall mean Licensor and any individual or Legal Entity
|
| 64 |
-
on behalf of whom a Contribution has been received by Licensor and
|
| 65 |
-
subsequently incorporated within the Work.
|
| 66 |
-
|
| 67 |
-
2. Grant of Copyright License. Subject to the terms and conditions of
|
| 68 |
-
this License, each Contributor hereby grants to You a perpetual,
|
| 69 |
-
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
| 70 |
-
copyright license to reproduce, prepare Derivative Works of,
|
| 71 |
-
publicly display, publicly perform, sublicense, and distribute the
|
| 72 |
-
Work and such Derivative Works in Source or Object form.
|
| 73 |
-
|
| 74 |
-
3. Grant of Patent License. Subject to the terms and conditions of
|
| 75 |
-
this License, each Contributor hereby grants to You a perpetual,
|
| 76 |
-
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
| 77 |
-
(except as stated in this section) patent license to make, have made,
|
| 78 |
-
use, offer to sell, sell, import, and otherwise transfer the Work,
|
| 79 |
-
where such license applies only to those patent claims licensable
|
| 80 |
-
by such Contributor that are necessarily infringed by their
|
| 81 |
-
Contribution(s) alone or by combination of their Contribution(s)
|
| 82 |
-
with the Work to which such Contribution(s) was submitted. If You
|
| 83 |
-
institute patent litigation against any entity (including a
|
| 84 |
-
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
| 85 |
-
or a Contribution incorporated within the Work constitutes direct
|
| 86 |
-
or contributory patent infringement, then any patent licenses
|
| 87 |
-
granted to You under this License for that Work shall terminate
|
| 88 |
-
as of the date such litigation is filed.
|
| 89 |
-
|
| 90 |
-
4. Redistribution. You may reproduce and distribute copies of the
|
| 91 |
-
Work or Derivative Works thereof in any medium, with or without
|
| 92 |
-
modifications, and in Source or Object form, provided that You
|
| 93 |
-
meet the following conditions:
|
| 94 |
-
|
| 95 |
-
(a) You must give any other recipients of the Work or
|
| 96 |
-
Derivative Works a copy of this License; and
|
| 97 |
-
|
| 98 |
-
(b) You must cause any modified files to carry prominent notices
|
| 99 |
-
stating that You changed the files; and
|
| 100 |
-
|
| 101 |
-
(c) You must retain, in the Source form of any Derivative Works
|
| 102 |
-
that You distribute, all copyright, patent, trademark, and
|
| 103 |
-
attribution notices from the Source form of the Work,
|
| 104 |
-
excluding those notices that do not pertain to any part of
|
| 105 |
-
the Derivative Works; and
|
| 106 |
-
|
| 107 |
-
(d) If the Work includes a "NOTICE" text file as part of its
|
| 108 |
-
distribution, then any Derivative Works that You distribute must
|
| 109 |
-
include a readable copy of the attribution notices contained
|
| 110 |
-
within such NOTICE file, excluding those notices that do not
|
| 111 |
-
pertain to any part of the Derivative Works, in at least one
|
| 112 |
-
of the following places: within a NOTICE text file distributed
|
| 113 |
-
as part of the Derivative Works; within the Source form or
|
| 114 |
-
documentation, if provided along with the Derivative Works; or,
|
| 115 |
-
within a display generated by the Derivative Works, if and
|
| 116 |
-
wherever such third-party notices normally appear. The contents
|
| 117 |
-
of the NOTICE file are for informational purposes only and
|
| 118 |
-
do not modify the License. You may add Your own attribution
|
| 119 |
-
notices within Derivative Works that You distribute, alongside
|
| 120 |
-
or as an addendum to the NOTICE text from the Work, provided
|
| 121 |
-
that such additional attribution notices cannot be construed
|
| 122 |
-
as modifying the License.
|
| 123 |
-
|
| 124 |
-
You may add Your own copyright statement to Your modifications and
|
| 125 |
-
may provide additional or different license terms and conditions
|
| 126 |
-
for use, reproduction, or distribution of Your modifications, or
|
| 127 |
-
for any such Derivative Works as a whole, provided Your use,
|
| 128 |
-
reproduction, and distribution of the Work otherwise complies with
|
| 129 |
-
the conditions stated in this License.
|
| 130 |
-
|
| 131 |
-
5. Submission of Contributions. Unless You explicitly state otherwise,
|
| 132 |
-
any Contribution intentionally submitted for inclusion in the Work
|
| 133 |
-
by You to the Licensor shall be under the terms and conditions of
|
| 134 |
-
this License, without any additional terms or conditions.
|
| 135 |
-
Notwithstanding the above, nothing herein shall supersede or modify
|
| 136 |
-
the terms of any separate license agreement you may have executed
|
| 137 |
-
with Licensor regarding such Contributions.
|
| 138 |
-
|
| 139 |
-
6. Trademarks. This License does not grant permission to use the trade
|
| 140 |
-
names, trademarks, service marks, or product names of the Licensor,
|
| 141 |
-
except as required for reasonable and customary use in describing the
|
| 142 |
-
origin of the Work and reproducing the content of the NOTICE file.
|
| 143 |
-
|
| 144 |
-
7. Disclaimer of Warranty. Unless required by applicable law or
|
| 145 |
-
agreed to in writing, Licensor provides the Work (and each
|
| 146 |
-
Contributor provides its Contributions) on an "AS IS" BASIS,
|
| 147 |
-
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
| 148 |
-
implied, including, without limitation, any warranties or conditions
|
| 149 |
-
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
| 150 |
-
PARTICULAR PURPOSE. You are solely responsible for determining the
|
| 151 |
-
appropriateness of using or redistributing the Work and assume any
|
| 152 |
-
risks associated with Your exercise of permissions under this License.
|
| 153 |
-
|
| 154 |
-
8. Limitation of Liability. In no event and under no legal theory,
|
| 155 |
-
whether in tort (including negligence), contract, or otherwise,
|
| 156 |
-
unless required by applicable law (such as deliberate and grossly
|
| 157 |
-
negligent acts) or agreed to in writing, shall any Contributor be
|
| 158 |
-
liable to You for damages, including any direct, indirect, special,
|
| 159 |
-
incidental, or consequential damages of any character arising as a
|
| 160 |
-
result of this License or out of the use or inability to use the
|
| 161 |
-
Work (including but not limited to damages for loss of goodwill,
|
| 162 |
-
work stoppage, computer failure or malfunction, or any and all
|
| 163 |
-
other commercial damages or losses), even if such Contributor
|
| 164 |
-
has been advised of the possibility of such damages.
|
| 165 |
-
|
| 166 |
-
9. Accepting Warranty or Additional Liability. While redistributing
|
| 167 |
-
the Work or Derivative Works thereof, You may choose to offer,
|
| 168 |
-
and charge a fee for, acceptance of support, warranty, indemnity,
|
| 169 |
-
or other liability obligations and/or rights consistent with this
|
| 170 |
-
License. However, in accepting such obligations, You may act only
|
| 171 |
-
on Your own behalf and on Your sole responsibility, not on behalf
|
| 172 |
-
of any other Contributor, and only if You agree to indemnify,
|
| 173 |
-
defend, and hold each Contributor harmless for any liability
|
| 174 |
-
incurred by, or claims asserted against, such Contributor by reason
|
| 175 |
-
of your accepting any such warranty or additional liability.
|
| 176 |
-
|
| 177 |
-
END OF TERMS AND CONDITIONS
|
| 178 |
-
|
| 179 |
-
APPENDIX: How to apply the Apache License to your work.
|
| 180 |
-
|
| 181 |
-
To apply the Apache License to your work, attach the following
|
| 182 |
-
boilerplate notice, with the fields enclosed by brackets "[]"
|
| 183 |
-
replaced with your own identifying information. (Don't include
|
| 184 |
-
the brackets!) The text should be enclosed in the appropriate
|
| 185 |
-
comment syntax for the file format. We also recommend that a
|
| 186 |
-
file or class name and description of purpose be included on the
|
| 187 |
-
same "printed page" as the copyright notice for easier
|
| 188 |
-
identification within third-party archives.
|
| 189 |
-
|
| 190 |
-
Copyright [yyyy] [name of copyright owner]
|
| 191 |
-
|
| 192 |
-
Licensed under the Apache License, Version 2.0 (the "License");
|
| 193 |
-
you may not use this file except in compliance with the License.
|
| 194 |
-
You may obtain a copy of the License at
|
| 195 |
-
|
| 196 |
-
http://www.apache.org/licenses/LICENSE-2.0
|
| 197 |
-
|
| 198 |
-
Unless required by applicable law or agreed to in writing, software
|
| 199 |
-
distributed under the License is distributed on an "AS IS" BASIS,
|
| 200 |
-
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 201 |
-
See the License for the specific language governing permissions and
|
| 202 |
-
limitations under the License.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
NOTICE
CHANGED
|
@@ -25,9 +25,9 @@ lookup tables shared by groups of 16 output rows; activations in 16-bit
|
|
| 25 |
floating point) and carries the decoder's 6-bit tables unchanged, packed four
|
| 26 |
codes to three bytes.
|
| 27 |
|
| 28 |
-
These weights are therefore distributed under CC-BY-4.0. The
|
| 29 |
-
|
| 30 |
-
|
| 31 |
|
| 32 |
================================================================================
|
| 33 |
TRAINING DATA
|
|
@@ -49,14 +49,4 @@ RUNTIME DEPENDENCIES
|
|
| 49 |
|
| 50 |
Core ML, Accelerate, AVFoundation ...... Apple system frameworks
|
| 51 |
The encoder runs as Core ML programs; the log-mel front end uses Accelerate.
|
| 52 |
-
The greedy TDT loop is Fermion's
|
| 53 |
-
|
| 54 |
-
================================================================================
|
| 55 |
-
EXPORT / REFERENCE TOOLING (optional, not needed to run the model)
|
| 56 |
-
================================================================================
|
| 57 |
-
|
| 58 |
-
coremltools ................. BSD-3-Clause ........ https://github.com/apple/coremltools
|
| 59 |
-
PyTorch ..................... BSD-3-Clause ........ https://pytorch.org
|
| 60 |
-
transformers ................ Apache-2.0 .......... https://github.com/huggingface/transformers
|
| 61 |
-
NumPy ....................... BSD-3-Clause ........ https://numpy.org
|
| 62 |
-
soundfile ................... BSD-3-Clause ........ https://github.com/bastibe/python-soundfile
|
|
|
|
| 25 |
floating point) and carries the decoder's 6-bit tables unchanged, packed four
|
| 26 |
codes to three bytes.
|
| 27 |
|
| 28 |
+
These weights are therefore distributed under CC-BY-4.0. The runtime in bin/
|
| 29 |
+
(library, command-line tool, framework) is distributed in compiled form only,
|
| 30 |
+
under [[BINARY LICENCE: founder to choose]].
|
| 31 |
|
| 32 |
================================================================================
|
| 33 |
TRAINING DATA
|
|
|
|
| 49 |
|
| 50 |
Core ML, Accelerate, AVFoundation ...... Apple system frameworks
|
| 51 |
The encoder runs as Core ML programs; the log-mel front end uses Accelerate.
|
| 52 |
+
The greedy TDT loop is Fermion's compiled implementation, linked into bin/.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Phonon-2.5.mlpackage/Data/com.apple.CoreML/model.mlmodel
CHANGED
|
@@ -1,3 +1,3 @@
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
-
oid sha256:
|
| 3 |
size 2500522
|
|
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:96f303742669ad4dfe644a667914b285e4ba034200545aa9d38ee626d268f989
|
| 3 |
size 2500522
|
Phonon-2.5.mlpackage/Manifest.json
CHANGED
|
@@ -1,18 +1,18 @@
|
|
| 1 |
{
|
| 2 |
"fileFormatVersion": "1.0.0",
|
| 3 |
"itemInfoEntries": {
|
| 4 |
-
"
|
| 5 |
"author": "com.apple.CoreML",
|
| 6 |
"description": "CoreML Model Weights",
|
| 7 |
"name": "weights",
|
| 8 |
"path": "com.apple.CoreML/weights"
|
| 9 |
},
|
| 10 |
-
"
|
| 11 |
"author": "com.apple.CoreML",
|
| 12 |
"description": "CoreML Model Specification",
|
| 13 |
"name": "model.mlmodel",
|
| 14 |
"path": "com.apple.CoreML/model.mlmodel"
|
| 15 |
}
|
| 16 |
},
|
| 17 |
-
"rootModelIdentifier": "
|
| 18 |
}
|
|
|
|
| 1 |
{
|
| 2 |
"fileFormatVersion": "1.0.0",
|
| 3 |
"itemInfoEntries": {
|
| 4 |
+
"01d7d685-d4aa-4d24-b3f9-258006fd31f6": {
|
| 5 |
"author": "com.apple.CoreML",
|
| 6 |
"description": "CoreML Model Weights",
|
| 7 |
"name": "weights",
|
| 8 |
"path": "com.apple.CoreML/weights"
|
| 9 |
},
|
| 10 |
+
"0f2910fc-1561-4279-9710-56335cedb643": {
|
| 11 |
"author": "com.apple.CoreML",
|
| 12 |
"description": "CoreML Model Specification",
|
| 13 |
"name": "model.mlmodel",
|
| 14 |
"path": "com.apple.CoreML/model.mlmodel"
|
| 15 |
}
|
| 16 |
},
|
| 17 |
+
"rootModelIdentifier": "0f2910fc-1561-4279-9710-56335cedb643"
|
| 18 |
}
|
README.md
CHANGED
|
@@ -45,18 +45,25 @@ metrics:
|
|
| 45 |
|
| 46 |
# Phonon-2.5 Core ML
|
| 47 |
|
| 48 |
-
Phonon-2.5 for the Apple Neural Engine. Phonon-2.5 transcribes 25 European languages
|
| 49 |
-
|
|
|
|
| 50 |
|
| 51 |
-
One 333 MB package holds the encoder's five-value weights
|
| 52 |
-
|
| 53 |
|
| 54 |
## Run it
|
| 55 |
|
| 56 |
-
|
| 57 |
|
| 58 |
-
**
|
| 59 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 60 |
|
| 61 |
```swift
|
| 62 |
import PhononCoreML
|
|
@@ -67,29 +74,53 @@ print(result.text)
|
|
| 67 |
for word in result.words { print(word.start, word.end, word.text) }
|
| 68 |
```
|
| 69 |
|
| 70 |
-
```
|
| 71 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 72 |
```
|
| 73 |
|
| 74 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 75 |
|
| 76 |
```bash
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
python Phonon-2.5-CoreML/phonon_coreml.py Phonon-2.5-CoreML recording.wav
|
| 80 |
```
|
| 81 |
|
| 82 |
-
|
| 83 |
-
first run prepares the package for the Neural Engine once; the compiled copy is kept, so later loads take under a second.
|
| 84 |
-
|
| 85 |
-
Phonon-2.5 also runs through the `fermion` command line on Apple silicon, Linux, Windows and NVIDIA GPUs. See the
|
| 86 |
-
[Phonon-2.5 card](https://huggingface.co/FermionResearch/Phonon-2.5).
|
| 87 |
|
| 88 |
## Long audio and the leading pad
|
| 89 |
|
| 90 |
An utterance of up to 35 seconds is read in one pass by the smallest encoder window that holds it. Longer recordings are cut at
|
| 91 |
-
pauses into windows of up to 15 seconds and their words are joined, so no word is split at a boundary. Pass recordings whole;
|
| 92 |
-
|
| 93 |
|
| 94 |
Every window is encoded with a quarter second of silence in front of it (`leading_pad_s` in `manifest.json`), the runtime default of
|
| 95 |
Phonon-2.5: a recording that starts in the middle of a word is then read from its first word. Word times are reported on the
|
|
@@ -97,30 +128,42 @@ recording's own clock.
|
|
| 97 |
|
| 98 |
## Accuracy
|
| 99 |
|
| 100 |
-
|
|
|
|
|
|
|
| 101 |
|
| 102 |
-
|
| 103 |
-
|
| 104 |
-
|
|
|
|
|
|
|
|
|
|
| 105 |
|
| 106 |
## Speed
|
| 107 |
|
| 108 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 109 |
|
| 110 |
## Files
|
| 111 |
|
| 112 |
| File | Size | Contents |
|
| 113 |
|---|---:|---|
|
| 114 |
-
| `Phonon-2.5.mlpackage` | 333 MB | the encoder for 5, 10, 15 and 35 second windows over one shared weight set (five-value weights stored exactly, 16-bit float activations)
|
| 115 |
| `decoder.bin` | 13 MB | the prediction network, joint and vocabulary |
|
| 116 |
| `manifest.json` | | source checksum, window lengths, the leading pad and the input contract |
|
| 117 |
-
| `
|
| 118 |
-
| `
|
| 119 |
| `ci/` | | three LibriSpeech clips and their transcripts, for a quick check |
|
| 120 |
| `SHA256SUMS` | | a checksum for every file above |
|
| 121 |
|
| 122 |
## Licence
|
| 123 |
|
| 124 |
The weights are released under CC-BY-4.0. They derive from NVIDIA's parakeet-tdt-0.6b-v3, whose tokenizer and output
|
| 125 |
-
conventions (punctuation, casing, numerals) they keep, and `NOTICE` lists the changes. The
|
| 126 |
-
|
|
|
|
| 45 |
|
| 46 |
# Phonon-2.5 Core ML
|
| 47 |
|
| 48 |
+
Phonon-2.5 for the Apple Neural Engine. Phonon-2.5 transcribes 25 European languages with punctuation and casing; the language is not declared, the model hears it. This package carries the Phonon-2.5 weights exactly: on a
|
| 49 |
+
420-utterance gate set its transcripts are identical to the Phonon-2.5 reference engine's on 394, and the rest differ only by
|
| 50 |
+
16-bit float rounding (accuracy below).
|
| 51 |
|
| 52 |
+
One 333 MB package holds the encoder's five-value weights for every utterance up to 35 seconds, over a single set of weights; the
|
| 53 |
+
decoder is a 13 MB table file. Every word carries its start and end time, and the GPU stays free.
|
| 54 |
|
| 55 |
## Run it
|
| 56 |
|
| 57 |
+
macOS 15 or later on Apple silicon. The runtime ships compiled in `bin/`.
|
| 58 |
|
| 59 |
+
**Command line**
|
| 60 |
+
|
| 61 |
+
```bash
|
| 62 |
+
hf download FermionResearch/Phonon-2.5-CoreML --local-dir Phonon-2.5-CoreML
|
| 63 |
+
Phonon-2.5-CoreML/bin/phonon-coreml-cli Phonon-2.5-CoreML recording.wav --words
|
| 64 |
+
```
|
| 65 |
+
|
| 66 |
+
**Swift**: add `bin/PhononCoreML.xcframework.zip` (unzipped) to your target as a binary framework.
|
| 67 |
|
| 68 |
```swift
|
| 69 |
import PhononCoreML
|
|
|
|
| 74 |
for word in result.words { print(word.start, word.end, word.text) }
|
| 75 |
```
|
| 76 |
|
| 77 |
+
**C, Python and other languages**: `bin/libphonon_coreml.dylib` with the C header `bin/include/phonon_coreml.h`. From Python, with
|
| 78 |
+
nothing to install, run from the downloaded folder:
|
| 79 |
+
|
| 80 |
+
```python
|
| 81 |
+
import ctypes, json, sys
|
| 82 |
+
lib = ctypes.CDLL("bin/libphonon_coreml.dylib")
|
| 83 |
+
lib.pcm_open.restype = ctypes.c_void_p
|
| 84 |
+
lib.pcm_open.argtypes = [ctypes.c_char_p, ctypes.c_int32, ctypes.c_int32, ctypes.c_char_p, ctypes.c_int32]
|
| 85 |
+
lib.pcm_transcribe_long.restype = ctypes.c_void_p
|
| 86 |
+
lib.pcm_transcribe_long.argtypes = [ctypes.c_void_p, ctypes.c_char_p, ctypes.c_void_p, ctypes.c_int64, ctypes.c_int32,
|
| 87 |
+
ctypes.c_double, ctypes.c_double, ctypes.c_void_p, ctypes.c_void_p, ctypes.c_void_p,
|
| 88 |
+
ctypes.c_char_p, ctypes.c_int32]
|
| 89 |
+
lib.pcm_free.argtypes = [ctypes.c_void_p]
|
| 90 |
+
err = ctypes.create_string_buffer(1024)
|
| 91 |
+
h = lib.pcm_open(b".", 4, 0, err, len(err)) # this folder; 4 decoder threads; Neural Engine
|
| 92 |
+
if not h: sys.exit(err.value.decode())
|
| 93 |
+
p = lib.pcm_transcribe_long(h, sys.argv[1].encode(), None, 0, 1, 0, 0, None, None, None, err, len(err))
|
| 94 |
+
if not p: sys.exit(err.value.decode())
|
| 95 |
+
result = json.loads(ctypes.string_at(p).decode()); lib.pcm_free(p)
|
| 96 |
+
print(result["text"])
|
| 97 |
+
for w in result["words"]: print(w["start"], w["end"], w["text"])
|
| 98 |
```
|
| 99 |
|
| 100 |
+
All three take 16 kHz audio of any length (stereo is mixed down). The first run prepares the package for the Neural Engine once (about 50 seconds before the first transcript and about 3 minutes for all four windows on an M5 MacBook Air); the
|
| 101 |
+
prepared copy is kept, so later loads take about a second.
|
| 102 |
+
|
| 103 |
+
Phonon-2.5 also runs through the `fermion` command line on Apple silicon, Linux, Windows and NVIDIA GPUs. See the
|
| 104 |
+
[Phonon-2.5 card](https://huggingface.co/FermionResearch/Phonon-2.5).
|
| 105 |
+
|
| 106 |
+
## Smaller download
|
| 107 |
+
|
| 108 |
+
If the five-value container of Phonon-2.5 (`model.fermion`, the file the `fermion` runtime keeps) is already on the machine, the
|
| 109 |
+
package can be built from it instead of downloaded: fetch only the small files (≈39 MB) and expand. The result is checked byte for
|
| 110 |
+
byte against the published package before it is written.
|
| 111 |
|
| 112 |
```bash
|
| 113 |
+
hf download FermionResearch/Phonon-2.5-CoreML --local-dir Phonon-2.5-CoreML --exclude "Phonon-2.5.mlpackage/*"
|
| 114 |
+
Phonon-2.5-CoreML/bin/phonon-coreml-cli --expand model.fermion Phonon-2.5-CoreML/kit Phonon-2.5-CoreML/Phonon-2.5.mlpackage
|
|
|
|
| 115 |
```
|
| 116 |
|
| 117 |
+
Expansion takes about 2 seconds. From C: `pcm_expand(container, kit_dir, out_package, 0, err, errlen)`.
|
|
|
|
|
|
|
|
|
|
|
|
|
| 118 |
|
| 119 |
## Long audio and the leading pad
|
| 120 |
|
| 121 |
An utterance of up to 35 seconds is read in one pass by the smallest encoder window that holds it. Longer recordings are cut at
|
| 122 |
+
pauses into windows of up to 15 seconds and their words are joined, so no word is split at a boundary. Pass recordings whole; the
|
| 123 |
+
runtime does the cutting.
|
| 124 |
|
| 125 |
Every window is encoded with a quarter second of silence in front of it (`leading_pad_s` in `manifest.json`), the runtime default of
|
| 126 |
Phonon-2.5: a recording that starts in the middle of a word is then read from its first word. Word times are reported on the
|
|
|
|
| 128 |
|
| 129 |
## Accuracy
|
| 130 |
|
| 131 |
+
Word error rate, %, lower is better: this package on the Neural Engine beside the Phonon-2.5 reference engine on the same utterances.
|
| 132 |
+
English sets are scored with the Open ASR Leaderboard's own code; FLEURS with a case- and punctuation-insensitive word error rate.
|
| 133 |
+
The [Phonon-2.5 card](https://huggingface.co/FermionResearch/Phonon-2.5) lists the full-set accuracy in every language.
|
| 134 |
|
| 135 |
+
| Set | Core ML, Neural Engine | Reference engine |
|
| 136 |
+
|---|---:|---:|
|
| 137 |
+
| Open ASR Leaderboard English sets (280-utterance sample of the seven sets) | 6.18 | 6.07 |
|
| 138 |
+
| LibriSpeech test-clean (40 utterances) | 2.07 | 2.07 |
|
| 139 |
+
| FLEURS, 8 languages (96 utterances) | 7.41 | 7.32 |
|
| 140 |
+
| One hour of LibriSpeech read as one file | 1.11 | |
|
| 141 |
|
| 142 |
## Speed
|
| 143 |
|
| 144 |
+
M5 MacBook Air, Neural Engine, package loaded:
|
| 145 |
+
|
| 146 |
+
| | |
|
| 147 |
+
|---|---|
|
| 148 |
+
| Long audio | One hour of audio in 6 seconds (608× real time) |
|
| 149 |
+
| A 3 to 5 second utterance | 9 ms |
|
| 150 |
+
| Later loads (all four windows) | about a second |
|
| 151 |
+
| Memory while reading an hour | 0.14 GB |
|
| 152 |
|
| 153 |
## Files
|
| 154 |
|
| 155 |
| File | Size | Contents |
|
| 156 |
|---|---:|---|
|
| 157 |
+
| `Phonon-2.5.mlpackage` | 333 MB | the encoder for 5, 10, 15 and 35 second windows over one shared weight set (five-value weights stored exactly, 16-bit float activations) |
|
| 158 |
| `decoder.bin` | 13 MB | the prediction network, joint and vocabulary |
|
| 159 |
| `manifest.json` | | source checksum, window lengths, the leading pad and the input contract |
|
| 160 |
+
| `kit/` | 26 MB | what `--expand` needs to build `Phonon-2.5.mlpackage` from `model.fermion` |
|
| 161 |
+
| `bin/` | 1 MB | `phonon-coreml-cli`, `libphonon_coreml.dylib` + `include/phonon_coreml.h`, `PhononCoreML.xcframework.zip` (macOS, arm64) |
|
| 162 |
| `ci/` | | three LibriSpeech clips and their transcripts, for a quick check |
|
| 163 |
| `SHA256SUMS` | | a checksum for every file above |
|
| 164 |
|
| 165 |
## Licence
|
| 166 |
|
| 167 |
The weights are released under CC-BY-4.0. They derive from NVIDIA's parakeet-tdt-0.6b-v3, whose tokenizer and output
|
| 168 |
+
conventions (punctuation, casing, numerals) they keep, and `NOTICE` lists the changes. The runtime in `bin/` is distributed in
|
| 169 |
+
compiled form under [[BINARY LICENCE: founder to choose]].
|
SHA256SUMS
CHANGED
|
@@ -1,19 +1,20 @@
|
|
| 1 |
-
|
|
|
|
|
|
|
|
|
|
| 2 |
30885601173f96b0d8ddd020dc959b055c6c1582b85a33e3fcab8c4b08ed94c2 ./ci/clips/1089-134686-0000.flac
|
| 3 |
66277a3fa3df407261dc2a3ce685a7ceef19999ab0c10531bee5257cb64cb59d ./ci/clips/1089-134686-0002.flac
|
| 4 |
c65e16be3ef92c11a31a9c2c4c570542eb2ed66153150a7c4cca00c01b30a4e2 ./ci/clips/1089-134686-0011.flac
|
| 5 |
1daf8af0dfdf36897223657b6f5a619c1fa28359a4c9ef1456b27a1751b35aa0 ./ci/expected_texts.json
|
| 6 |
2b640691ec5cd9ad46c9e1a3ba461d1ce6b3063f1b173ea7cc9168966f0079ed ./decoder.bin
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
|
|
|
| 10 |
9ba9550ad48438d0836ddab3da480b3b69ffa0aac7b7878b5a0039e7ab429411 ./LICENSE-WEIGHTS-CC-BY-4.0.txt
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
03c358a1876c1d72abb2b4d4479a92a2da487282bcddc3c7d85d692e0771ca5e ./Phonon-2.5.mlpackage/Data/com.apple.CoreML/model.mlmodel
|
| 15 |
aa651cbc1a60abf2b14820d1d45dc4282ed71a6a542da24ac143d5a2cc7ac07f ./Phonon-2.5.mlpackage/Data/com.apple.CoreML/weights/weight.bin
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
19b1e4d4c5da2b1e6d24841797aaa682e75c1d8fc050681bc6927cb0453cf9f1 ./README.md
|
| 19 |
-
37aa36169e4d71ba8007c0bf3af91757edc66f503cb18c1ed388e0457650b074 ./segmenter_np.py
|
|
|
|
| 1 |
+
d5a7c35fb9968bebe2a57ab1e90ab428ebb4319d483d990cf1934adc53f2895c ./bin/include/phonon_coreml.h
|
| 2 |
+
6ecf2e3a0a7cdd50967dbefb7b77d02b6d060db7f90e77a717312d7b2fdc935d ./bin/libphonon_coreml.dylib
|
| 3 |
+
a2b89bc8ca8507e621df51efe7a9dee0b4c44eb2e4903e2b49baa3ee9134f450 ./bin/phonon-coreml-cli
|
| 4 |
+
4bb15a5a068441c855aa5be018f790af48e6f70a880bb60c689f4fba299ad4c8 ./bin/PhononCoreML.xcframework.zip
|
| 5 |
30885601173f96b0d8ddd020dc959b055c6c1582b85a33e3fcab8c4b08ed94c2 ./ci/clips/1089-134686-0000.flac
|
| 6 |
66277a3fa3df407261dc2a3ce685a7ceef19999ab0c10531bee5257cb64cb59d ./ci/clips/1089-134686-0002.flac
|
| 7 |
c65e16be3ef92c11a31a9c2c4c570542eb2ed66153150a7c4cca00c01b30a4e2 ./ci/clips/1089-134686-0011.flac
|
| 8 |
1daf8af0dfdf36897223657b6f5a619c1fa28359a4c9ef1456b27a1751b35aa0 ./ci/expected_texts.json
|
| 9 |
2b640691ec5cd9ad46c9e1a3ba461d1ce6b3063f1b173ea7cc9168966f0079ed ./decoder.bin
|
| 10 |
+
8aa0eb738296cd3e0e060f8cdd5e431d37553fade23a6b4ff773b93ebb2a5a74 ./kit/kit.json
|
| 11 |
+
49016d3d06aa3c4aa1d9b9bf1af20d1d90aa1f6f12182c3cd24be37735a73c24 ./kit/Manifest.json
|
| 12 |
+
96f303742669ad4dfe644a667914b285e4ba034200545aa9d38ee626d268f989 ./kit/model.mlmodel
|
| 13 |
+
87db2686c07753743b1e168d4c9ac6a489553d2173cf1a297f96fb1c08a88f2f ./kit/skeleton.deflate
|
| 14 |
9ba9550ad48438d0836ddab3da480b3b69ffa0aac7b7878b5a0039e7ab429411 ./LICENSE-WEIGHTS-CC-BY-4.0.txt
|
| 15 |
+
1292704b9d4440e5128b6b112e46f1203502650f7d1aad5df24e9264539813d5 ./manifest.json
|
| 16 |
+
ef62807ef8a116b269d641fada22329992d29ad5eff9755d282b8501490143f5 ./NOTICE
|
| 17 |
+
96f303742669ad4dfe644a667914b285e4ba034200545aa9d38ee626d268f989 ./Phonon-2.5.mlpackage/Data/com.apple.CoreML/model.mlmodel
|
|
|
|
| 18 |
aa651cbc1a60abf2b14820d1d45dc4282ed71a6a542da24ac143d5a2cc7ac07f ./Phonon-2.5.mlpackage/Data/com.apple.CoreML/weights/weight.bin
|
| 19 |
+
49016d3d06aa3c4aa1d9b9bf1af20d1d90aa1f6f12182c3cd24be37735a73c24 ./Phonon-2.5.mlpackage/Manifest.json
|
| 20 |
+
d31da9b7dca1d6fb39fb8f760390749319efebb8a9bf551d51890fb3ba1a7aec ./README.md
|
|
|
|
|
|
phonon-coreml-src.tgz → bin/PhononCoreML.xcframework.zip
RENAMED
|
@@ -1,3 +1,3 @@
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
-
oid sha256:
|
| 3 |
-
size
|
|
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:4bb15a5a068441c855aa5be018f790af48e6f70a880bb60c689f4fba299ad4c8
|
| 3 |
+
size 217606
|
bin/include/phonon_coreml.h
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/* phonon_coreml.h -- C ABI of libphonon_coreml.dylib (pcm_*, ABI 1). Phonon Core ML runtime, macOS arm64.
|
| 2 |
+
* Strings are UTF-8, NUL-terminated. err/errlen: optional buffer for the reason of a failure (truncated to errlen-1 bytes).
|
| 3 |
+
* *_json(h, buf, len): writes into buf when len > 0 and returns the bytes needed (incl. NUL); call with len 0 to size the buffer.
|
| 4 |
+
* Every call is thread-safe; long calls (open = ANE compile on the first run, decode, expand) hold no host lock. */
|
| 5 |
+
#ifndef PHONON_COREML_H
|
| 6 |
+
#define PHONON_COREML_H
|
| 7 |
+
#include <stdint.h>
|
| 8 |
+
#ifdef __cplusplus
|
| 9 |
+
extern "C" {
|
| 10 |
+
#endif
|
| 11 |
+
|
| 12 |
+
typedef void *pcm_handle;
|
| 13 |
+
typedef void (*pcm_progress_fn)(int32_t done, int32_t total, void *ctx);
|
| 14 |
+
|
| 15 |
+
int32_t pcm_abi_version(void); /* 1 */
|
| 16 |
+
/* 1 = the first pcm_open will compile, 0 = cached, -1 = no readable manifest.json in bundle_dir */
|
| 17 |
+
int32_t pcm_needs_compile(const char *bundle_dir);
|
| 18 |
+
/* compute: 0 = CPU + Neural Engine (default), 1 = all, 2 = CPU only, 3 = CPU + GPU. Returns NULL on failure. */
|
| 19 |
+
pcm_handle pcm_open(const char *bundle_dir, int32_t decoders, int32_t compute, char *err, int32_t errlen);
|
| 20 |
+
int32_t pcm_info_json(pcm_handle h, char *buf, int32_t len);
|
| 21 |
+
int32_t pcm_vocab_json(pcm_handle h, char *buf, int32_t len);
|
| 22 |
+
/* One window of 16 kHz mono float32 (n <= largest_window_s * 16000). bias_table == NULL -> unbiased decode.
|
| 23 |
+
* Writes up to cap tokens (token id, frame, duration); timing[4] = encode s, decode s, function that ran (s; 0 = silence), encoder frames.
|
| 24 |
+
* Returns the token count (may exceed cap: call again with a larger cap), or -1. */
|
| 25 |
+
int32_t pcm_decode(pcm_handle h, const float *samples, int32_t n,
|
| 26 |
+
int32_t bias_s, int32_t bias_k, const int32_t *bias_table, const int32_t *bias_toks,
|
| 27 |
+
const int32_t *bias_col, int32_t ncol, const int32_t *bias_depth, float lam,
|
| 28 |
+
int32_t *out_tok, int32_t *out_frame, int32_t *out_dur, int32_t cap, double *timing,
|
| 29 |
+
char *err, int32_t errlen);
|
| 30 |
+
void pcm_close(pcm_handle h);
|
| 31 |
+
int32_t pcm_preload_all(pcm_handle h, char *err, int32_t errlen); /* 0 or -1 */
|
| 32 |
+
void pcm_warm(pcm_handle h, double seconds); /* async key-down warm-up */
|
| 33 |
+
int32_t pcm_wait_all(pcm_handle h); /* blocks until every function load finished; returns loaded count */
|
| 34 |
+
int32_t pcm_loaded_json(pcm_handle h, char *buf, int32_t len);
|
| 35 |
+
/* Long audio: path (16 kHz file, streamed) or samples/n. Returns malloc'd JSON (release with pcm_free) or NULL. *cancel != 0 stops. */
|
| 36 |
+
char *pcm_transcribe_long(pcm_handle h, const char *path, const float *samples, int64_t n, int32_t rescue,
|
| 37 |
+
double window_s, double band_min_s, pcm_progress_fn progress, void *ctx,
|
| 38 |
+
const int32_t *cancel, char *err, int32_t errlen);
|
| 39 |
+
/* First-run package build from the five-value container + the bundle's kit/ directory -> out_package (an .mlpackage dir),
|
| 40 |
+
* byte-identical to the shipped package (sha256 checked; nothing written on a mismatch). threads <= 0 -> 6. Returns 0 or -1.
|
| 41 |
+
* Additive to ABI 1: probe with dlsym(handle, "pcm_expand"). */
|
| 42 |
+
int32_t pcm_expand(const char *container, const char *kit_dir, const char *out_package, int32_t threads, char *err, int32_t errlen);
|
| 43 |
+
void pcm_free(char *p);
|
| 44 |
+
|
| 45 |
+
#ifdef __cplusplus
|
| 46 |
+
}
|
| 47 |
+
#endif
|
| 48 |
+
#endif
|
libphonon_tdt.dylib → bin/libphonon_coreml.dylib
RENAMED
|
@@ -1,3 +1,3 @@
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
-
oid sha256:
|
| 3 |
-
size
|
|
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:6ecf2e3a0a7cdd50967dbefb7b77d02b6d060db7f90e77a717312d7b2fdc935d
|
| 3 |
+
size 501432
|
bin/phonon-coreml-cli
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:a2b89bc8ca8507e621df51efe7a9dee0b4c44eb2e4903e2b49baa3ee9134f450
|
| 3 |
+
size 535360
|
build.json
DELETED
|
@@ -1,19 +0,0 @@
|
|
| 1 |
-
{
|
| 2 |
-
"bundle": "phonon-2.5",
|
| 3 |
-
"functions": [
|
| 4 |
-
5,
|
| 5 |
-
10,
|
| 6 |
-
15,
|
| 7 |
-
35
|
| 8 |
-
],
|
| 9 |
-
"merge_s": 56.9,
|
| 10 |
-
"package_mb": 332.62,
|
| 11 |
-
"decoder_mb": 0.0,
|
| 12 |
-
"bundle_mb": 345.92,
|
| 13 |
-
"inputs_mb": {
|
| 14 |
-
"5": 318.72,
|
| 15 |
-
"10": 318.72,
|
| 16 |
-
"15": 318.71,
|
| 17 |
-
"35": 312.23
|
| 18 |
-
}
|
| 19 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
frontend.py
DELETED
|
@@ -1,39 +0,0 @@
|
|
| 1 |
-
"""Log-mel front end = the pip CPU engine's arithmetic (HF ParakeetFeatureExtractor): pre-emphasis 0.97, 512-pt STFT hop 160 win 400
|
| 2 |
-
Hann (centre, zero pad), power, slaney mel 128, log(x + 2^-24), per-feature normalisation over the true length. numpy only."""
|
| 3 |
-
import numpy as np
|
| 4 |
-
N_FFT, HOP, WIN, N_MELS, PREEMPH, SR = 512, 160, 400, 128, 0.97, 16000
|
| 5 |
-
LOG_GUARD = 2.0 ** -24
|
| 6 |
-
|
| 7 |
-
def _hz_to_mel(f):
|
| 8 |
-
f = np.asarray(f, dtype=np.float64); f_sp = 200.0 / 3; min_log_hz = 1000.0; min_log_mel = min_log_hz / f_sp; logstep = np.log(6.4) / 27.0
|
| 9 |
-
return np.where(f >= min_log_hz, min_log_mel + np.log(np.maximum(f, 1e-30) / min_log_hz) / logstep, f / f_sp)
|
| 10 |
-
def _mel_to_hz(m):
|
| 11 |
-
m = np.asarray(m, dtype=np.float64); f_sp = 200.0 / 3; min_log_hz = 1000.0; min_log_mel = min_log_hz / f_sp; logstep = np.log(6.4) / 27.0
|
| 12 |
-
return np.where(m >= min_log_mel, min_log_hz * np.exp(logstep * (m - min_log_mel)), f_sp * m)
|
| 13 |
-
def mel_filters(sr=SR, n_fft=N_FFT, n_mels=N_MELS):
|
| 14 |
-
fftfreqs = np.linspace(0, sr / 2, 1 + n_fft // 2); mel_f = _mel_to_hz(np.linspace(_hz_to_mel(0.0), _hz_to_mel(sr / 2), n_mels + 2))
|
| 15 |
-
fdiff = np.diff(mel_f); ramps = np.subtract.outer(mel_f, fftfreqs); w = np.zeros((n_mels, 1 + n_fft // 2))
|
| 16 |
-
for i in range(n_mels):
|
| 17 |
-
lower = -ramps[i] / fdiff[i]; upper = ramps[i + 2] / fdiff[i + 1]; w[i] = np.maximum(0, np.minimum(lower, upper))
|
| 18 |
-
w *= (2.0 / (mel_f[2:n_mels + 2] - mel_f[:n_mels]))[:, None]
|
| 19 |
-
return w.astype(np.float32)
|
| 20 |
-
_MELF = mel_filters()
|
| 21 |
-
_WINDOW = np.hanning(WIN).astype(np.float32) # torch.hann_window(400, periodic=False) = HF ParakeetFeatureExtractor
|
| 22 |
-
_L = (N_FFT - WIN) // 2
|
| 23 |
-
_WIN512 = np.pad(_WINDOW, (_L, N_FFT - WIN - _L)) # torch.stft centres a short window inside n_fft
|
| 24 |
-
|
| 25 |
-
def log_mel(wave, rule="hf"):
|
| 26 |
-
"""wave float32 [n] 16 kHz -> feats float32 [128, T] normalised, T = n//160 (HF: features_lengths = n // hop; the STFT's
|
| 27 |
-
extra last frame is dropped, exactly as the HF attention mask drops it)."""
|
| 28 |
-
x = np.asarray(wave, dtype=np.float32); n = len(x)
|
| 29 |
-
x = np.concatenate([x[:1], x[1:] - PREEMPH * x[:-1]])
|
| 30 |
-
x = np.pad(x, (N_FFT // 2, N_FFT // 2)) # centre, constant (zero) pad as torch.stft pad_mode="constant"
|
| 31 |
-
T = (1 + n // HOP) if rule == "pip" else n // HOP
|
| 32 |
-
idx = np.arange(N_FFT)[None, :] + HOP * np.arange(T)[:, None]
|
| 33 |
-
frames = x[idx] * _WIN512
|
| 34 |
-
spec = np.fft.rfft(frames.astype(np.float64), axis=1)
|
| 35 |
-
power = (spec.real ** 2 + spec.imag ** 2).astype(np.float32) # [T, 257]
|
| 36 |
-
mel = np.log(power @ _MELF.T + LOG_GUARD) # [T, 128]
|
| 37 |
-
mean = mel.mean(0, keepdims=True); var = ((mel - mean) ** 2).sum(0) / (T - 1)
|
| 38 |
-
mel = (mel - mean) / (np.sqrt(var) + 1e-5)
|
| 39 |
-
return mel.T.astype(np.float32)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
kit/Manifest.json
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"fileFormatVersion": "1.0.0",
|
| 3 |
+
"itemInfoEntries": {
|
| 4 |
+
"01d7d685-d4aa-4d24-b3f9-258006fd31f6": {
|
| 5 |
+
"author": "com.apple.CoreML",
|
| 6 |
+
"description": "CoreML Model Weights",
|
| 7 |
+
"name": "weights",
|
| 8 |
+
"path": "com.apple.CoreML/weights"
|
| 9 |
+
},
|
| 10 |
+
"0f2910fc-1561-4279-9710-56335cedb643": {
|
| 11 |
+
"author": "com.apple.CoreML",
|
| 12 |
+
"description": "CoreML Model Specification",
|
| 13 |
+
"name": "model.mlmodel",
|
| 14 |
+
"path": "com.apple.CoreML/model.mlmodel"
|
| 15 |
+
}
|
| 16 |
+
},
|
| 17 |
+
"rootModelIdentifier": "0f2910fc-1561-4279-9710-56335cedb643"
|
| 18 |
+
}
|
kit/kit.json
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
kit/model.mlmodel
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:96f303742669ad4dfe644a667914b285e4ba034200545aa9d38ee626d268f989
|
| 3 |
+
size 2500522
|
kit/skeleton.deflate
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:87db2686c07753743b1e168d4c9ac6a489553d2173cf1a297f96fb1c08a88f2f
|
| 3 |
+
size 22469095
|
manifest.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
| 1 |
{
|
| 2 |
"name": "Phonon-2.5 Core ML",
|
| 3 |
"model": "phonon-2.5",
|
| 4 |
-
"version": "3.
|
| 5 |
"container_sha256": "17cb62d08e751a41819eb779db089aa7ac4eb2bab433ba5c2991d8cbd3cfefb9",
|
| 6 |
"multifunction": "Phonon-2.5.mlpackage",
|
| 7 |
"functions_s": [
|
|
@@ -26,7 +26,10 @@
|
|
| 26 |
"single_shot_max_s": 35,
|
| 27 |
"residual_scale": 64.0,
|
| 28 |
"leading_pad_s": 0.25,
|
| 29 |
-
"
|
|
|
|
|
|
|
|
|
|
| 30 |
"inputs": "mel [1,128,T] normalised log-mel, zero-padded to the function's length; m1/m2/m3 frame masks after each stride-2 conv; kmask additive key mask over encoder frames (0 / -1e4); pos [1,2*T3-1,1024] relative-position table (functions with pos_input only)",
|
| 31 |
"output": "enc [1,T3,640] = encoder output after the projector; greedy TDT (durations 0-4, blank 8192, at most 10 symbols per frame) with decoder.bin",
|
| 32 |
"decoder_bin": "prediction network, joint and vocabulary: 6-bit tables packed 4 codes per 3 bytes (format v2) with 16-bit float row scales",
|
|
|
|
| 1 |
{
|
| 2 |
"name": "Phonon-2.5 Core ML",
|
| 3 |
"model": "phonon-2.5",
|
| 4 |
+
"version": "3.2",
|
| 5 |
"container_sha256": "17cb62d08e751a41819eb779db089aa7ac4eb2bab433ba5c2991d8cbd3cfefb9",
|
| 6 |
"multifunction": "Phonon-2.5.mlpackage",
|
| 7 |
"functions_s": [
|
|
|
|
| 26 |
"single_shot_max_s": 35,
|
| 27 |
"residual_scale": 64.0,
|
| 28 |
"leading_pad_s": 0.25,
|
| 29 |
+
"layout": "sparse-g16-6b",
|
| 30 |
+
"expander_kit": "kit",
|
| 31 |
+
"final_sigma": true,
|
| 32 |
+
"weights": "exact five-value palettes (sparse-g16-6b), 16-bit float activations; one weight blob shared by all functions; relative keys constant-folded for the 15 s function (and any longer const function) and sliced from the 15 s table for the 5 s and 10 s functions",
|
| 33 |
"inputs": "mel [1,128,T] normalised log-mel, zero-padded to the function's length; m1/m2/m3 frame masks after each stride-2 conv; kmask additive key mask over encoder frames (0 / -1e4); pos [1,2*T3-1,1024] relative-position table (functions with pos_input only)",
|
| 34 |
"output": "enc [1,T3,640] = encoder output after the projector; greedy TDT (durations 0-4, blank 8192, at most 10 symbols per frame) with decoder.bin",
|
| 35 |
"decoder_bin": "prediction network, joint and vocabulary: 6-bit tables packed 4 codes per 3 bytes (format v2) with 16-bit float row scales",
|
phonon_coreml.py
DELETED
|
@@ -1,267 +0,0 @@
|
|
| 1 |
-
#!/usr/bin/env python3
|
| 2 |
-
"""Phonon-2 / Phonon-2.5 Core ML reference runner (Python example): wav in, text + words out. Needs coremltools, numpy, soundfile (no torch).
|
| 3 |
-
|
| 4 |
-
python phonon_coreml.py <bundle-dir> file.wav [more.wav ...] [--json out.json] [--reference] [--frames hf|pip]
|
| 5 |
-
|
| 6 |
-
bundle-dir holds manifest.json, decoder.bin and Phonon-2.mlpackage (encoder functions enc_5s ... enc_35s over one weight blob; each window
|
| 7 |
-
runs the smallest function that holds it). The encoder runs on
|
| 8 |
-
the Neural Engine; the decoder runs on the CPU through the compiled library that the Swift package also uses (libphonon_tdt.dylib, next to this file). Audio up to
|
| 9 |
-
35 s is one window; longer audio is cut into windows of at most 15 s at quiet points, with a 2 s overlap and a word-level stitch when
|
| 10 |
-
there is no quiet point. `words` is one {text, start, end} per word in seconds from the start of the file, the pip engine's shape."""
|
| 11 |
-
import json, os, sys, time
|
| 12 |
-
import numpy as np
|
| 13 |
-
HERE = os.path.dirname(os.path.abspath(__file__)); sys.path.insert(0, HERE)
|
| 14 |
-
from frontend import log_mel, HOP
|
| 15 |
-
from segmenter_np import plan as reference_plan, is_silent
|
| 16 |
-
|
| 17 |
-
FRAME_S = 0.08; SR = 16000
|
| 18 |
-
|
| 19 |
-
def _load_library():
|
| 20 |
-
import ctypes
|
| 21 |
-
path = os.path.join(HERE, "libphonon_tdt.dylib")
|
| 22 |
-
try: lib = ctypes.CDLL(path)
|
| 23 |
-
except OSError as e: raise SystemExit(f"error: could not load {path} ({e})")
|
| 24 |
-
P, I = ctypes.c_void_p, ctypes.c_int
|
| 25 |
-
lib.phonon2_tdt_create.restype = P; lib.phonon2_tdt_create.argtypes = [I, I, I, I, I, P, I, I] + [P] * 20
|
| 26 |
-
lib.phonon2_tdt_decode_timed.restype = I; lib.phonon2_tdt_decode_timed.argtypes = [P, P, I, P, P, P, I]
|
| 27 |
-
lib.phonon2_tdt_destroy.restype = None; lib.phonon2_tdt_destroy.argtypes = [P]
|
| 28 |
-
return lib
|
| 29 |
-
|
| 30 |
-
class DecoderBin:
|
| 31 |
-
"""decoder.bin (prediction network, joint, vocabulary) and the greedy decoder from the compiled library the Swift package uses."""
|
| 32 |
-
def __init__(self, path):
|
| 33 |
-
d = open(path, "rb").read(); hl = int.from_bytes(d[:4], "little"); self.h = json.loads(d[4:4 + hl]); blob = d[4 + hl:]
|
| 34 |
-
A = {}
|
| 35 |
-
for a in self.h["arrays"]:
|
| 36 |
-
n = int(np.prod(a["shape"]))
|
| 37 |
-
if a["dtype"] == "int6p":
|
| 38 |
-
b = np.frombuffer(blob, np.uint8, count=a["bytes"], offset=a["offset"]).reshape(-1, 3).astype(np.uint32); w = b[:, 0] | (b[:, 1] << 8) | (b[:, 2] << 16)
|
| 39 |
-
u = np.stack([(w >> (6 * k)) & 63 for k in range(4)], 1).reshape(-1)[:n].astype(np.int16); A[a["name"]] = np.where(u >= 32, u - 64, u).astype(np.int8).reshape(a["shape"])
|
| 40 |
-
else: A[a["name"]] = np.frombuffer(blob, dtype=np.dtype(a["dtype"]), count=n, offset=a["offset"]).reshape(a["shape"])
|
| 41 |
-
self._keep = {k: np.ascontiguousarray(v) for k, v in A.items()}
|
| 42 |
-
self.lib = _load_library(); h = self.h
|
| 43 |
-
def q(n): return self._keep[n + ".q"].ctypes.data
|
| 44 |
-
def f16(n): return self._keep[n].view(np.uint16).ctypes.data
|
| 45 |
-
args = [q("decoder.embedding.weight"), f16("decoder.embedding.weight.scale")]
|
| 46 |
-
for l in range(2):
|
| 47 |
-
for kind in ("ih", "hh"):
|
| 48 |
-
w = f"decoder.lstm.weight_{kind}_l{l}"; args += [q(w), f16(w + ".scale"), f16(f"decoder.lstm.bias_{kind}_l{l}")]
|
| 49 |
-
args += [q("decoder.decoder_projector.weight"), f16("decoder.decoder_projector.weight.scale"), f16("decoder.decoder_projector.bias")]
|
| 50 |
-
args += [q("joint.head.weight"), f16("joint.head.weight.scale"), f16("joint.head.bias")]
|
| 51 |
-
self._durs = np.ascontiguousarray(np.array(h["durations"], np.int32))
|
| 52 |
-
self.handle = self.lib.phonon2_tdt_create(h["V"], h["E"], h["H"], h["nhead"], len(h["durations"]), self._durs.ctypes.data, h["blank"], h["max_symbols"], *args)
|
| 53 |
-
if not self.handle: raise RuntimeError("decoder tables could not be loaded")
|
| 54 |
-
self.vocab = h["vocab"]; self.container_sha256 = h["container_sha256"]
|
| 55 |
-
def __del__(self):
|
| 56 |
-
if getattr(self, "handle", None): self.lib.phonon2_tdt_destroy(self.handle); self.handle = None
|
| 57 |
-
def decode(self, enc):
|
| 58 |
-
"""-> [(token, frame, duration)]: greedy decode of one window's encoder output (frames x 640)."""
|
| 59 |
-
enc = np.ascontiguousarray(enc, np.float32); T = enc.shape[0]; cap = max(64, 12 * T)
|
| 60 |
-
out, fr, du = (np.zeros(cap, np.int32) for _ in range(3))
|
| 61 |
-
n = self.lib.phonon2_tdt_decode_timed(self.handle, enc.ctypes.data, T, out.ctypes.data, fr.ctypes.data, du.ctypes.data, cap)
|
| 62 |
-
return [(int(out[i]), int(fr[i]), int(du[i])) for i in range(n)]
|
| 63 |
-
def pieces(self, toks):
|
| 64 |
-
"""(piece with the word marker as a leading space, start s, duration s) per token, specials dropped."""
|
| 65 |
-
out = []
|
| 66 |
-
for tok, fr, du in toks:
|
| 67 |
-
p = self.vocab[tok]
|
| 68 |
-
if (p.startswith("<|") and p.endswith("|>")) or p in ("<unk>", "<pad>"): continue
|
| 69 |
-
out.append((p.replace("▁", " "), fr * FRAME_S, du * FRAME_S))
|
| 70 |
-
return out
|
| 71 |
-
|
| 72 |
-
def _is_punct(s): return bool(s) and not any(ch.isalnum() for ch in s)
|
| 73 |
-
def words_from_tokens(tokens, offset=0.0, limit=None):
|
| 74 |
-
"""pip rule (fermion._speech.segment.words_from_tokens)."""
|
| 75 |
-
words = []; cur = []
|
| 76 |
-
def flush():
|
| 77 |
-
if not cur: return
|
| 78 |
-
text = "".join(t[0] for t in cur).strip()
|
| 79 |
-
if text:
|
| 80 |
-
end = cur[-1][1] + cur[-1][2]
|
| 81 |
-
if limit is not None: end = min(end, limit)
|
| 82 |
-
words.append({"text": text, "start": round(cur[0][1] + offset, 3), "end": round(max(end, cur[0][1]) + offset, 3)})
|
| 83 |
-
cur.clear()
|
| 84 |
-
for piece, start, dur in tokens:
|
| 85 |
-
if piece.startswith(" ") and cur and (not piece.strip() or not _is_punct(piece.strip())): flush()
|
| 86 |
-
cur.append((piece, start, dur))
|
| 87 |
-
flush(); return words
|
| 88 |
-
|
| 89 |
-
def stitch(kept, incoming, split, jitter=0.25):
|
| 90 |
-
"""word-level stitch at an overlapped boundary (see Words.swift)."""
|
| 91 |
-
while kept and kept[-1]["start"] >= split: kept.pop()
|
| 92 |
-
seam = [w for w in kept if w["end"] > split - jitter - 0.5]
|
| 93 |
-
for w in incoming:
|
| 94 |
-
if w["start"] < split - jitter: continue
|
| 95 |
-
dup = False
|
| 96 |
-
for a in seam:
|
| 97 |
-
ov = min(a["end"], w["end"]) - max(a["start"], w["start"])
|
| 98 |
-
if ov <= 1e-9: continue
|
| 99 |
-
if a["text"].lower() == w["text"].lower() or ov > 0.5 * min(a["end"] - a["start"], w["end"] - w["start"]): dup = True; break
|
| 100 |
-
if not dup: kept.append(w)
|
| 101 |
-
|
| 102 |
-
def plan_windows(audio, window_s=15.0, band_min_s=10.0, overlap_s=2.0, single_shot_max_s=35.0):
|
| 103 |
-
"""-> [(start, end, split_or_None)] samples; the Swift Windower, line for line."""
|
| 104 |
-
n = audio.size
|
| 105 |
-
if n <= int(single_shot_max_s * SR): return [(0, n, None)]
|
| 106 |
-
block = int(0.05 * SR); nb = -(-n // block); padded = np.zeros(nb * block, np.float32); padded[:n] = audio
|
| 107 |
-
rms = np.sqrt(np.mean(padded.reshape(nb, block) ** 2, axis=1))
|
| 108 |
-
W = int(window_s * SR) - 400; overlap = int(overlap_s * SR); out = []; start = 0; split = None
|
| 109 |
-
while n - start > W:
|
| 110 |
-
lo, hi = start + int(band_min_s * SR), start + W
|
| 111 |
-
b0, b1, bs = -(-lo // block), min(hi // block, nb), start // block
|
| 112 |
-
cut = None
|
| 113 |
-
if b0 < b1 and b1 > bs:
|
| 114 |
-
gate = max(0.004, 0.18 * float(rms[bs:b1].max())); best = None; i = b0
|
| 115 |
-
while i < b1:
|
| 116 |
-
if rms[i] > gate: i += 1; continue
|
| 117 |
-
j = i
|
| 118 |
-
while j < b1 and rms[j] <= gate: j += 1
|
| 119 |
-
cand = (j - i, -abs((i + j) * block // 2 - hi), (i + j) * block // 2)
|
| 120 |
-
if best is None or cand > best: best = cand
|
| 121 |
-
i = j
|
| 122 |
-
if best: cut = best[2]
|
| 123 |
-
if cut is not None: out.append((start, cut, split)); start = cut; split = None
|
| 124 |
-
else:
|
| 125 |
-
out.append((start, hi, split)); s_lo, s_hi = hi - overlap + int(0.3 * SR), hi - int(0.3 * SR)
|
| 126 |
-
b = -(-s_lo // block); bestb, bestv = -1, np.inf
|
| 127 |
-
while (b + 1) * block <= s_hi and b < nb:
|
| 128 |
-
if rms[b] < bestv: bestv, bestb = rms[b], b
|
| 129 |
-
b += 1
|
| 130 |
-
split = bestb * block + block // 2 if bestb >= 0 else hi - overlap // 2; start = hi - overlap
|
| 131 |
-
out.append((start, n, split)); return out
|
| 132 |
-
|
| 133 |
-
def speech_blocks(x, block=800):
|
| 134 |
-
"""50 ms blocks above the reference gate (max(0.004, 0.18 x peak RMS of the window))."""
|
| 135 |
-
n = x.size // block
|
| 136 |
-
if n == 0: return np.zeros(0, bool)
|
| 137 |
-
rms = np.sqrt((x[:n * block].reshape(n, block) ** 2).mean(1)); return rms > max(0.004, 0.18 * float(rms.max()))
|
| 138 |
-
|
| 139 |
-
def worst_gap(speech, words):
|
| 140 |
-
"""longest run of 50 ms blocks no word covers -> (start s, end s, speech s) or None"""
|
| 141 |
-
covered = np.zeros(speech.size, bool)
|
| 142 |
-
for w in words: covered[max(0, int(w["start"] / 0.05)):min(speech.size, int(w["end"] / 0.05) + 1)] = True
|
| 143 |
-
best = None; i = 0
|
| 144 |
-
while i < speech.size:
|
| 145 |
-
if covered[i]: i += 1; continue
|
| 146 |
-
j = i
|
| 147 |
-
while j < speech.size and not covered[j]: j += 1
|
| 148 |
-
sp = int(speech[i:j].sum())
|
| 149 |
-
if best is None or sp > best[2]: best = (i, j, sp)
|
| 150 |
-
i = j
|
| 151 |
-
return None if best is None else (best[0] * 0.05, best[1] * 0.05, best[2] * 0.05)
|
| 152 |
-
|
| 153 |
-
class Phonon2CoreML:
|
| 154 |
-
RESCUE_GAP_S = 1.5; RESCUE_MIN_DENSITY = 2.4
|
| 155 |
-
def rescue(self, x, toks, depth=0):
|
| 156 |
-
"""long-audio windows only: >= RESCUE_GAP_S of speech energy with no word (or a very sparse window) -> re-decode as two halves
|
| 157 |
-
split at the gap's quietest block; keep the halves when they give more words. Returns new token triples or None."""
|
| 158 |
-
secs = x.size / SR
|
| 159 |
-
if secs < 3.0 or depth >= 2: return None
|
| 160 |
-
speech = speech_blocks(x); speech_s = float(speech.sum()) * 0.05
|
| 161 |
-
if speech_s < 2.0: return None
|
| 162 |
-
words = words_from_tokens(toks, 0.0, secs); gap = worst_gap(speech, words)
|
| 163 |
-
if gap is None or not (gap[2] >= self.RESCUE_GAP_S or len(words) / speech_s < self.RESCUE_MIN_DENSITY): return None
|
| 164 |
-
cut = (gap[0] + gap[1]) / 2
|
| 165 |
-
if gap[1] - gap[0] > 0.4:
|
| 166 |
-
b0 = int(gap[0] / 0.05) + 1; b1 = int(gap[1] / 0.05); e = [(float((x[b * 800:(b + 1) * 800] ** 2).sum()), b) for b in range(b0, b1)]
|
| 167 |
-
if e: cut = min(e)[1] * 0.05 + 0.025
|
| 168 |
-
cut = min(max(cut, 1.0), secs - 1.0); m = int(cut * SR); out = []
|
| 169 |
-
for a, b in ((0, m), (m, x.size)):
|
| 170 |
-
part = x[a:b]; t = self.run_window(part)
|
| 171 |
-
deeper = self.rescue(part, t, depth + 1)
|
| 172 |
-
if deeper is not None: t = deeper
|
| 173 |
-
out.extend((pc, st + a / SR, du) for pc, st, du in t)
|
| 174 |
-
return out if len(words_from_tokens(out, 0.0, secs)) > len(words) else None
|
| 175 |
-
|
| 176 |
-
def __init__(self, bundle, compute="CPU_AND_NE", frames=None, long_audio=None):
|
| 177 |
-
import coremltools as ct
|
| 178 |
-
self._recent = {}
|
| 179 |
-
self.m = json.load(open(os.path.join(bundle, "manifest.json"))); self.dec = DecoderBin(os.path.join(bundle, "decoder.bin"))
|
| 180 |
-
assert self.dec.container_sha256 == self.m["container_sha256"], "decoder.bin and manifest come from different containers"
|
| 181 |
-
self.frames = frames or self.m.get("frames_rule", "hf"); self.cu = getattr(ct.ComputeUnit, compute); self.bundle = bundle; self.ct = ct
|
| 182 |
-
self.long_audio = long_audio or self.m.get("long_audio", "windows15"); self.functions = sorted(self.m["functions_s"]); self.progs = {}; self.pos = {}; self.load_s = 0.0
|
| 183 |
-
# the runtime pad (manifest leading_pad_s; Phonon-2.5 bundles 0.25 s, Phonon-2 bundles none): digital silence in front of every window
|
| 184 |
-
# before the encoder, word times moved back by it and clamped at 0; the pad counts towards the function's length
|
| 185 |
-
self.lead = min(0.5, max(0.0, float(self.m.get("leading_pad_s") or 0.0))); self.single_shot_max = float(self.m.get("single_shot_max_s", 35.0)) - self.lead
|
| 186 |
-
self._comp = self._compiled(os.path.join(bundle, self.m["multifunction"]))
|
| 187 |
-
def cache_key(self, pkg):
|
| 188 |
-
"""Same key as the Swift package (Transcriber.cacheKey): container + FNV-1a 64 of the program spec + the weight blob's size, so two
|
| 189 |
-
packages of the same weights never share a compiled model, and Swift and Python share one compiled copy."""
|
| 190 |
-
d = os.path.join(pkg, "Data", "com.apple.CoreML"); h = 0xcbf29ce484222325
|
| 191 |
-
for b in open(os.path.join(d, "model.mlmodel"), "rb").read() + os.path.getsize(os.path.join(d, "weights", "weight.bin")).to_bytes(8, "little"):
|
| 192 |
-
h = ((h ^ b) * 0x100000001b3) & 0xFFFFFFFFFFFFFFFF
|
| 193 |
-
return self.m["container_sha256"][:16] + "-" + format(h, "016x")
|
| 194 |
-
def _compiled(self, pkg):
|
| 195 |
-
import shutil
|
| 196 |
-
name = os.path.splitext(os.path.basename(pkg))[0] + ".mlmodelc"
|
| 197 |
-
root = os.environ.get("P2_COMPILE_DIR", os.path.expanduser("~/Library/Caches/phonon-coreml")); key = self.cache_key(pkg)
|
| 198 |
-
for d in (os.path.dirname(pkg), os.path.join(root, key)):
|
| 199 |
-
c = os.path.join(d, name)
|
| 200 |
-
if os.path.isdir(c): return c
|
| 201 |
-
tmp = self.ct.models.utils.compile_model(pkg); d = os.path.join(root, key); os.makedirs(d, exist_ok=True); c = os.path.join(d, name); shutil.move(tmp, c); return c
|
| 202 |
-
def prog(self, s):
|
| 203 |
-
if s not in self.progs:
|
| 204 |
-
t0 = time.perf_counter(); self.progs[s] = self.ct.models.CompiledMLModel(self._comp, compute_units=self.cu, function_name=f"{self.m['program_prefix']}{int(s)}s"); self.load_s += time.perf_counter() - t0
|
| 205 |
-
return self.progs[s]
|
| 206 |
-
@staticmethod
|
| 207 |
-
def frames_for(sec): return 1 + int(round(sec * SR)) // HOP
|
| 208 |
-
def pos_table(self, T3):
|
| 209 |
-
if T3 not in self.pos:
|
| 210 |
-
P = 2 * T3 - 1; p = np.arange(T3 - 1, -T3, -1, dtype=np.float64)[:, None]; invf = 1.0 / (10000.0 ** (np.arange(0, 1024, 2) / 1024.0)); f = p * invf[None, :]
|
| 211 |
-
t = np.zeros((1, P, 1024), np.float32); t[0, :, 0::2] = np.sin(f); t[0, :, 1::2] = np.cos(f); self.pos[T3] = t
|
| 212 |
-
return self.pos[T3]
|
| 213 |
-
def encode(self, wave):
|
| 214 |
-
feats = log_mel(wave, self.frames); n = feats.shape[1]; sec = n * HOP / SR + 0.02
|
| 215 |
-
s = next((b for b in self.functions if sec <= b), None); assert s is not None, f"window of {sec:.1f}s exceeds the largest function"
|
| 216 |
-
T = self.frames_for(s); mel = np.zeros((1, 128, T), np.float32); mel[0, :, :n] = feats; lens = [n]; Ts = [T]
|
| 217 |
-
for _ in range(3): lens.append((lens[-1] - 1) // 2 + 1); Ts.append((Ts[-1] - 1) // 2 + 1)
|
| 218 |
-
feed = {"mel": mel}
|
| 219 |
-
for i, name in enumerate(("m1", "m2", "m3")):
|
| 220 |
-
m = np.zeros((1, 1, Ts[i + 1], 1), np.float32); m[:, :, :lens[i + 1]] = 1; feed[name] = m
|
| 221 |
-
km = np.full((1, 1, 1, Ts[3]), -1e4, np.float32); km[..., :lens[3]] = 0; feed["kmask"] = km
|
| 222 |
-
p = self.prog(s)
|
| 223 |
-
pi = self.m.get("pos_input", True); pi = pi.get(str(int(s)), True) if isinstance(pi, dict) else pi # per function or one flag
|
| 224 |
-
if pi: feed["pos"] = self.pos_table(Ts[3])
|
| 225 |
-
if self.m.get("io") == "float16": feed = {k: v.astype(np.float16) for k, v in feed.items()} # bundles with 16-bit float inputs
|
| 226 |
-
out = np.asarray(p.predict(feed)["enc"], np.float32)[0, :lens[3]]
|
| 227 |
-
# Core ML keeps each function's last inputs and releases them later on its own thread; holding the recent ones here
|
| 228 |
-
# keeps that release from freeing Python memory outside the interpreter lock.
|
| 229 |
-
self._recent.setdefault(s, []).append(feed); del self._recent[s][:-8]
|
| 230 |
-
return out
|
| 231 |
-
def run_window(self, x):
|
| 232 |
-
"""one window (<= single_shot_max s of audio) -> (piece, start s, duration s) tokens on the window's clock, lead pad applied and removed"""
|
| 233 |
-
if is_silent(x): return []
|
| 234 |
-
pad = int(round(self.lead * SR)); xp = np.concatenate([np.zeros(pad, np.float32), np.asarray(x, np.float32)]) if pad else x
|
| 235 |
-
toks = self.dec.pieces(self.dec.decode(self.encode(xp)))
|
| 236 |
-
return [(pc, max(0.0, st - self.lead), du) for pc, st, du in toks] if pad else toks
|
| 237 |
-
def transcribe(self, wave):
|
| 238 |
-
"""-> {"text", "words", "segments"}"""
|
| 239 |
-
wave = np.asarray(wave, np.float32).reshape(-1)
|
| 240 |
-
if self.long_audio == "reference": wins = [(a, b, None) for a, b in reference_plan(wave, single_shot_max_s=min(35.0, self.single_shot_max))]
|
| 241 |
-
else: wins = plan_windows(wave, window_s=15.0 - self.lead, band_min_s=min(10.0, 14.0 - self.lead), single_shot_max_s=self.single_shot_max)
|
| 242 |
-
words = []; segments = []
|
| 243 |
-
for i, (a, b, split) in enumerate(wins):
|
| 244 |
-
w = wave[a:b]; toks = self.run_window(w)
|
| 245 |
-
if len(wins) > 1 and self.long_audio != "reference":
|
| 246 |
-
r = self.rescue(w, toks)
|
| 247 |
-
if r is not None: toks = r
|
| 248 |
-
ws = words_from_tokens(toks, a / SR, (b - a) / SR)
|
| 249 |
-
if split is not None: stitch(words, ws, split / SR)
|
| 250 |
-
else: words.extend(ws)
|
| 251 |
-
segments.append({"id": i, "start": round(a / SR, 3), "end": round(b / SR, 3), "text": " ".join(x["text"] for x in ws)})
|
| 252 |
-
return {"text": " ".join(x["text"] for x in words), "words": words, "segments": segments}
|
| 253 |
-
|
| 254 |
-
def main():
|
| 255 |
-
import argparse, soundfile as sf
|
| 256 |
-
ap = argparse.ArgumentParser(); ap.add_argument("bundle"); ap.add_argument("wavs", nargs="+"); ap.add_argument("--json"); ap.add_argument("--frames", choices=["pip", "hf"]); ap.add_argument("--compute", default="CPU_AND_NE"); ap.add_argument("--reference", action="store_true")
|
| 257 |
-
a = ap.parse_args(); m = Phonon2CoreML(a.bundle, a.compute, a.frames, "reference" if a.reference else None); rows = []; ta = tw = 0.0
|
| 258 |
-
for p in a.wavs:
|
| 259 |
-
w, sr = sf.read(p, dtype="float32")
|
| 260 |
-
if w.ndim > 1: w = w.mean(1)
|
| 261 |
-
if sr != SR:
|
| 262 |
-
import scipy.signal as ss; w = ss.resample_poly(w, SR, sr)
|
| 263 |
-
t0 = time.perf_counter(); r = m.transcribe(w); dt = time.perf_counter() - t0; ta += len(w) / SR; tw += dt
|
| 264 |
-
print(r["text"]); rows.append({"path": os.path.basename(p), "audio_s": round(len(w) / SR, 2), "wall_s": round(dt, 4), **r})
|
| 265 |
-
if a.json: json.dump({"runtime": "phonon_coreml.py (Core ML encoder, compiled decoder)", "frames_rule": m.frames, "compute": a.compute, "long_audio": m.long_audio, "load_s": round(m.load_s, 2), "audio_s": round(ta, 2), "decode_wall_s": round(tw, 3), "x_realtime": round(ta / tw, 1) if tw else None, "rows": rows}, open(a.json, "w"), indent=1)
|
| 266 |
-
|
| 267 |
-
if __name__ == "__main__": main()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
segmenter_np.py
DELETED
|
@@ -1,27 +0,0 @@
|
|
| 1 |
-
"""Line-for-line port of fermion._speech.segment.plan / is_silent (numpy) for the reference runner; no silence padding anywhere."""
|
| 2 |
-
import numpy as np
|
| 3 |
-
SR = 16000; SINGLE_SHOT_MAX_S = 35.0; BAND_MIN_S = 25.0; BAND_MAX_S = 35.0; TARGET_S = 30.0; BLOCK_S = 0.05; NOISE_FLOOR_RMS = 0.004; GATE_RATIO = 0.18
|
| 4 |
-
def is_silent(audio): return audio.size == 0 or float(np.max(np.abs(audio))) < 1e-4
|
| 5 |
-
def plan(audio, sample_rate=SR, single_shot_max_s=SINGLE_SHOT_MAX_S):
|
| 6 |
-
"""single_shot_max_s < 35 (a bundle with a leading pad): the one-window limit and the band's end shrink by the pad."""
|
| 7 |
-
audio = np.asarray(audio, dtype=np.float32).reshape(-1); n = int(audio.size)
|
| 8 |
-
band_max = min(BAND_MAX_S, single_shot_max_s); band_min = min(BAND_MIN_S, band_max - 1); target = min(TARGET_S, band_max)
|
| 9 |
-
if n <= int(single_shot_max_s * sample_rate): return [(0, n)]
|
| 10 |
-
block = int(BLOCK_S * sample_rate); n_blocks = -(-n // block); padded = np.zeros(n_blocks * block, dtype=np.float32); padded[:n] = audio
|
| 11 |
-
rms = np.sqrt(np.mean(padded.reshape(n_blocks, block) ** 2, axis=1)); single = int(single_shot_max_s * sample_rate); windows = []; start = 0
|
| 12 |
-
while n - start > single:
|
| 13 |
-
lo = start + int(band_min * sample_rate); hi = start + int(band_max * sample_rate); b0 = -(-lo // block); b1 = hi // block
|
| 14 |
-
peak = float(rms[start // block:b1].max()) if b1 > start // block else 0.0; gate = max(NOISE_FLOOR_RMS, GATE_RATIO * peak); quiet = rms[b0:b1] <= gate
|
| 15 |
-
cut = start + int(target * sample_rate)
|
| 16 |
-
if quiet.any():
|
| 17 |
-
best = None; i = 0
|
| 18 |
-
while i < quiet.size:
|
| 19 |
-
if not quiet[i]: i += 1; continue
|
| 20 |
-
j = i
|
| 21 |
-
while j < quiet.size and quiet[j]: j += 1
|
| 22 |
-
mid = int(((b0 + i) + (b0 + j)) * block // 2); cand = (j - i, -abs(mid - (start + int(target * sample_rate))), mid)
|
| 23 |
-
if best is None or cand > best: best = cand
|
| 24 |
-
i = j
|
| 25 |
-
cut = best[2]
|
| 26 |
-
cut = max(lo, min(hi, cut, n)); windows.append((start, cut)); start = cut
|
| 27 |
-
windows.append((start, n)); return windows
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|