@gjsify/sherpa-native 0.0.0-stage → 0.64.15
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +330 -2
- package/lib/esm/_virtual/_rolldown/runtime.js +1 -0
- package/lib/esm/index.js +1 -0
- package/lib/types/index.d.ts +47 -0
- package/meson.build +563 -0
- package/package.json +93 -5
- package/src/c/gjsify-sherpa-shim.c +575 -0
- package/src/c/gjsify-sherpa-shim.h +259 -0
- package/src/c/gjsify-sherpa.map +27 -0
- package/src/ts/gjsifysherpa-1.0.d.ts +1159 -0
- package/src/ts/index.ts +95 -0
- package/src/vala/offline-recognizer.vala +238 -0
- package/src/vala/online-recognizer.vala +303 -0
- package/src/vala/sherpa-shim.vapi +178 -0
- package/src/vala/sherpa.vala +76 -0
- package/src/vala/vad.vala +207 -0
- package/subprojects/packagefiles/sherpa-onnx-shared-onnxruntime/cmake/onnxruntime-linux-x86_64-static.cmake +112 -0
- package/subprojects/sherpa-onnx.wrap +56 -0
- package/test/api.gjs.js +155 -0
- package/test/check-elf-deps.py +213 -0
- package/test/shim-smoke.c +146 -0
- package/test/vad-model.gjs.js +112 -0
package/README.md
CHANGED
|
@@ -1,3 +1,331 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @gjsify/sherpa-native
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
[sherpa-onnx](https://github.com/k2-fsa/sherpa-onnx)'s C API as a Vala/GObject bridge,
|
|
4
|
+
built as one relocatable shared library plus its GObject-Introspection typelib — so
|
|
5
|
+
`gi://GjsifySherpa?version=1.0` gives GJS a Silero voice activity detector and
|
|
6
|
+
streaming/whole-utterance speech recognizers on a host that has neither sherpa-onnx nor
|
|
7
|
+
onnxruntime installed.
|
|
8
|
+
|
|
9
|
+
This is the backend of [`@gjsify/vad`](../vad/README.md). It contains no policy of its
|
|
10
|
+
own: no model cache, no default model path, no chunking, no timing.
|
|
11
|
+
|
|
12
|
+
## What it is
|
|
13
|
+
|
|
14
|
+
sherpa-onnx is an **inference runtime**, not a model. Each of its three engines is an
|
|
15
|
+
opaque handle created from a nested C struct of file paths and numbers, and the struct is
|
|
16
|
+
the part JavaScript cannot express: GJS has no way to lay out
|
|
17
|
+
`SherpaOnnxOnlineRecognizerConfig` or hand sherpa-onnx a `const float*`. That is this
|
|
18
|
+
package's entire job.
|
|
19
|
+
|
|
20
|
+
| ships | from |
|
|
21
|
+
|---|---|
|
|
22
|
+
| `libgjsifysherpa.so` + `libonnxruntime.so` + `GjsifySherpa-1.0.typelib`, per target, in `@gjsify/sherpa-native-<os>-<arch>` | this package's meson build |
|
|
23
|
+
| `loadNativeSherpa()` / `hasNativeSherpa()` / `getLoadError()` | `src/ts/index.ts` |
|
|
24
|
+
| generated `GjsifySherpa-1.0` types | `src/ts/gjsifysherpa-1.0.d.ts` — `npm run build:gir-types` |
|
|
25
|
+
|
|
26
|
+
**No model is bundled, ever** (ADR 0127 decision 14). Model licences differ from
|
|
27
|
+
sherpa-onnx's own Apache-2.0, several forbid redistribution, and the smallest useful one
|
|
28
|
+
is larger than this library. Every class takes its files from the caller.
|
|
29
|
+
|
|
30
|
+
Recognizers are **transducer-only** (encoder + decoder + joiner + tokens). Whisper is a
|
|
31
|
+
different model layout with a different config struct and belongs in a separate
|
|
32
|
+
`@gjsify/whisper-native`, not in a `model_type` switch here.
|
|
33
|
+
|
|
34
|
+
## The API
|
|
35
|
+
|
|
36
|
+
Three independent classes, each a GObject with construct properties and a separate
|
|
37
|
+
`open()`. Construction never touches the filesystem or allocates an engine; `open()` is
|
|
38
|
+
where paths are checked, the ~50 MB of model weights are mapped and onnxruntime builds its
|
|
39
|
+
session. So a caller can configure a detector, decide it is not needed, and drop it for
|
|
40
|
+
free — and a failure to open is an exception at one named point rather than inside a
|
|
41
|
+
constructor.
|
|
42
|
+
|
|
43
|
+
```js
|
|
44
|
+
import GjsifySherpa from 'gi://GjsifySherpa?version=1.0';
|
|
45
|
+
|
|
46
|
+
const vad = new GjsifySherpa.Vad({
|
|
47
|
+
model: '/path/to/silero_vad.onnx',
|
|
48
|
+
min_silence_duration: 0.3, // seconds; also the default, per ADR 0127 decision 8
|
|
49
|
+
});
|
|
50
|
+
vad.open();
|
|
51
|
+
|
|
52
|
+
vad.accept(samples); // float32, -1..1, any length
|
|
53
|
+
while (vad.has_segment()) {
|
|
54
|
+
const [got, speech, start] = vad.next_segment(); // samples, and where they began
|
|
55
|
+
}
|
|
56
|
+
vad.close();
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
`accept()` takes **any chunk size**: `VoiceActivityDetectorAcceptWaveform` buffers
|
|
60
|
+
internally and runs the model whenever it has `window_size` (512) samples, so a caller
|
|
61
|
+
feeds it whatever its source produces and never pads.
|
|
62
|
+
|
|
63
|
+
`next_segment()` is the `read`/`pop` half of a `peek`/`read`/`pop` trio in the C shim:
|
|
64
|
+
`has_segment()` asks, `next_segment()` copies the samples out and advances. A segment is
|
|
65
|
+
the audio between a speech start and the silence that ended it — the detector reports
|
|
66
|
+
boundaries, never "turns"; whose turn it is is an application's question.
|
|
67
|
+
|
|
68
|
+
It returns a **boolean plus two out parameters** rather than a nullable array, and that is
|
|
69
|
+
a measurement rather than a preference: under gjs a NULL C array of length 0 arrives as an
|
|
70
|
+
empty `Array`, so a `float[]?` return collapses "nothing is queued" and "here is a segment"
|
|
71
|
+
into one value `=== null` cannot tell apart.
|
|
72
|
+
|
|
73
|
+
```js
|
|
74
|
+
const rec = new GjsifySherpa.OnlineRecognizer({
|
|
75
|
+
encoder: enc, decoder: dec, joiner: join, tokens: tok,
|
|
76
|
+
});
|
|
77
|
+
rec.open();
|
|
78
|
+
const stream = rec.create_stream();
|
|
79
|
+
stream.accept(16000, samples);
|
|
80
|
+
while (stream.is_ready()) stream.decode();
|
|
81
|
+
const text = stream.get_text(); // also get_json() for timestamps + per-token data
|
|
82
|
+
if (stream.is_endpoint()) stream.reset();
|
|
83
|
+
stream.close();
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
`OfflineRecognizer` is the same shape for a whole utterance: `accept()`, `decode()`,
|
|
87
|
+
`get_text()`, with no `is_ready`/`is_endpoint`/`reset`.
|
|
88
|
+
|
|
89
|
+
### Lifetime
|
|
90
|
+
|
|
91
|
+
A stream holds a strong reference on its recognizer, so a recognizer cannot be finalised
|
|
92
|
+
under a live stream, and `recognizer.close()` closes its streams first — it keeps an
|
|
93
|
+
`unowned` list of them. That is the idiom
|
|
94
|
+
[`@gjsify/sqlite-native`](../../node/sqlite-native/src/vala/database.vala) established for
|
|
95
|
+
a handle that owns child handles; without it, a GC in the wrong order is a use-after-free
|
|
96
|
+
inside sherpa-onnx rather than an exception.
|
|
97
|
+
|
|
98
|
+
Every method used before `open()` or after `close()` throws `SherpaError.NOT_OPEN` — the
|
|
99
|
+
other two members are `MODEL_MISSING`, which names the file, and `OPEN_FAILED`, which is
|
|
100
|
+
sherpa-onnx refusing a configuration for a reason it only writes to stderr. `close()` is
|
|
101
|
+
idempotent and also runs from `dispose`, so forgetting it leaks nothing.
|
|
102
|
+
|
|
103
|
+
### From TypeScript
|
|
104
|
+
|
|
105
|
+
```ts
|
|
106
|
+
import { hasNativeSherpa, loadNativeSherpa } from '@gjsify/sherpa-native';
|
|
107
|
+
|
|
108
|
+
const sherpa = loadNativeSherpa(); // null when no prebuild for this platform
|
|
109
|
+
if (sherpa) {
|
|
110
|
+
sherpa.version(); // '2.0.1'
|
|
111
|
+
sherpa.onnxruntime_version(); // '1.28.2'
|
|
112
|
+
}
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
Loading is `loadOptionalNativeModule` from `@gjsify/utils/core`: absent is an answer, with
|
|
116
|
+
the cause in `getLoadError()`. It resolves through `imports.gi.*` rather than a static
|
|
117
|
+
`gi://` import on purpose — a static specifier is resolved during ESM linking, before
|
|
118
|
+
`GI_TYPELIB_PATH` is set, so the prebuild would be invisible to it.
|
|
119
|
+
|
|
120
|
+
## Building
|
|
121
|
+
|
|
122
|
+
```sh
|
|
123
|
+
gjsify workspace @gjsify/sherpa-native run build:prebuilds # meson + stage-prebuild
|
|
124
|
+
gjsify workspace @gjsify/sherpa-native run test:meson
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
`meson setup` fetches the pinned sherpa-onnx checkout and CMake then fetches eigen,
|
|
128
|
+
kaldi-native-fbank, kaldi-decoder, kissfft, kaldifst, openfst, utf8proc,
|
|
129
|
+
simple-sentencepiece and nlohmann/json, so **the first configure needs network access**
|
|
130
|
+
even though every revision is pinned. It also wants the onnxruntime **shared** release zip
|
|
131
|
+
(~35 MB) — see the subproject bullet below for why shared; CMake caches it and will not
|
|
132
|
+
re-fetch.
|
|
133
|
+
|
|
134
|
+
`libstdc++.a` must be installed, because `libgjsifysherpa.so` is linked with
|
|
135
|
+
`-static-libstdc++`. Not because no libstdc++ may be in the process — `libonnxruntime.so`
|
|
136
|
+
beside it has its own DT_NEEDED on `libstdc++.so.6` — but to keep this library from adding
|
|
137
|
+
a **second, higher GLIBCXX floor** on top of the engine's. The engine is built by GCC 4.8
|
|
138
|
+
and asks for `GLIBCXX_3.4.19`; the same code compiled by Fedora 44's GCC 16 and linked
|
|
139
|
+
dynamically asks for `GLIBCXX_3.4.30`. The C++ that crosses between bridge and engine is
|
|
140
|
+
sherpa-onnx's use of onnxruntime's **C** API, so the two libstdc++ copies never meet an
|
|
141
|
+
object of each other's. **This does not need root** — the package can be unpacked into a
|
|
142
|
+
scratch directory and pointed at with `-B`:
|
|
143
|
+
|
|
144
|
+
```sh
|
|
145
|
+
dnf download libstdc++-static # works unprivileged
|
|
146
|
+
rpm2cpio libstdc++-static-*.rpm | (cd /tmp/stdcxxa && cpio -idm)
|
|
147
|
+
cc -B/tmp/stdcxxa/usr/lib/gcc/x86_64-redhat-linux/16/ -print-file-name=libstdc++.a
|
|
148
|
+
```
|
|
149
|
+
|
|
150
|
+
`meson.build` **probes** for the archive (`cc -print-file-name=libstdc++.a`, accepted only
|
|
151
|
+
as an absolute path that exists) rather than hardcoding one, warns when it is missing, and
|
|
152
|
+
only then passes `--require-static-libstdcxx` to the ELF test. Without the probe the
|
|
153
|
+
failure surfaces four dependencies deep, as simple-sentencepiece reporting "requires a
|
|
154
|
+
compiler supporting at least C++14 … upgrade GCC to at least version 7.0".
|
|
155
|
+
|
|
156
|
+
What `-static-libstdc++` does **not** buy is a low glibc floor — that is set by the build
|
|
157
|
+
image, for every prebuild in this repository alike. Measured here on Fedora 44:
|
|
158
|
+
`sqrtf@GLIBC_2.43` and `log10f@GLIBC_2.43` from the feature maths, plus
|
|
159
|
+
`__isoc23_strtoll@GLIBC_2.38`. glibc 2.43 re-versions those float-math symbols and the
|
|
160
|
+
linker binds the newest default version available, so building there raises the
|
|
161
|
+
requirement with no source change — which is exactly why `prebuilds.yml` pins
|
|
162
|
+
`fedora:43` and says so at length above its `container:`. The CI artifact therefore has a
|
|
163
|
+
lower floor than a local Fedora 44 build; do not read a local measurement as the shipped
|
|
164
|
+
one.
|
|
165
|
+
|
|
166
|
+
Five other things in `meson.build` are worth knowing:
|
|
167
|
+
|
|
168
|
+
- **sherpa-onnx is a CMake subproject** (`cmake.subproject()`), the pattern
|
|
169
|
+
[`@gjsify/gamepad-native`](../gamepad-native/meson.build) uses for SDL3 — sherpa-onnx
|
|
170
|
+
has no meson build. It is built with `BUILD_SHARED_LIBS=OFF`, and the target to link is
|
|
171
|
+
`sherpa-onnx-c-api`.
|
|
172
|
+
- **onnxruntime is the one thing that is NOT static**, and this is the package's single
|
|
173
|
+
most load-bearing measurement. The prebuilt `libonnxruntime.a` (GCC 4.8) and the
|
|
174
|
+
host-GCC `libsherpa_onnx_core.a` both define the same 54 weak vague-linkage symbols —
|
|
175
|
+
among them all nine members of `std::__detail::_Scanner<char>`, whose mangled name is
|
|
176
|
+
stable across GCC versions while its layout is not, because libstdc++ puts
|
|
177
|
+
`regex_traits` in `std::__cxx11` but `_Scanner` in plain `std::__detail`. The linker
|
|
178
|
+
dedupes them, `DeviceDiscovery::GetPciBusId` then builds an old-layout `_Scanner` through
|
|
179
|
+
a new-layout constructor, and the first `Vad.open()` dies in `free(): invalid pointer`.
|
|
180
|
+
The fix is a `patch_directory` overlay on the wrap
|
|
181
|
+
([`subprojects/packagefiles/sherpa-onnx-shared-onnxruntime/`](subprojects/packagefiles/sherpa-onnx-shared-onnxruntime/cmake/onnxruntime-linux-x86_64-static.cmake))
|
|
182
|
+
that swaps upstream's static x86_64 fetch file for upstream's own shared one, so
|
|
183
|
+
`libonnxruntime.so` travels in the prebuild and is found through RUNPATH `$ORIGIN`. The
|
|
184
|
+
overlay is **per architecture**: `meson.build` maps arch → overlay file and `error()`s on
|
|
185
|
+
a linux arch it has no entry for, rather than falling back to the static file that
|
|
186
|
+
crashes.
|
|
187
|
+
- **`sherpa_inc` must be declared after `cmake.subproject()`**, because that call is what
|
|
188
|
+
materialises the checkout, and because sherpa-onnx sets its include path with a
|
|
189
|
+
directory-scoped `include_directories()` that meson's cmake module cannot read off the
|
|
190
|
+
target.
|
|
191
|
+
- **The C shim is its own `static_library`**, and both the shared library and the smoke
|
|
192
|
+
test consume `shim.extract_all_objects(recursive: false)`. `extract_all_objects` on a
|
|
193
|
+
target with Vala sources does not work: ninja has no rule for the Vala-generated `.c.o`
|
|
194
|
+
outside the library target. The shared library takes the **objects**, not
|
|
195
|
+
`link_whole` — an archive's symbols would be localised by `--exclude-libs,ALL`.
|
|
196
|
+
- **Symbols are hidden twice**: `-Wl,--exclude-libs,ALL` for the static archives, plus a
|
|
197
|
+
version script (`src/c/gjsify-sherpa.map`) exporting one `gjsify_sherpa_*` glob that
|
|
198
|
+
covers both the Vala API and the shim. Measured on the built artifact: 168 exported
|
|
199
|
+
symbols, all `gjsify_sherpa_*`, and no onnxruntime symbol at all — so this file cannot
|
|
200
|
+
collide with a host onnxruntime.
|
|
201
|
+
|
|
202
|
+
Measured DT_NEEDED on the static-libstdc++ build — **6 entries**: `libglib-2.0.so.0`,
|
|
203
|
+
`libgobject-2.0.so.0`, `libonnxruntime.so`, `libm.so.6`, `libmvec.so.1`, `libc.so.6`.
|
|
204
|
+
Nothing else: no libstdc++, no libgcc_s. RUNPATH is `$ORIGIN` and no RPATH, which is the
|
|
205
|
+
ADR 0017 prebuild layout, not an accident, and it is also the only thing that resolves the
|
|
206
|
+
deliberately unversioned `libonnxruntime.so` to the sibling rather than to a distribution's
|
|
207
|
+
`libonnxruntime.so.1`. `libmvec` is part of glibc and arrives through `-lm` with the feature
|
|
208
|
+
maths auto-vectorised; it is in `check-elf-deps.py`'s allow-list for that reason.
|
|
209
|
+
|
|
210
|
+
The engine's own surface is measured from the other side in the same test: `libonnxruntime.so`
|
|
211
|
+
exports exactly `OrtGetApiBase`, `OrtSessionOptionsAppendExecutionProvider_CPU` and the
|
|
212
|
+
version node `VERS_1.28.2`, and its GLIBCXX floor is 3.4.19 — asserted at ≤ 3.4.20 so that
|
|
213
|
+
a wrap bump to an archive from a newer toolchain reds the test instead of silently costing
|
|
214
|
+
the prebuild its portability.
|
|
215
|
+
|
|
216
|
+
The link uses `-Wl,--strip-all`, not the `--strip-debug` the sibling packages use. Measured
|
|
217
|
+
by relinking the same objects both ways: 5,113,824 bytes with `--strip-debug`,
|
|
218
|
+
**4,298,944 with `--strip-all`** — 0.8 MB of `.symtab` that is sherpa-onnx's complete static
|
|
219
|
+
symbol table and that nothing reads. `.dynsym` is untouched, so the ELF read-back still
|
|
220
|
+
measures the exports.
|
|
221
|
+
|
|
222
|
+
### The linux-x64 prebuild is built and committed by CI
|
|
223
|
+
|
|
224
|
+
`prebuilds.yml` builds it on its own `sherpa-native-prebuild` job — a separate job only
|
|
225
|
+
because this bridge needs `cmake` and `libstdc++-static` on top of the toolchain the other
|
|
226
|
+
Vala legs install — and `commit-prebuilds` downloads the artifact into
|
|
227
|
+
`@gjsify/sherpa-native-linux-x64/prebuilds/linux-x64/` and pushes it to `main` as
|
|
228
|
+
`chore: update native prebuilds [skip ci]`. That is the one route every native prebuild in
|
|
229
|
+
this repository takes; nothing is ever committed by hand.
|
|
230
|
+
|
|
231
|
+
The staged directory is **24.2 MiB**: 4.1 MiB of bridge, 20.0 MiB of engine, plus the GIR
|
|
232
|
+
and typelib. Big, against the 12.8 MB of `rolldown-native-linux-x64` — the largest the
|
|
233
|
+
repository committed before this one — and a sherpa-onnx bump re-commits all of it. Both
|
|
234
|
+
`.so` files are stripped to get there: the bridge by `-Wl,--strip-all` at link time, and
|
|
235
|
+
the engine by `strip --strip-all` as `meson.build` stages it, because upstream ships the
|
|
236
|
+
release unstripped and 6.0 MB of it (22 %) is a debug symbol table nothing in a prebuild
|
|
237
|
+
can read. `strip` is probed, not assumed; a host without binutils gets a warning and an
|
|
238
|
+
unstripped copy, while the CI leg asserts the stripped form of the staged artifact.
|
|
239
|
+
|
|
240
|
+
A local meson build stages into this bridge's own `prebuilds/linux-x64/` — the path the CI
|
|
241
|
+
upload reads — and the root `.gitignore` lists it, for the reason the note beside
|
|
242
|
+
`packages/napi/napi/prebuilds/` gives: untracked and unignored is one `git add -A` away from
|
|
243
|
+
25 MB of binary in a package that declares no `gjsify.prebuilds` and therefore has no
|
|
244
|
+
conformance rule watching it.
|
|
245
|
+
|
|
246
|
+
Delete that directory before running `scripts/generate-platform-packages.mjs`. Its `--write`
|
|
247
|
+
still carries the ADR 0017 migration step — `git mv <bridge>/prebuilds/<target>` into the
|
|
248
|
+
per-target package — and a scratch staging dir looks exactly like the thing that step exists
|
|
249
|
+
to move. It crashes rather than moving it, which is the safe failure, but `--check` reports a
|
|
250
|
+
`libc` field the generator would only have measured from those bytes, and the error names
|
|
251
|
+
neither the staging dir nor the build that wrote it.
|
|
252
|
+
|
|
253
|
+
`gjsify.platformsUncommitted` is still set on the child package until that first commit
|
|
254
|
+
lands, and it is not a deferral to clear by hand: `commit-prebuilds` runs
|
|
255
|
+
`scripts/clear-committed-platform-exemptions.mjs` immediately before staging, so the run
|
|
256
|
+
that downloads the artifact is the run that drops the marker, in the same commit as the
|
|
257
|
+
bytes.
|
|
258
|
+
|
|
259
|
+
`build:gir-types` reads `--girDirectories=build` — the meson build directory — rather than
|
|
260
|
+
the child's `prebuilds/linux-x64` as `sqlite-native` does, and keeps doing so after the
|
|
261
|
+
artifact is committed: the GIR that describes the library you just built is the one in your
|
|
262
|
+
own build tree, and a checkout must be able to generate types before any CI run has touched
|
|
263
|
+
it.
|
|
264
|
+
|
|
265
|
+
## Testing
|
|
266
|
+
|
|
267
|
+
```sh
|
|
268
|
+
gjsify workspace @gjsify/sherpa-native run test:meson
|
|
269
|
+
```
|
|
270
|
+
|
|
271
|
+
- `shim-smoke` — C, links the shim's objects directly and reports the two versions. It is
|
|
272
|
+
the leg that fails first and most legibly when the subproject or the link breaks.
|
|
273
|
+
- `elf-deps` — reads DT_NEEDED, RUNPATH and the exported symbol table back off both built
|
|
274
|
+
files (`test/check-elf-deps.py`), and asserts no dynamic libstdc++ in the bridge when the
|
|
275
|
+
archive probe succeeded.
|
|
276
|
+
- `api-gjs` — imports `gi://GjsifySherpa?version=1.0` under `gjs` from the build directory
|
|
277
|
+
and drives the detector and both recognizers: construct properties read back their
|
|
278
|
+
defaults, a missing model is refused by path, a closed object throws. This is what
|
|
279
|
+
proves the GIR, the typelib and the library agree.
|
|
280
|
+
- `vad-model-gjs` — the one leg that opens a real onnxruntime session, because opening a
|
|
281
|
+
session was the only thing that ever saw the heap corruption the overlay fixes. It exits
|
|
282
|
+
**77 (skip)** unless a Silero model is cached at
|
|
283
|
+
`~/.cache/gjsify/speech-models/silero_vad_v5.onnx` or named by
|
|
284
|
+
`GJSIFY_SHERPA_VAD_MODEL`, so it is a regression guard where a model exists and silent
|
|
285
|
+
where one does not.
|
|
286
|
+
|
|
287
|
+
**Nothing in the suite downloads a model.** What that costs in coverage, stated plainly:
|
|
288
|
+
the detector is exercised against real weights wherever a model is cached, and has been
|
|
289
|
+
run by hand on Fedora 44 / x86_64 / GCC 16 against two 16 kHz recordings (one segment
|
|
290
|
+
each, boundaries within a chunk of the audible ones). **The two recognizers have not been
|
|
291
|
+
run against real weights at all** — they are compiled, their construct properties, path
|
|
292
|
+
refusal and lifecycle are tested, and that is the whole of it. Transducer weights are
|
|
293
|
+
~250 MB and a download does not belong in `meson test`; the gap closes when the scheduled
|
|
294
|
+
model job of ADR 0127 exists.
|
|
295
|
+
|
|
296
|
+
**No test ever produces audible sound or opens a microphone** (ADR 0127). Audio in is a
|
|
297
|
+
`float[]` or a WAV fixture; there is no output path in this package at all.
|
|
298
|
+
|
|
299
|
+
## Updating sherpa-onnx
|
|
300
|
+
|
|
301
|
+
`subprojects/sherpa-onnx.wrap` pins the tag `v2.0.1` with `depth = 1`, which resolves to
|
|
302
|
+
commit `af2d8d81dbfa61c4cea4c568da78f3982edca005`. A shallow clone can fetch a tag; move
|
|
303
|
+
off `depth = 1` if the pin ever has to become a non-tip commit.
|
|
304
|
+
|
|
305
|
+
To update: change the `revision`, **re-check the overlay against the new upstream
|
|
306
|
+
`cmake/onnxruntime-linux-x86_64-shared.cmake`** (its header file says what to diff and
|
|
307
|
+
why), `rm -rf subprojects/sherpa-onnx` so meson re-applies the patch to a fresh checkout —
|
|
308
|
+
it only patches a checkout it created itself — then rebuild, run the tests, and re-measure
|
|
309
|
+
the numbers in this file: exported symbols, DT_NEEDED, the engine's floor and the stripped
|
|
310
|
+
file sizes. Only GLib/GObject, `libonnxruntime.so`, libm/libmvec and libc may appear, and
|
|
311
|
+
no exported symbol outside `gjsify_sherpa_*`. The onnxruntime version moves with
|
|
312
|
+
sherpa-onnx's own `cmake/onnxruntime.cmake`, which also means the `VERS_` node asserted in
|
|
313
|
+
`check-elf-deps.py` moves; `shim-smoke` prints what it actually got.
|
|
314
|
+
|
|
315
|
+
The C shim is the whole surface that knows sherpa-onnx's structs
|
|
316
|
+
(`src/c/gjsify-sherpa-shim.h`); the VAPI below it binds nothing but scalars, strings and
|
|
317
|
+
opaque pointers. A struct that changes upstream therefore breaks one file, with a C
|
|
318
|
+
compiler error, instead of silently mis-reading memory through a hand-written VAPI.
|
|
319
|
+
|
|
320
|
+
## License
|
|
321
|
+
|
|
322
|
+
This package is MIT.
|
|
323
|
+
|
|
324
|
+
The **prebuilt libraries** in `@gjsify/sherpa-native-linux-x64` are `MIT AND Apache-2.0`:
|
|
325
|
+
`libgjsifysherpa.so` has sherpa-onnx (© the k2-fsa authors, Apache-2.0) linked in
|
|
326
|
+
statically, and `libonnxruntime.so` beside it is a verbatim copy of Microsoft's
|
|
327
|
+
onnxruntime (MIT) as redistributed by the
|
|
328
|
+
[onnxruntime-libs](https://github.com/csukuangfj/onnxruntime-libs) release the overlay
|
|
329
|
+
pins. The pinned revision in `subprojects/sherpa-onnx.wrap` is the corresponding source. Model weights are **not** covered — they are never shipped, and each
|
|
330
|
+
carries its own licence from whoever trained it. See
|
|
331
|
+
[`docs/attribution.md`](../../../docs/attribution.md).
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var e=Object.defineProperty,__name=(t,n)=>e(t,`name`,{value:n,configurable:!0});export{__name};
|
package/lib/esm/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import"./_virtual/_rolldown/runtime.js";import{loadOptionalNativeModule as e}from"@gjsify/utils/core";let t=null,n=!1,r=null;function loadNativeSherpa(){if(n)return t;n=!0;let{module:i,error:a}=e(`GjsifySherpa`,[`Vad`,`OnlineRecognizer`,`OfflineRecognizer`]);return t=i,r=a,t}function hasNativeSherpa(){return loadNativeSherpa()!==null}function getLoadError(){return r}export{getLoadError,hasNativeSherpa,loadNativeSherpa};
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import type { GjsifySherpa as GjsifySherpaNS } from 'gi://GjsifySherpa?version=1.0';
|
|
2
|
+
type VadInstance = GjsifySherpaNS.Vad;
|
|
3
|
+
type VadStatic = typeof GjsifySherpaNS.Vad;
|
|
4
|
+
type OnlineRecognizerInstance = GjsifySherpaNS.OnlineRecognizer;
|
|
5
|
+
type OnlineRecognizerStatic = typeof GjsifySherpaNS.OnlineRecognizer;
|
|
6
|
+
type OnlineStreamInstance = GjsifySherpaNS.OnlineStream;
|
|
7
|
+
type OfflineRecognizerInstance = GjsifySherpaNS.OfflineRecognizer;
|
|
8
|
+
type OfflineRecognizerStatic = typeof GjsifySherpaNS.OfflineRecognizer;
|
|
9
|
+
type OfflineStreamInstance = GjsifySherpaNS.OfflineStream;
|
|
10
|
+
/**
|
|
11
|
+
* The module as `imports.gi.GjsifySherpa` actually presents it.
|
|
12
|
+
*
|
|
13
|
+
* The free functions keep their C names: GJS camel-cases METHODS but not
|
|
14
|
+
* namespace-level functions, so `onnxruntime_version` and `file_exists` are
|
|
15
|
+
* what the typelib hands over — verified against the built library, not
|
|
16
|
+
* assumed.
|
|
17
|
+
*/
|
|
18
|
+
export interface NativeSherpaModule {
|
|
19
|
+
Vad: VadStatic;
|
|
20
|
+
OnlineRecognizer: OnlineRecognizerStatic;
|
|
21
|
+
OfflineRecognizer: OfflineRecognizerStatic;
|
|
22
|
+
/** The statically linked sherpa-onnx version, e.g. `2.0.1`. */
|
|
23
|
+
version(): string;
|
|
24
|
+
/** The onnxruntime version sherpa-onnx was built against, e.g. `1.28.2`. */
|
|
25
|
+
onnxruntime_version(): string;
|
|
26
|
+
/** Whether a path is readable, as sherpa-onnx itself would judge it. */
|
|
27
|
+
file_exists(path: string): boolean;
|
|
28
|
+
}
|
|
29
|
+
export type { VadInstance as Vad };
|
|
30
|
+
export type { OnlineRecognizerInstance as OnlineRecognizer };
|
|
31
|
+
export type { OnlineStreamInstance as OnlineStream };
|
|
32
|
+
export type { OfflineRecognizerInstance as OfflineRecognizer };
|
|
33
|
+
export type { OfflineStreamInstance as OfflineStream };
|
|
34
|
+
/**
|
|
35
|
+
* Lazily load the GjsifySherpa typelib. Idempotent — subsequent calls
|
|
36
|
+
* return the cached module (or `null` if the first call failed).
|
|
37
|
+
*/
|
|
38
|
+
export declare function loadNativeSherpa(): NativeSherpaModule | null;
|
|
39
|
+
/**
|
|
40
|
+
* Returns `true` if the GjsifySherpa typelib is loadable (prebuild present).
|
|
41
|
+
*/
|
|
42
|
+
export declare function hasNativeSherpa(): boolean;
|
|
43
|
+
/**
|
|
44
|
+
* Returns the load error from the first `loadNativeSherpa()` call, or `null`
|
|
45
|
+
* if loading succeeded or hasn't been attempted yet.
|
|
46
|
+
*/
|
|
47
|
+
export declare function getLoadError(): Error | null;
|