react-native-sherpa-onnx 0.1.0

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.
Files changed (83) hide show
  1. package/LICENSE +20 -0
  2. package/README.md +402 -0
  3. package/SherpaOnnx.podspec +84 -0
  4. package/android/build.gradle +193 -0
  5. package/android/src/main/AndroidManifest.xml +2 -0
  6. package/android/src/main/cpp/CMakeLists.txt +121 -0
  7. package/android/src/main/cpp/include/sherpa-onnx/c-api/c-api.h +1918 -0
  8. package/android/src/main/cpp/include/sherpa-onnx/c-api/cxx-api.h +841 -0
  9. package/android/src/main/cpp/jni/sherpa-onnx-jni.cpp +129 -0
  10. package/android/src/main/cpp/jni/sherpa-onnx-wrapper.cpp +649 -0
  11. package/android/src/main/cpp/jni/sherpa-onnx-wrapper.h +56 -0
  12. package/android/src/main/java/com/sherpaonnx/SherpaOnnxModule.kt +316 -0
  13. package/android/src/main/java/com/sherpaonnx/SherpaOnnxPackage.kt +33 -0
  14. package/ios/Frameworks/sherpa_onnx.xcframework.zip +0 -0
  15. package/ios/SherpaOnnx.h +5 -0
  16. package/ios/SherpaOnnx.mm +293 -0
  17. package/ios/SherpaOnnx.xcconfig +19 -0
  18. package/ios/include/sherpa-onnx/c-api/c-api.h +1918 -0
  19. package/ios/include/sherpa-onnx/c-api/cxx-api.h +841 -0
  20. package/ios/sherpa-onnx-wrapper.h +57 -0
  21. package/ios/sherpa-onnx-wrapper.mm +432 -0
  22. package/lib/module/NativeSherpaOnnx.js +5 -0
  23. package/lib/module/NativeSherpaOnnx.js.map +1 -0
  24. package/lib/module/diarization/index.js +54 -0
  25. package/lib/module/diarization/index.js.map +1 -0
  26. package/lib/module/enhancement/index.js +54 -0
  27. package/lib/module/enhancement/index.js.map +1 -0
  28. package/lib/module/index.js +25 -0
  29. package/lib/module/index.js.map +1 -0
  30. package/lib/module/package.json +1 -0
  31. package/lib/module/separation/index.js +54 -0
  32. package/lib/module/separation/index.js.map +1 -0
  33. package/lib/module/stt/index.js +79 -0
  34. package/lib/module/stt/index.js.map +1 -0
  35. package/lib/module/stt/types.js +4 -0
  36. package/lib/module/stt/types.js.map +1 -0
  37. package/lib/module/tts/index.js +54 -0
  38. package/lib/module/tts/index.js.map +1 -0
  39. package/lib/module/types.js +2 -0
  40. package/lib/module/types.js.map +1 -0
  41. package/lib/module/utils.js +93 -0
  42. package/lib/module/utils.js.map +1 -0
  43. package/lib/module/vad/index.js +54 -0
  44. package/lib/module/vad/index.js.map +1 -0
  45. package/lib/typescript/package.json +1 -0
  46. package/lib/typescript/src/NativeSherpaOnnx.d.ts +39 -0
  47. package/lib/typescript/src/NativeSherpaOnnx.d.ts.map +1 -0
  48. package/lib/typescript/src/diarization/index.d.ts +49 -0
  49. package/lib/typescript/src/diarization/index.d.ts.map +1 -0
  50. package/lib/typescript/src/enhancement/index.d.ts +47 -0
  51. package/lib/typescript/src/enhancement/index.d.ts.map +1 -0
  52. package/lib/typescript/src/index.d.ts +9 -0
  53. package/lib/typescript/src/index.d.ts.map +1 -0
  54. package/lib/typescript/src/separation/index.d.ts +48 -0
  55. package/lib/typescript/src/separation/index.d.ts.map +1 -0
  56. package/lib/typescript/src/stt/index.d.ts +53 -0
  57. package/lib/typescript/src/stt/index.d.ts.map +1 -0
  58. package/lib/typescript/src/stt/types.d.ts +39 -0
  59. package/lib/typescript/src/stt/types.d.ts.map +1 -0
  60. package/lib/typescript/src/tts/index.d.ts +47 -0
  61. package/lib/typescript/src/tts/index.d.ts.map +1 -0
  62. package/lib/typescript/src/types.d.ts +59 -0
  63. package/lib/typescript/src/types.d.ts.map +1 -0
  64. package/lib/typescript/src/utils.d.ts +53 -0
  65. package/lib/typescript/src/utils.d.ts.map +1 -0
  66. package/lib/typescript/src/vad/index.d.ts +48 -0
  67. package/lib/typescript/src/vad/index.d.ts.map +1 -0
  68. package/package.json +221 -0
  69. package/scripts/copy-headers.js +184 -0
  70. package/scripts/setup-assets.js +323 -0
  71. package/scripts/setup-ios-framework.sh +282 -0
  72. package/scripts/switch-registry.js +75 -0
  73. package/src/NativeSherpaOnnx.ts +44 -0
  74. package/src/diarization/index.ts +69 -0
  75. package/src/enhancement/index.ts +67 -0
  76. package/src/index.tsx +30 -0
  77. package/src/separation/index.ts +68 -0
  78. package/src/stt/index.ts +83 -0
  79. package/src/stt/types.ts +42 -0
  80. package/src/tts/index.ts +67 -0
  81. package/src/types.ts +73 -0
  82. package/src/utils.ts +97 -0
  83. package/src/vad/index.ts +70 -0
package/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 XDcobra
4
+ Permission is hereby granted, free of charge, to any person obtaining a copy
5
+ of this software and associated documentation files (the "Software"), to deal
6
+ in the Software without restriction, including without limitation the rights
7
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ copies of the Software, and to permit persons to whom the Software is
9
+ furnished to do so, subject to the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be included in all
12
+ copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,402 @@
1
+ # react-native-sherpa-onnx
2
+
3
+ React Native SDK for sherpa-onnx - providing offline speech processing capabilities
4
+
5
+ [![npm version](https://img.shields.io/npm/v/react-native-sherpa-onnx.svg)](https://www.npmjs.com/package/react-native-sherpa-onnx)
6
+ [![npm downloads](https://img.shields.io/npm/dm/react-native-sherpa-onnx.svg)](https://www.npmjs.com/package/react-native-sherpa-onnx)
7
+ [![npm license](https://img.shields.io/npm/l/react-native-sherpa-onnx.svg)](https://www.npmjs.com/package/react-native-sherpa-onnx)
8
+ [![Android](https://img.shields.io/badge/Android-Supported-green)](https://www.android.com/)
9
+ [![iOS](https://img.shields.io/badge/iOS-Supported-blue)](https://www.apple.com/ios/)
10
+
11
+ A React Native TurboModule that provides offline speech processing capabilities using [sherpa-onnx](https://github.com/k2-fsa/sherpa-onnx). The SDK aims to support all functionalities that sherpa-onnx offers, including offline speech-to-text, text-to-speech, speaker diarization, speech enhancement, source separation, and VAD (Voice Activity Detection).
12
+
13
+ ## Feature Support
14
+
15
+ | Feature | Status |
16
+ |---------|--------|
17
+ | Offline Speech-to-Text | ✅ Supported |
18
+ | Text-to-Speech | ❌ Not yet supported |
19
+ | Speaker Diarization | ❌ Not yet supported |
20
+ | Speech Enhancement | ❌ Not yet supported |
21
+ | Source Separation | ❌ Not yet supported |
22
+ | VAD (Voice Activity Detection) | ❌ Not yet supported |
23
+
24
+ ## Platform Support Status
25
+
26
+ | Platform | Status | Notes |
27
+ |----------|--------|-------|
28
+ | **Android** | ✅ **Production Ready** | Fully tested, CI/CD automated, multiple models supported |
29
+ | **iOS** | 🟡 **Beta / Experimental** | XCFramework + Podspec ready<br/>✅ GitHub Actions builds pass<br/>❌ **No local Xcode testing** *(Windows-only dev)* |
30
+
31
+ ### 🔧 **iOS Contributors WANTED!** 🙌
32
+
33
+ **Full iOS support is a priority!** Help bring sherpa-onnx to iOS devices.
34
+
35
+ **What's ready:**
36
+ - ✅ XCFramework integration
37
+ - ✅ Podspec configuration
38
+ - ✅ GitHub Actions CI (macOS runner)
39
+ - ✅ TypeScript bindings
40
+
41
+ **What's needed:**
42
+ - **Local Xcode testing** (Simulator + Device)
43
+ - **iOS example app** (beyond CI)
44
+ - **TurboModule iOS testing**
45
+ - **Edge case testing**
46
+
47
+ ## Supported Model Types
48
+
49
+ | Model Type | `modelType` Value | Description | Download Links |
50
+ | ------------------------ | ----------------- | ---------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------ |
51
+ | **Zipformer/Transducer** | `'transducer'` | Requires `encoder.onnx`, `decoder.onnx`, `joiner.onnx`, and `tokens.txt` | [Download](https://k2-fsa.github.io/sherpa/onnx/pretrained_models/offline-transducer/index.html) |
52
+ | **Paraformer** | `'paraformer'` | Requires `model.onnx` (or `model.int8.onnx`) and `tokens.txt` | [Download](https://k2-fsa.github.io/sherpa/onnx/pretrained_models/offline-paraformer/index.html) |
53
+ | **NeMo CTC** | `'nemo_ctc'` | Requires `model.onnx` (or `model.int8.onnx`) and `tokens.txt` | [Download](https://k2-fsa.github.io/sherpa/onnx/pretrained_models/offline-ctc/nemo/index.html) |
54
+ | **Whisper** | `'whisper'` | Requires `encoder.onnx`, `decoder.onnx`, and `tokens.txt` | [Download](https://k2-fsa.github.io/sherpa/onnx/pretrained_models/whisper/index.html) |
55
+ | **WeNet CTC** | `'wenet_ctc'` | Requires `model.onnx` (or `model.int8.onnx`) and `tokens.txt` | [Download](https://k2-fsa.github.io/sherpa/onnx/pretrained_models/offline-ctc/wenet/index.html) |
56
+ | **SenseVoice** | `'sense_voice'` | Requires `model.onnx` (or `model.int8.onnx`) and `tokens.txt` | [Download](https://k2-fsa.github.io/sherpa/onnx/pretrained_models/sense-voice/index.html) |
57
+ | **FunASR Nano** | `'funasr_nano'` | Requires `encoder_adaptor.onnx`, `llm.onnx`, `embedding.onnx`, and `tokenizer` directory | [Download](https://k2-fsa.github.io/sherpa/onnx/pretrained_models/funasr-nano/index.html) |
58
+
59
+ ## Features
60
+
61
+ - ✅ **Offline Speech-to-Text** - No internet connection required for speech recognition
62
+ - ✅ **Multiple Model Types** - Supports Zipformer/Transducer, Paraformer, NeMo CTC, Whisper, WeNet CTC, SenseVoice, and FunASR Nano models
63
+ - ✅ **Model Quantization** - Automatic detection and preference for quantized (int8) models
64
+ - ✅ **Flexible Model Loading** - Asset models, file system models, or auto-detection
65
+ - ✅ **Android Support** - Fully supported on Android
66
+ - ✅ **iOS Support** - Fully supported on iOS (requires sherpa-onnx XCFramework)
67
+ - ✅ **TypeScript Support** - Full TypeScript definitions included
68
+ - 🚧 **Additional Features Coming Soon** - Text-to-Speech, Speaker Diarization, Speech Enhancement, Source Separation, and VAD support are planned for future releases
69
+
70
+ ## Installation
71
+
72
+ ```sh
73
+ npm install react-native-sherpa-onnx
74
+ ```
75
+
76
+ If your project uses Yarn (v3+) or Plug'n'Play, configure Yarn to use the Node Modules linker to avoid postinstall issues:
77
+
78
+ ```yaml
79
+ # .yarnrc.yml
80
+ nodeLinker: node-modules
81
+ ```
82
+
83
+ Alternatively, set the environment variable during install:
84
+
85
+ ```sh
86
+ YARN_NODE_LINKER=node-modules yarn install
87
+ ```
88
+
89
+ ### Android
90
+
91
+ No additional setup required. The library automatically handles native dependencies via Gradle.
92
+
93
+ ### iOS
94
+
95
+ The sherpa-onnx XCFramework is **not included in the repository or npm package** due to its size (~80MB), but **no manual action is required**! The framework is automatically downloaded during `pod install`.
96
+
97
+ #### Quick Setup
98
+
99
+ ```sh
100
+ cd example
101
+ bundle install
102
+ bundle exec pod install --project-directory=ios
103
+ ```
104
+
105
+ That's it! The `Podfile` automatically:
106
+ 1. Copies required header files from the git submodule
107
+ 2. Downloads the latest XCFramework from [GitHub Releases](https://github.com/XDcobra/react-native-sherpa-onnx/releases?q=framework)
108
+ 3. Verifies everything is in place before building
109
+
110
+ #### For Advanced Users: Building the Framework Locally
111
+
112
+ If you want to build the XCFramework yourself instead of using the prebuilt release:
113
+
114
+ ```sh
115
+ # Clone sherpa-onnx repository
116
+ git clone https://github.com/k2-fsa/sherpa-onnx.git
117
+ cd sherpa-onnx
118
+ git checkout v1.12.23
119
+
120
+ # Build the iOS XCFramework (requires macOS, Xcode, CMake, and ONNX Runtime)
121
+ ./build-ios.sh
122
+
123
+ # Copy to your project
124
+ cp -r build-ios/sherpa_onnx.xcframework /path/to/react-native-sherpa-onnx/ios/Frameworks/
125
+ ```
126
+
127
+ Then run `pod install` as usual.
128
+
129
+ **Note:** The iOS implementation uses the same C++ wrapper as Android, ensuring consistent behavior across platforms.
130
+
131
+ ## Quick Start
132
+
133
+ ```typescript
134
+ import { resolveModelPath } from 'react-native-sherpa-onnx';
135
+ import {
136
+ initializeSTT,
137
+ transcribeFile,
138
+ unloadSTT,
139
+ } from 'react-native-sherpa-onnx/stt';
140
+
141
+ // Initialize with a model
142
+ const modelPath = await resolveModelPath({
143
+ type: 'asset',
144
+ path: 'models/sherpa-onnx-model',
145
+ });
146
+
147
+ await initializeSTT({
148
+ modelPath: modelPath,
149
+ preferInt8: true, // Optional: prefer quantized models
150
+ });
151
+
152
+ // Transcribe an audio file
153
+ const transcription = await transcribeFile('path/to/audio.wav');
154
+ console.log('Transcription:', transcription);
155
+
156
+ // Release resources when done
157
+ await unloadSTT();
158
+ ```
159
+
160
+ ## Usage
161
+
162
+ ### Initialization
163
+
164
+ ```typescript
165
+ import {
166
+ initializeSherpaOnnx,
167
+ assetModelPath,
168
+ autoModelPath,
169
+ } from 'react-native-sherpa-onnx';
170
+
171
+ // Option 1: Asset model (bundled in app)
172
+ await initializeSherpaOnnx({
173
+ modelPath: assetModelPath('models/sherpa-onnx-model'),
174
+ preferInt8: true, // Prefer quantized models
175
+ });
176
+
177
+ // Option 2: Auto-detect (tries asset, then file system)
178
+ await initializeSherpaOnnx({
179
+ modelPath: autoModelPath('models/sherpa-onnx-model'),
180
+ });
181
+
182
+ // Option 3: Simple string (backward compatible)
183
+ await initializeSherpaOnnx('models/sherpa-onnx-model');
184
+ ```
185
+
186
+ ### Transcription (Speech-to-Text)
187
+
188
+ ```typescript
189
+ import { transcribeFile } from 'react-native-sherpa-onnx/stt';
190
+
191
+ // Transcribe a WAV file (16kHz, mono, 16-bit PCM)
192
+ const result = await transcribeFile('path/to/audio.wav');
193
+ console.log('Transcription:', result);
194
+ ```
195
+
196
+ ### Model Quantization
197
+
198
+ Control whether to prefer quantized (int8) or regular models:
199
+
200
+ ```typescript
201
+ import { initializeSTT } from 'react-native-sherpa-onnx/stt';
202
+ import { resolveModelPath } from 'react-native-sherpa-onnx';
203
+
204
+ const modelPath = await resolveModelPath({
205
+ type: 'asset',
206
+ path: 'models/my-model',
207
+ });
208
+
209
+ // Default: try int8 first, then regular
210
+ await initializeSTT({ modelPath });
211
+
212
+ // Explicitly prefer int8 models (smaller, faster)
213
+ await initializeSTT({
214
+ modelPath,
215
+ preferInt8: true,
216
+ });
217
+
218
+ // Explicitly prefer regular models (higher accuracy)
219
+ await initializeSTT({
220
+ modelPath,
221
+ preferInt8: false,
222
+ });
223
+ ```
224
+
225
+ ### Explicit Model Type
226
+
227
+ For robustness, you can explicitly specify the model type to avoid auto-detection issues:
228
+
229
+ ```typescript
230
+ import { initializeSTT } from 'react-native-sherpa-onnx/stt';
231
+ import { resolveModelPath } from 'react-native-sherpa-onnx';
232
+
233
+ const modelPath = await resolveModelPath({
234
+ type: 'asset',
235
+ path: 'models/sherpa-onnx-nemo-parakeet-tdt-ctc-en',
236
+ });
237
+
238
+ // Explicitly specify model type
239
+ await initializeSTT({
240
+ modelPath,
241
+ modelType: 'nemo_ctc', // 'transducer', 'paraformer', 'nemo_ctc', 'whisper', 'wenet_ctc', 'sense_voice', 'funasr_nano'
242
+ });
243
+
244
+ // Auto-detection (default behavior)
245
+ await initializeSTT({
246
+ modelPath,
247
+ // modelType defaults to 'auto'
248
+ });
249
+ ```
250
+
251
+ ### Cleanup (Speech-to-Text)
252
+
253
+ ```typescript
254
+ import { unloadSTT } from 'react-native-sherpa-onnx/stt';
255
+
256
+ // Release resources when done
257
+ await unloadSTT();
258
+ ```
259
+
260
+ ## Model Setup
261
+
262
+ The library does **not** bundle models. You must provide your own models. See [MODEL_SETUP.md](./MODEL_SETUP.md) for detailed setup instructions.
263
+
264
+ ### Model File Requirements
265
+
266
+ - **Zipformer/Transducer**: Requires `encoder.onnx`, `decoder.onnx`, `joiner.onnx`, and `tokens.txt`
267
+ - **Paraformer**: Requires `model.onnx` (or `model.int8.onnx`) and `tokens.txt`
268
+ - **NeMo CTC**: Requires `model.onnx` (or `model.int8.onnx`) and `tokens.txt`
269
+ - **Whisper**: Requires `encoder.onnx`, `decoder.onnx`, and `tokens.txt`
270
+ - **WeNet CTC**: Requires `model.onnx` (or `model.int8.onnx`) and `tokens.txt`
271
+ - **SenseVoice**: Requires `model.onnx` (or `model.int8.onnx`) and `tokens.txt`
272
+
273
+ ### Model Files
274
+
275
+ Place models in:
276
+
277
+ - **Android**: `android/app/src/main/assets/models/`
278
+ - **iOS**: Add to Xcode project as folder reference
279
+
280
+ ## API Reference
281
+
282
+ ### Speech-to-Text (STT) Module
283
+
284
+ Import from `react-native-sherpa-onnx/stt`:
285
+
286
+ #### `initializeSTT(options)`
287
+
288
+ Initialize the speech-to-text engine with a model.
289
+
290
+ **Parameters:**
291
+
292
+ - `options.modelPath`: Absolute path to the model directory
293
+ - `options.preferInt8` (optional): Prefer quantized models (`true`), regular models (`false`), or auto-detect (`undefined`, default)
294
+ - `options.modelType` (optional): Explicit model type (`'transducer'`, `'paraformer'`, `'nemo_ctc'`, `'whisper'`, `'wenet_ctc'`, `'sense_voice'`, `'funasr_nano'`), or auto-detect (`'auto'`, default)
295
+
296
+ **Returns:** `Promise<void>`
297
+
298
+ #### `transcribeFile(filePath)`
299
+
300
+ Transcribe an audio file.
301
+
302
+ **Parameters:**
303
+
304
+ - `filePath`: Path to WAV file (16kHz, mono, 16-bit PCM)
305
+
306
+ **Returns:** `Promise<string>` - Transcribed text
307
+
308
+ #### `unloadSTT()`
309
+
310
+ Release resources and unload the speech-to-text model.
311
+
312
+ **Returns:** `Promise<void>`
313
+
314
+ ### Utility Functions
315
+
316
+ Import from `react-native-sherpa-onnx`:
317
+
318
+ #### `resolveModelPath(config)`
319
+
320
+ Resolve a model path configuration to an absolute path.
321
+
322
+ **Parameters:**
323
+
324
+ - `config.type`: Path type (`'asset'`, `'file'`, or `'auto'`)
325
+ - `config.path`: Path to resolve (relative for assets, absolute for files)
326
+
327
+ **Returns:** `Promise<string>` - Absolute path to model directory
328
+
329
+ #### `testSherpaInit()`
330
+
331
+ Test that the sherpa-onnx native module is properly loaded.
332
+
333
+ **Returns:** `Promise<string>` - Test message confirming module is loaded
334
+
335
+ ## Requirements
336
+
337
+ - React Native >= 0.70
338
+ - Android API 24+ (Android 7.0+)
339
+ - iOS 13.0+ (requires sherpa-onnx XCFramework - see iOS Setup below)
340
+
341
+ ## Example Apps
342
+
343
+ We provide example applications to help you get started with `react-native-sherpa-onnx`:
344
+
345
+ ### Example App (Audio to Text)
346
+
347
+ The example app included in this repository demonstrates basic audio-to-text transcription capabilities. It includes:
348
+
349
+ - Multiple model type support (Zipformer, Paraformer, NeMo CTC, Whisper, WeNet CTC, SenseVoice, FunASR Nano)
350
+ - Model selection and configuration
351
+ - Audio file transcription
352
+ - Test audio files for different languages
353
+
354
+ **Getting started:**
355
+
356
+ ```sh
357
+ cd example
358
+ yarn install
359
+ yarn android # or yarn ios
360
+ ```
361
+
362
+ <div align="center">
363
+ <img src="./docs/images/example_home_screen.png" alt="Model selection home screen" width="30%" />
364
+ <img src="./docs/images/example_english.png" alt="Transcribe english audio" width="30%" />
365
+ <img src="./docs/images/example_multilanguage.png" alt="Transcribe english and chinese audio" width="30%" />
366
+ </div>
367
+
368
+ ### Video to Text Comparison App
369
+
370
+ A comprehensive comparison app that demonstrates video-to-text transcription using `react-native-sherpa-onnx` alongside other speech-to-text solutions:
371
+
372
+ **Repository:** [mobile-videototext-comparison](https://github.com/XDcobra/mobile-videototext-comparison)
373
+
374
+ **Features:**
375
+
376
+ - Video to audio conversion (using native APIs)
377
+ - Audio to text transcription
378
+ - Video to text (video --> WAV --> text)
379
+ - Comparison between different STT providers
380
+ - Performance benchmarking
381
+
382
+ This app showcases how to integrate `react-native-sherpa-onnx` into a real-world application that processes video files and converts them to text.
383
+
384
+ <div align="center">
385
+ <img src="./docs/images/vtt_model_overview.png" alt="Video-to-Text Model Overview" width="30%" />
386
+ <img src="./docs/images/vtt_result_file_picker.png" alt="Video-to-Text file picker" width="30%" />
387
+ <img src="./docs/images/vtt_result_test_audio.png" alt="Video-to-Text test audio" width="30%" />
388
+ </div>
389
+
390
+ ## Contributing
391
+
392
+ - [Development workflow](CONTRIBUTING.md#development-workflow)
393
+ - [Sending a pull request](CONTRIBUTING.md#sending-a-pull-request)
394
+ - [Code of conduct](CODE_OF_CONDUCT.md)
395
+
396
+ ## License
397
+
398
+ MIT
399
+
400
+ ---
401
+
402
+ Made with [create-react-native-library](https://github.com/callstack/react-native-builder-bob)
@@ -0,0 +1,84 @@
1
+ require "json"
2
+
3
+ package = JSON.parse(File.read(File.join(__dir__, "package.json")))
4
+
5
+ # Compute absolute paths
6
+ pod_root = __dir__
7
+ ios_include_path = File.join(pod_root, 'ios', 'include')
8
+ framework_path = File.join(pod_root, 'ios', 'Frameworks', 'sherpa_onnx.xcframework')
9
+
10
+ Pod::Spec.new do |s|
11
+ s.name = "SherpaOnnx"
12
+ s.version = package["version"]
13
+ s.summary = package["description"]
14
+ s.homepage = package["homepage"]
15
+ s.license = package["license"]
16
+ s.authors = package["author"]
17
+
18
+ s.platforms = { :ios => min_ios_version_supported }
19
+ s.source = { :git => "https://github.com/XDcobra/react-native-sherpa-onnx.git", :tag => "#{s.version}" }
20
+
21
+ # Source files (implementation)
22
+ # Include .cc for cxx-api.cc (C++ wrapper around C API)
23
+ s.source_files = "ios/**/*.{h,m,mm,swift,cpp,cc}"
24
+
25
+ # Private headers (our wrapper headers)
26
+ s.private_header_files = [
27
+ "ios/*.h",
28
+ "ios/include/**/*.h"
29
+ ]
30
+
31
+ # Link with required frameworks and libraries
32
+ # CoreML is required by ONNX Runtime's CoreML execution provider
33
+ s.frameworks = 'Foundation', 'Accelerate', 'CoreML'
34
+ s.libraries = 'c++'
35
+
36
+ # Note: Header files and framework are set up by postinstall script (yarn setup-assets)
37
+ # This runs automatically after yarn/npm install and handles all setup tasks
38
+
39
+ # Verify XCFramework exists
40
+ unless File.exist?(framework_path)
41
+ raise <<~MSG
42
+ [SherpaOnnx] ERROR: iOS Framework not found.
43
+
44
+ The sherpa-onnx XCFramework should have been downloaded automatically during pod install.
45
+ If the automatic download failed, you can manually download it by running:
46
+
47
+ yarn download-ios-framework
48
+
49
+ Or download from GitHub Releases:
50
+ https://github.com/XDcobra/react-native-sherpa-onnx/releases?q=framework
51
+
52
+ Then extract to: #{framework_path}
53
+ MSG
54
+ end
55
+
56
+ # Log paths for debugging (visible during pod install)
57
+ puts "[SherpaOnnx] Pod root: #{pod_root}"
58
+ puts "[SherpaOnnx] Include path: #{ios_include_path}"
59
+ puts "[SherpaOnnx] Framework path: #{framework_path}"
60
+ framework_version = File.read(File.join(pod_root, 'ios', 'Frameworks', '.framework-version')).strip rescue 'unknown'
61
+ puts "[SherpaOnnx] Framework version: #{framework_version}"
62
+
63
+ # Use vendored_frameworks for the XCFramework
64
+ s.vendored_frameworks = 'ios/Frameworks/sherpa_onnx.xcframework'
65
+
66
+ # Preserve headers and config files
67
+ s.preserve_paths = [
68
+ 'ios/SherpaOnnx.xcconfig',
69
+ 'ios/include/**/*'
70
+ ]
71
+
72
+ s.pod_target_xcconfig = {
73
+ 'CLANG_CXX_LANGUAGE_STANDARD' => 'c++17',
74
+ 'CLANG_CXX_LIBRARY' => 'libc++',
75
+ 'HEADER_SEARCH_PATHS' => "$(inherited) \"#{ios_include_path}\"",
76
+ }
77
+
78
+ s.user_target_xcconfig = {
79
+ 'CLANG_CXX_LANGUAGE_STANDARD' => 'c++17',
80
+ 'CLANG_CXX_LIBRARY' => 'libc++',
81
+ }
82
+
83
+ install_modules_dependencies(s)
84
+ end
@@ -0,0 +1,193 @@
1
+ // Configurable sherpa-onnx version (default: 1.12.23)
2
+ def sherpaOnnxVersion = project.hasProperty('sherpaOnnxVersion') ? project.sherpaOnnxVersion : '1.12.23'
3
+
4
+ buildscript {
5
+ ext.SherpaOnnx = [
6
+ kotlinVersion: "2.0.21",
7
+ minSdkVersion: 24,
8
+ compileSdkVersion: 36,
9
+ targetSdkVersion: 36
10
+ ]
11
+
12
+ ext.getExtOrDefault = { prop ->
13
+ if (rootProject.ext.has(prop)) {
14
+ return rootProject.ext.get(prop)
15
+ }
16
+
17
+ return SherpaOnnx[prop]
18
+ }
19
+
20
+ repositories {
21
+ google()
22
+ mavenCentral()
23
+ }
24
+
25
+ dependencies {
26
+ classpath "com.android.tools.build:gradle:8.7.2"
27
+ // noinspection DifferentKotlinGradleVersion
28
+ classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:${getExtOrDefault('kotlinVersion')}"
29
+ }
30
+ }
31
+
32
+
33
+ apply plugin: "com.android.library"
34
+ apply plugin: "kotlin-android"
35
+
36
+ apply plugin: "com.facebook.react"
37
+
38
+ android {
39
+ namespace "com.sherpaonnx"
40
+
41
+ compileSdkVersion getExtOrDefault("compileSdkVersion")
42
+
43
+ defaultConfig {
44
+ minSdkVersion getExtOrDefault("minSdkVersion")
45
+ targetSdkVersion getExtOrDefault("targetSdkVersion")
46
+
47
+ // NDK configuration
48
+ ndkVersion getExtOrDefault("ndkVersion")
49
+ externalNativeBuild {
50
+ cmake {
51
+ cppFlags "-std=c++17", "-Wall", "-Wextra", "-fvisibility=hidden"
52
+ arguments "-DANDROID_STL=c++_shared"
53
+ }
54
+ }
55
+
56
+ // Supported ABIs
57
+ ndk {
58
+ abiFilters "arm64-v8a", "armeabi-v7a", "x86", "x86_64"
59
+ }
60
+ }
61
+
62
+ buildFeatures {
63
+ buildConfig true
64
+ }
65
+
66
+ // CMake configuration
67
+ externalNativeBuild {
68
+ cmake {
69
+ path "src/main/cpp/CMakeLists.txt"
70
+ version "3.22.1"
71
+ }
72
+ }
73
+
74
+ buildTypes {
75
+ release {
76
+ minifyEnabled false
77
+ }
78
+ }
79
+
80
+ lint {
81
+ disable "GradleCompatible"
82
+ }
83
+
84
+ compileOptions {
85
+ sourceCompatibility JavaVersion.VERSION_1_8
86
+ targetCompatibility JavaVersion.VERSION_1_8
87
+ }
88
+ }
89
+
90
+
91
+ repositories {
92
+ mavenCentral()
93
+ google()
94
+ maven { url 'https://jitpack.io' }
95
+ }
96
+
97
+ def kotlin_version = getExtOrDefault("kotlinVersion")
98
+
99
+ dependencies {
100
+ implementation "com.facebook.react:react-android"
101
+ implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
102
+
103
+ // sherpa-onnx prebuilt AAR from JitPack
104
+ // This includes the native .so libraries for all ABIs
105
+ implementation "com.github.k2-fsa:sherpa-onnx:v${sherpaOnnxVersion}"
106
+ }
107
+
108
+ // Create resolvable configuration for extraction
109
+ configurations {
110
+ extractNativeLibs {
111
+ canBeResolved = true
112
+ canBeConsumed = false
113
+ }
114
+ }
115
+
116
+ dependencies {
117
+ extractNativeLibs "com.github.k2-fsa:sherpa-onnx:v${sherpaOnnxVersion}"
118
+ }
119
+
120
+ // Extract native libraries from AAR before CMake runs
121
+ def extractNativeLibs = tasks.register("extractNativeLibs") {
122
+ doLast {
123
+ def extractedLibsDir = file("${buildDir}/extracted_native_libs")
124
+ extractedLibsDir.mkdirs()
125
+
126
+ def resolvedConfig = configurations.extractNativeLibs.resolvedConfiguration
127
+ def foundAar = false
128
+
129
+ resolvedConfig.resolvedArtifacts.each { artifact ->
130
+ def aarFile = artifact.file
131
+ println "Checking artifact: ${aarFile.name} (exists: ${aarFile.exists()})"
132
+
133
+ if (aarFile.exists() && (aarFile.name.endsWith(".aar") || aarFile.name.endsWith(".jar"))) {
134
+ foundAar = true
135
+ println "Extracting native libraries from: ${aarFile.name}"
136
+
137
+ copy {
138
+ from(zipTree(aarFile)) {
139
+ include "jni/**/*.so"
140
+ }
141
+ into extractedLibsDir
142
+ }
143
+
144
+ // Verify extraction succeeded
145
+ def extractedFiles = fileTree(extractedLibsDir).matching { include "**/*.so" }
146
+ if (extractedFiles.isEmpty()) {
147
+ println "WARNING: No .so files extracted from ${aarFile.name}"
148
+ println "Contents of AAR:"
149
+ zipTree(aarFile).each { entry ->
150
+ if (entry.name.contains("jni") || entry.name.endsWith(".so")) {
151
+ println " ${entry.name}"
152
+ }
153
+ }
154
+ }
155
+ }
156
+ }
157
+
158
+ if (!foundAar) {
159
+ throw new RuntimeException("No AAR file found for sherpa-onnx. Check if the dependency is correctly resolved.")
160
+ }
161
+ }
162
+ }
163
+
164
+ // NOTE: Header files are now set up by postinstall script (yarn setup-assets)
165
+ // This runs automatically after yarn/npm install and handles copying headers
166
+ // We no longer need a Gradle task for this - headers will be present when build starts
167
+
168
+ // Task to check and log header source before CMake runs
169
+ def checkHeaderSource = tasks.register("checkHeaderSource") {
170
+ doLast {
171
+ def cppDir = file("src/main/cpp")
172
+ def bundledHeaderPath = file("${cppDir}/include/sherpa-onnx/c-api/cxx-api.h")
173
+
174
+ if (bundledHeaderPath.exists()) {
175
+ println "[SherpaOnnx] Header files present"
176
+ } else {
177
+ println "[SherpaOnnx] ERROR: Header files not found at ${bundledHeaderPath.absolutePath}"
178
+ throw new RuntimeException("Header files not found. Run 'yarn setup-assets' or 'yarn copy-headers'")
179
+ }
180
+ }
181
+ }
182
+
183
+ // Make CMake depend on extraction and header verification - ensure they run before any CMake task
184
+ afterEvaluate {
185
+ tasks.matching { it.name.contains("configureCMake") || it.name.contains("externalNativeBuild") }.configureEach {
186
+ dependsOn extractNativeLibs
187
+ dependsOn checkHeaderSource
188
+ }
189
+
190
+ // Also ensure all extraction and verification tasks run before preBuild
191
+ preBuild.dependsOn extractNativeLibs
192
+ preBuild.dependsOn checkHeaderSource
193
+ }