react-native-sherpa-onnx 0.2.0 → 0.3.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.
- package/README.md +232 -236
- package/SherpaOnnx.podspec +68 -64
- package/android/build.gradle +182 -192
- package/android/codegen.gradle +57 -0
- package/android/prebuilt-download.gradle +428 -0
- package/android/prebuilt-versions.gradle +43 -0
- package/android/proguard-rules.pro +10 -0
- package/android/src/main/assets/testModels/add_mul_add.onnx +28 -0
- package/android/src/main/assets/testModels/nnapi_internal_uint8_support.onnx +0 -0
- package/android/src/main/assets/testModels/qnn_multi_ctx_embed.onnx +0 -0
- package/android/src/main/cpp/CMakeLists.txt +166 -129
- package/android/src/main/cpp/CMakePresets.json +54 -0
- package/android/src/main/cpp/crypto/sha256.cpp +174 -0
- package/android/src/main/cpp/crypto/sha256.h +16 -0
- package/android/src/main/cpp/jni/archive/sherpa-onnx-archive-helper.cpp +404 -0
- package/android/src/main/cpp/jni/archive/sherpa-onnx-archive-helper.h +56 -0
- package/android/src/main/cpp/jni/archive/sherpa-onnx-archive-jni.cpp +181 -0
- package/android/src/main/cpp/jni/audio/sherpa-onnx-audio-convert-jni.cpp +888 -0
- package/{ios → android/src/main/cpp/jni/model_detect}/sherpa-onnx-common.h +18 -18
- package/android/src/main/cpp/jni/model_detect/sherpa-onnx-detect-jni-common.cpp +86 -0
- package/android/src/main/cpp/jni/model_detect/sherpa-onnx-detect-jni-common.h +20 -0
- package/android/src/main/cpp/jni/model_detect/sherpa-onnx-model-detect-helper.cpp +423 -0
- package/android/src/main/cpp/jni/model_detect/sherpa-onnx-model-detect-helper.h +55 -0
- package/android/src/main/cpp/jni/model_detect/sherpa-onnx-model-detect-stt.cpp +399 -0
- package/android/src/main/cpp/jni/model_detect/sherpa-onnx-model-detect-tts.cpp +238 -0
- package/{ios → android/src/main/cpp/jni/model_detect}/sherpa-onnx-model-detect.h +122 -89
- package/android/src/main/cpp/jni/model_detect/sherpa-onnx-stt-wrapper.cpp +99 -0
- package/android/src/main/cpp/jni/model_detect/sherpa-onnx-stt-wrapper.h +16 -0
- package/android/src/main/cpp/jni/model_detect/sherpa-onnx-tts-wrapper.cpp +78 -0
- package/android/src/main/cpp/jni/model_detect/sherpa-onnx-tts-wrapper.h +16 -0
- package/android/src/main/cpp/jni/module/sherpa-onnx-module-jni.cpp +190 -0
- package/android/src/main/cpp/jni/tts/sherpa-onnx-tts-zipvoice-jni.cpp +301 -0
- package/android/src/main/java/com/sherpaonnx/SherpaOnnxArchiveHelper.kt +94 -0
- package/android/src/main/java/com/sherpaonnx/{SherpaOnnxCoreHelper.kt → SherpaOnnxAssetHelper.kt} +350 -236
- package/android/src/main/java/com/sherpaonnx/SherpaOnnxModule.kt +791 -483
- package/android/src/main/java/com/sherpaonnx/SherpaOnnxSttHelper.kt +699 -109
- package/android/src/main/java/com/sherpaonnx/SherpaOnnxTtsHelper.kt +1123 -668
- package/android/src/main/java/com/sherpaonnx/ZipvoiceTtsWrapper.kt +187 -0
- package/ios/SherpaOnnx+Assets.h +11 -0
- package/ios/SherpaOnnx+Assets.mm +325 -0
- package/ios/SherpaOnnx+STT.mm +455 -118
- package/ios/SherpaOnnx+TTS.mm +1101 -712
- package/ios/SherpaOnnx.h +17 -6
- package/ios/SherpaOnnx.mm +206 -311
- package/ios/SherpaOnnx.xcconfig +19 -19
- package/ios/SherpaOnnxCoreMLHelper.swift +24 -0
- package/ios/archive/sherpa-onnx-archive-helper.h +21 -0
- package/ios/archive/sherpa-onnx-archive-helper.mm +296 -0
- package/ios/libarchive_darwin_config.h +153 -0
- package/{android/src/main/cpp/jni → ios/model_detect}/sherpa-onnx-common.h +18 -18
- package/ios/model_detect/sherpa-onnx-model-detect-helper.h +49 -0
- package/ios/model_detect/sherpa-onnx-model-detect-helper.mm +210 -0
- package/ios/model_detect/sherpa-onnx-model-detect-stt.mm +344 -0
- package/ios/model_detect/sherpa-onnx-model-detect-tts.mm +201 -0
- package/{android/src/main/cpp/jni → ios/model_detect}/sherpa-onnx-model-detect.h +117 -89
- package/ios/scripts/patch-libarchive-includes.sh +61 -0
- package/ios/scripts/setup-ios-libarchive.sh +98 -0
- package/ios/stt/sherpa-onnx-stt-wrapper.h +129 -0
- package/ios/stt/sherpa-onnx-stt-wrapper.mm +523 -0
- package/ios/{sherpa-onnx-tts-wrapper.h → tts/sherpa-onnx-tts-wrapper.h} +90 -85
- package/ios/{sherpa-onnx-tts-wrapper.mm → tts/sherpa-onnx-tts-wrapper.mm} +376 -345
- package/lib/module/NativeSherpaOnnx.js +3 -0
- package/lib/module/NativeSherpaOnnx.js.map +1 -1
- package/lib/module/audio/index.js +22 -0
- package/lib/module/audio/index.js.map +1 -0
- package/lib/module/diarization/index.js +1 -1
- package/lib/module/diarization/index.js.map +1 -1
- package/lib/module/download/ModelDownloadManager.js +918 -0
- package/lib/module/download/ModelDownloadManager.js.map +1 -0
- package/lib/module/download/extractTarBz2.js +53 -0
- package/lib/module/download/extractTarBz2.js.map +1 -0
- package/lib/module/download/index.js +6 -0
- package/lib/module/download/index.js.map +1 -0
- package/lib/module/download/validation.js +178 -0
- package/lib/module/download/validation.js.map +1 -0
- package/lib/module/enhancement/index.js +1 -1
- package/lib/module/enhancement/index.js.map +1 -1
- package/lib/module/index.js +41 -3
- package/lib/module/index.js.map +1 -1
- package/lib/module/separation/index.js +1 -1
- package/lib/module/separation/index.js.map +1 -1
- package/lib/module/stt/index.js +127 -60
- package/lib/module/stt/index.js.map +1 -1
- package/lib/module/stt/sttModelLanguages.js +512 -0
- package/lib/module/stt/sttModelLanguages.js.map +1 -0
- package/lib/module/stt/types.js +53 -1
- package/lib/module/stt/types.js.map +1 -1
- package/lib/module/tts/index.js +216 -289
- package/lib/module/tts/index.js.map +1 -1
- package/lib/module/tts/types.js +86 -1
- package/lib/module/tts/types.js.map +1 -1
- package/lib/module/types.js.map +1 -1
- package/lib/module/utils.js +86 -73
- package/lib/module/utils.js.map +1 -1
- package/lib/module/vad/index.js +1 -1
- package/lib/module/vad/index.js.map +1 -1
- package/lib/typescript/src/NativeSherpaOnnx.d.ts +192 -38
- package/lib/typescript/src/NativeSherpaOnnx.d.ts.map +1 -1
- package/lib/typescript/src/audio/index.d.ts +13 -0
- package/lib/typescript/src/audio/index.d.ts.map +1 -0
- package/lib/typescript/src/diarization/index.d.ts +3 -2
- package/lib/typescript/src/diarization/index.d.ts.map +1 -1
- package/lib/typescript/src/download/ModelDownloadManager.d.ts +108 -0
- package/lib/typescript/src/download/ModelDownloadManager.d.ts.map +1 -0
- package/lib/typescript/src/download/extractTarBz2.d.ts +14 -0
- package/lib/typescript/src/download/extractTarBz2.d.ts.map +1 -0
- package/lib/typescript/src/download/index.d.ts +7 -0
- package/lib/typescript/src/download/index.d.ts.map +1 -0
- package/lib/typescript/src/download/validation.d.ts +57 -0
- package/lib/typescript/src/download/validation.d.ts.map +1 -0
- package/lib/typescript/src/enhancement/index.d.ts +3 -2
- package/lib/typescript/src/enhancement/index.d.ts.map +1 -1
- package/lib/typescript/src/index.d.ts +26 -2
- package/lib/typescript/src/index.d.ts.map +1 -1
- package/lib/typescript/src/separation/index.d.ts +3 -2
- package/lib/typescript/src/separation/index.d.ts.map +1 -1
- package/lib/typescript/src/stt/index.d.ts +31 -43
- package/lib/typescript/src/stt/index.d.ts.map +1 -1
- package/lib/typescript/src/stt/sttModelLanguages.d.ts +52 -0
- package/lib/typescript/src/stt/sttModelLanguages.d.ts.map +1 -0
- package/lib/typescript/src/stt/types.d.ts +196 -9
- package/lib/typescript/src/stt/types.d.ts.map +1 -1
- package/lib/typescript/src/tts/index.d.ts +25 -211
- package/lib/typescript/src/tts/index.d.ts.map +1 -1
- package/lib/typescript/src/tts/types.d.ts +148 -25
- package/lib/typescript/src/tts/types.d.ts.map +1 -1
- package/lib/typescript/src/types.d.ts +0 -32
- package/lib/typescript/src/types.d.ts.map +1 -1
- package/lib/typescript/src/utils.d.ts +28 -13
- package/lib/typescript/src/utils.d.ts.map +1 -1
- package/lib/typescript/src/vad/index.d.ts +3 -2
- package/lib/typescript/src/vad/index.d.ts.map +1 -1
- package/package.json +250 -222
- package/scripts/check-qnn-support.sh +78 -0
- package/scripts/setup-ios-framework.sh +379 -282
- package/src/NativeSherpaOnnx.ts +474 -251
- package/src/audio/index.ts +32 -0
- package/src/diarization/index.ts +4 -2
- package/src/download/ModelDownloadManager.ts +1325 -0
- package/src/download/extractTarBz2.ts +78 -0
- package/src/download/index.ts +43 -0
- package/src/download/validation.ts +279 -0
- package/src/enhancement/index.ts +4 -2
- package/src/index.tsx +78 -27
- package/src/separation/index.ts +4 -2
- package/src/stt/index.ts +249 -89
- package/src/stt/sttModelLanguages.ts +237 -0
- package/src/stt/types.ts +263 -9
- package/src/tts/index.ts +470 -458
- package/src/tts/types.ts +373 -218
- package/src/types.ts +0 -44
- package/src/utils.ts +145 -131
- package/src/vad/index.ts +4 -2
- package/third_party/ffmpeg_prebuilt/ANDROID_RELEASE_TAG +1 -0
- package/third_party/libarchive_prebuilt/ANDROID_RELEASE_TAG +1 -0
- package/third_party/libarchive_prebuilt/IOS_RELEASE_TAG +1 -0
- package/third_party/sherpa-onnx-prebuilt/ANDROID_RELEASE_TAG +1 -0
- package/third_party/sherpa-onnx-prebuilt/IOS_RELEASE_TAG +1 -0
- package/android/src/main/cpp/include/sherpa-onnx/c-api/c-api.h +0 -1918
- package/android/src/main/cpp/include/sherpa-onnx/c-api/cxx-api.h +0 -841
- package/android/src/main/cpp/jni/sherpa-onnx-model-detect.cpp +0 -541
- package/android/src/main/cpp/jni/sherpa-onnx-stt-jni.cpp +0 -336
- package/android/src/main/cpp/jni/sherpa-onnx-stt-wrapper.cpp +0 -222
- package/android/src/main/cpp/jni/sherpa-onnx-stt-wrapper.h +0 -68
- package/android/src/main/cpp/jni/sherpa-onnx-tts-jni.cpp +0 -823
- package/android/src/main/cpp/jni/sherpa-onnx-tts-wrapper.cpp +0 -387
- package/android/src/main/cpp/jni/sherpa-onnx-tts-wrapper.h +0 -147
- package/ios/Frameworks/sherpa_onnx.xcframework.zip +0 -0
- package/ios/include/sherpa-onnx/c-api/c-api.h +0 -1918
- package/ios/include/sherpa-onnx/c-api/cxx-api.h +0 -841
- package/ios/sherpa-onnx-model-detect.mm +0 -441
- package/ios/sherpa-onnx-stt-wrapper.h +0 -48
- package/ios/sherpa-onnx-stt-wrapper.mm +0 -201
- package/scripts/copy-headers.js +0 -184
- package/scripts/setup-assets.js +0 -323
package/scripts/copy-headers.js
DELETED
|
@@ -1,184 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Script to copy sherpa-onnx header files to Android and iOS include directories.
|
|
5
|
-
* This ensures that the headers are available when the package is published to npm,
|
|
6
|
-
* even if the git submodule is not initialized.
|
|
7
|
-
*/
|
|
8
|
-
|
|
9
|
-
const fs = require('fs');
|
|
10
|
-
const path = require('path');
|
|
11
|
-
|
|
12
|
-
const SOURCE_DIR = path.join(
|
|
13
|
-
__dirname,
|
|
14
|
-
'..',
|
|
15
|
-
'sherpa-onnx',
|
|
16
|
-
'sherpa-onnx',
|
|
17
|
-
'c-api'
|
|
18
|
-
);
|
|
19
|
-
const ANDROID_DEST_DIR = path.join(
|
|
20
|
-
__dirname,
|
|
21
|
-
'..',
|
|
22
|
-
'android',
|
|
23
|
-
'src',
|
|
24
|
-
'main',
|
|
25
|
-
'cpp',
|
|
26
|
-
'include',
|
|
27
|
-
'sherpa-onnx',
|
|
28
|
-
'c-api'
|
|
29
|
-
);
|
|
30
|
-
const IOS_DEST_DIR = path.join(
|
|
31
|
-
__dirname,
|
|
32
|
-
'..',
|
|
33
|
-
'ios',
|
|
34
|
-
'include',
|
|
35
|
-
'sherpa-onnx',
|
|
36
|
-
'c-api'
|
|
37
|
-
);
|
|
38
|
-
|
|
39
|
-
const HEADER_FILES = ['c-api.h', 'cxx-api.h'];
|
|
40
|
-
|
|
41
|
-
// C++ API implementation file needed for iOS (compiles the C++ wrapper around C API)
|
|
42
|
-
const CXX_IMPL_FILE = 'cxx-api.cc';
|
|
43
|
-
const IOS_ROOT_DIR = path.join(__dirname, '..', 'ios');
|
|
44
|
-
|
|
45
|
-
function ensureDirectoryExists(dirPath) {
|
|
46
|
-
if (!fs.existsSync(dirPath)) {
|
|
47
|
-
fs.mkdirSync(dirPath, { recursive: true });
|
|
48
|
-
console.log(`Created directory: ${dirPath}`);
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
function copyFile(source, destination) {
|
|
53
|
-
try {
|
|
54
|
-
fs.copyFileSync(source, destination);
|
|
55
|
-
console.log(
|
|
56
|
-
`Copied: ${path.basename(source)} -> ${path.relative(
|
|
57
|
-
process.cwd(),
|
|
58
|
-
destination
|
|
59
|
-
)}`
|
|
60
|
-
);
|
|
61
|
-
return true;
|
|
62
|
-
} catch (error) {
|
|
63
|
-
console.error(`Failed to copy ${source}:`, error.message);
|
|
64
|
-
return false;
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
function areHeadersAlreadyPresent() {
|
|
69
|
-
// Check if all critical headers are already in the destination directories
|
|
70
|
-
const requiredFiles = [
|
|
71
|
-
path.join(ANDROID_DEST_DIR, 'c-api.h'),
|
|
72
|
-
path.join(IOS_DEST_DIR, 'c-api.h'),
|
|
73
|
-
path.join(IOS_DEST_DIR, 'cxx-api.h'),
|
|
74
|
-
];
|
|
75
|
-
|
|
76
|
-
return requiredFiles.every((file) => fs.existsSync(file));
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
function main() {
|
|
80
|
-
console.log('Checking sherpa-onnx header files...\n');
|
|
81
|
-
|
|
82
|
-
// Check if headers are already present (e.g., from npm package)
|
|
83
|
-
if (areHeadersAlreadyPresent()) {
|
|
84
|
-
console.log('Header files already present, skipping copy.');
|
|
85
|
-
console.log(' Android: android/src/main/cpp/include/sherpa-onnx/c-api/');
|
|
86
|
-
console.log(' iOS: ios/include/sherpa-onnx/c-api/');
|
|
87
|
-
return;
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
console.log(
|
|
91
|
-
'Header files not found, attempting to copy from git submodule...\n'
|
|
92
|
-
);
|
|
93
|
-
|
|
94
|
-
// Check if source directory exists
|
|
95
|
-
if (!fs.existsSync(SOURCE_DIR)) {
|
|
96
|
-
console.error(`Error: Source directory not found: ${SOURCE_DIR}`);
|
|
97
|
-
console.error('Possible causes:');
|
|
98
|
-
console.error(' 1. Git submodule is not initialized');
|
|
99
|
-
console.error(
|
|
100
|
-
' 2. You are using an npm package (headers should already be included)'
|
|
101
|
-
);
|
|
102
|
-
console.error('');
|
|
103
|
-
console.error('Solutions:');
|
|
104
|
-
console.error(
|
|
105
|
-
' • Initialize submodule: git submodule update --init --recursive'
|
|
106
|
-
);
|
|
107
|
-
console.error(
|
|
108
|
-
' • Check if headers exist in ios/include/ or android/.../include/'
|
|
109
|
-
);
|
|
110
|
-
process.exit(1);
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
// Ensure destination directories exist
|
|
114
|
-
ensureDirectoryExists(ANDROID_DEST_DIR);
|
|
115
|
-
ensureDirectoryExists(IOS_DEST_DIR);
|
|
116
|
-
|
|
117
|
-
let successCount = 0;
|
|
118
|
-
let failCount = 0;
|
|
119
|
-
|
|
120
|
-
// Copy header files to Android
|
|
121
|
-
console.log('Copying to Android...');
|
|
122
|
-
for (const headerFile of HEADER_FILES) {
|
|
123
|
-
const source = path.join(SOURCE_DIR, headerFile);
|
|
124
|
-
const destination = path.join(ANDROID_DEST_DIR, headerFile);
|
|
125
|
-
|
|
126
|
-
if (!fs.existsSync(source)) {
|
|
127
|
-
console.error(`Source file not found: ${source}`);
|
|
128
|
-
failCount++;
|
|
129
|
-
continue;
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
if (copyFile(source, destination)) {
|
|
133
|
-
successCount++;
|
|
134
|
-
} else {
|
|
135
|
-
failCount++;
|
|
136
|
-
}
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
// Copy header files to iOS
|
|
140
|
-
console.log('\nCopying to iOS...');
|
|
141
|
-
for (const headerFile of HEADER_FILES) {
|
|
142
|
-
const source = path.join(SOURCE_DIR, headerFile);
|
|
143
|
-
const destination = path.join(IOS_DEST_DIR, headerFile);
|
|
144
|
-
|
|
145
|
-
if (!fs.existsSync(source)) {
|
|
146
|
-
console.error(`Source file not found: ${source}`);
|
|
147
|
-
failCount++;
|
|
148
|
-
continue;
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
if (copyFile(source, destination)) {
|
|
152
|
-
successCount++;
|
|
153
|
-
} else {
|
|
154
|
-
failCount++;
|
|
155
|
-
}
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
// Copy C++ API implementation to iOS root (needed for compilation)
|
|
159
|
-
console.log('\nCopying C++ API implementation to iOS...');
|
|
160
|
-
const cxxImplSource = path.join(SOURCE_DIR, CXX_IMPL_FILE);
|
|
161
|
-
const cxxImplDest = path.join(IOS_ROOT_DIR, CXX_IMPL_FILE);
|
|
162
|
-
|
|
163
|
-
if (!fs.existsSync(cxxImplSource)) {
|
|
164
|
-
console.error(`Source file not found: ${cxxImplSource}`);
|
|
165
|
-
failCount++;
|
|
166
|
-
} else if (copyFile(cxxImplSource, cxxImplDest)) {
|
|
167
|
-
successCount++;
|
|
168
|
-
} else {
|
|
169
|
-
failCount++;
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
console.log(`\n${'='.repeat(50)}`);
|
|
173
|
-
console.log(
|
|
174
|
-
`Summary: ${successCount} files copied successfully, ${failCount} failed`
|
|
175
|
-
);
|
|
176
|
-
|
|
177
|
-
if (failCount > 0) {
|
|
178
|
-
process.exit(1);
|
|
179
|
-
} else {
|
|
180
|
-
console.log('All header files copied successfully!');
|
|
181
|
-
}
|
|
182
|
-
}
|
|
183
|
-
|
|
184
|
-
main();
|
package/scripts/setup-assets.js
DELETED
|
@@ -1,323 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
|
|
3
|
-
const fs = require('fs');
|
|
4
|
-
const path = require('path');
|
|
5
|
-
const { execSync } = require('child_process');
|
|
6
|
-
|
|
7
|
-
// platform detection not needed currently
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* Setup script that runs after npm/yarn install
|
|
11
|
-
* Handles:
|
|
12
|
-
* 1. Copying C++ header files from sherpa-onnx submodule
|
|
13
|
-
* 2. Downloading iOS framework from GitHub releases
|
|
14
|
-
*/
|
|
15
|
-
|
|
16
|
-
function log(message, type = 'info') {
|
|
17
|
-
const colors = {
|
|
18
|
-
info: '\x1b[36m', // cyan
|
|
19
|
-
success: '\x1b[32m', // green
|
|
20
|
-
warning: '\x1b[33m', // yellow
|
|
21
|
-
error: '\x1b[31m', // red
|
|
22
|
-
reset: '\x1b[0m',
|
|
23
|
-
};
|
|
24
|
-
|
|
25
|
-
const color = colors[type] || colors.info;
|
|
26
|
-
console.log(`${color}[setup-assets] ${message}${colors.reset}`);
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
/**
|
|
30
|
-
* Run a command and return output
|
|
31
|
-
*/
|
|
32
|
-
function runCommand(cmd, options = {}) {
|
|
33
|
-
const { silent = false, allowFailure = false } = options;
|
|
34
|
-
|
|
35
|
-
try {
|
|
36
|
-
if (!silent) {
|
|
37
|
-
log(`Running: ${cmd}`);
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
const output = execSync(cmd, {
|
|
41
|
-
encoding: 'utf-8',
|
|
42
|
-
stdio: silent ? 'pipe' : 'inherit',
|
|
43
|
-
});
|
|
44
|
-
|
|
45
|
-
return { ok: true, output: (output || '').trim() };
|
|
46
|
-
} catch (error) {
|
|
47
|
-
if (!silent) {
|
|
48
|
-
log(
|
|
49
|
-
`${allowFailure ? 'Warning' : 'Failed'}: ${cmd}`,
|
|
50
|
-
allowFailure ? 'warning' : 'error'
|
|
51
|
-
);
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
if (!allowFailure) {
|
|
55
|
-
throw error;
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
return { ok: false, output: '' };
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
/**
|
|
63
|
-
* Verify header files are in the correct locations
|
|
64
|
-
*/
|
|
65
|
-
function verifyHeaders() {
|
|
66
|
-
log('Verifying header files...', 'info');
|
|
67
|
-
|
|
68
|
-
const requiredHeaders = [
|
|
69
|
-
path.join(
|
|
70
|
-
__dirname,
|
|
71
|
-
'..',
|
|
72
|
-
'ios',
|
|
73
|
-
'include',
|
|
74
|
-
'sherpa-onnx',
|
|
75
|
-
'c-api',
|
|
76
|
-
'c-api.h'
|
|
77
|
-
),
|
|
78
|
-
path.join(
|
|
79
|
-
__dirname,
|
|
80
|
-
'..',
|
|
81
|
-
'ios',
|
|
82
|
-
'include',
|
|
83
|
-
'sherpa-onnx',
|
|
84
|
-
'c-api',
|
|
85
|
-
'cxx-api.h'
|
|
86
|
-
),
|
|
87
|
-
path.join(
|
|
88
|
-
__dirname,
|
|
89
|
-
'..',
|
|
90
|
-
'android',
|
|
91
|
-
'src',
|
|
92
|
-
'main',
|
|
93
|
-
'cpp',
|
|
94
|
-
'include',
|
|
95
|
-
'sherpa-onnx',
|
|
96
|
-
'c-api',
|
|
97
|
-
'c-api.h'
|
|
98
|
-
),
|
|
99
|
-
path.join(
|
|
100
|
-
__dirname,
|
|
101
|
-
'..',
|
|
102
|
-
'android',
|
|
103
|
-
'src',
|
|
104
|
-
'main',
|
|
105
|
-
'cpp',
|
|
106
|
-
'include',
|
|
107
|
-
'sherpa-onnx',
|
|
108
|
-
'c-api',
|
|
109
|
-
'cxx-api.h'
|
|
110
|
-
),
|
|
111
|
-
];
|
|
112
|
-
|
|
113
|
-
const missingHeaders = requiredHeaders.filter(
|
|
114
|
-
(header) => !fs.existsSync(header)
|
|
115
|
-
);
|
|
116
|
-
|
|
117
|
-
if (missingHeaders.length === 0) {
|
|
118
|
-
log('All header files verified at correct locations', 'success');
|
|
119
|
-
return true;
|
|
120
|
-
} else {
|
|
121
|
-
log(
|
|
122
|
-
`Missing header files found (${missingHeaders.length}/${requiredHeaders.length}):`,
|
|
123
|
-
'error'
|
|
124
|
-
);
|
|
125
|
-
missingHeaders.forEach((header) => {
|
|
126
|
-
log(` - ${header}`, 'error');
|
|
127
|
-
});
|
|
128
|
-
return false;
|
|
129
|
-
}
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
/**
|
|
133
|
-
* Step 1: Copy header files
|
|
134
|
-
*/
|
|
135
|
-
function copyHeaders() {
|
|
136
|
-
log('Step 1: Copying header files...', 'info');
|
|
137
|
-
|
|
138
|
-
try {
|
|
139
|
-
// Call the script directly to avoid depending on yarn availability in consumers
|
|
140
|
-
const copyResult = runCommand('node scripts/copy-headers.js', {
|
|
141
|
-
allowFailure: true,
|
|
142
|
-
});
|
|
143
|
-
|
|
144
|
-
if (copyResult.ok) {
|
|
145
|
-
log('Header files copied successfully', 'success');
|
|
146
|
-
} else {
|
|
147
|
-
log(
|
|
148
|
-
'Warning: Header copy command reported a failure; verifying files...',
|
|
149
|
-
'warning'
|
|
150
|
-
);
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
// Verify headers after copy
|
|
154
|
-
console.log('');
|
|
155
|
-
const headersOk = verifyHeaders();
|
|
156
|
-
if (!headersOk) {
|
|
157
|
-
log('Header verification failed after copy', 'error');
|
|
158
|
-
}
|
|
159
|
-
return headersOk;
|
|
160
|
-
} catch {
|
|
161
|
-
log('Warning: Header copy failed, may already exist', 'warning');
|
|
162
|
-
// Still try to verify if headers exist
|
|
163
|
-
console.log('');
|
|
164
|
-
return verifyHeaders();
|
|
165
|
-
}
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
/**
|
|
169
|
-
* Verify iOS framework is downloaded and extracted correctly
|
|
170
|
-
*/
|
|
171
|
-
function verifyIOSFramework() {
|
|
172
|
-
log('Verifying iOS framework...', 'info');
|
|
173
|
-
|
|
174
|
-
const frameworkPath = path.join(
|
|
175
|
-
__dirname,
|
|
176
|
-
'..',
|
|
177
|
-
'ios',
|
|
178
|
-
'Frameworks',
|
|
179
|
-
'sherpa_onnx.xcframework'
|
|
180
|
-
);
|
|
181
|
-
|
|
182
|
-
// Check if framework directory exists
|
|
183
|
-
if (!fs.existsSync(frameworkPath)) {
|
|
184
|
-
log(`Framework directory not found at ${frameworkPath}`, 'error');
|
|
185
|
-
return false;
|
|
186
|
-
}
|
|
187
|
-
|
|
188
|
-
log(`Framework directory exists`, 'success');
|
|
189
|
-
|
|
190
|
-
// Check for required framework files
|
|
191
|
-
const requiredFiles = [
|
|
192
|
-
path.join(frameworkPath, 'Info.plist'),
|
|
193
|
-
path.join(frameworkPath, 'ios-arm64', 'libsherpa-onnx.a'),
|
|
194
|
-
path.join(frameworkPath, 'ios-arm64_x86_64-simulator', 'libsherpa-onnx.a'),
|
|
195
|
-
];
|
|
196
|
-
|
|
197
|
-
const missingFiles = requiredFiles.filter((file) => !fs.existsSync(file));
|
|
198
|
-
|
|
199
|
-
if (missingFiles.length === 0) {
|
|
200
|
-
// Calculate framework size
|
|
201
|
-
let totalSize = 0;
|
|
202
|
-
const getDirectorySize = (dirPath) => {
|
|
203
|
-
try {
|
|
204
|
-
const files = fs.readdirSync(dirPath);
|
|
205
|
-
files.forEach((file) => {
|
|
206
|
-
const filePath = path.join(dirPath, file);
|
|
207
|
-
const stats = fs.statSync(filePath);
|
|
208
|
-
if (stats.isDirectory()) {
|
|
209
|
-
totalSize += getDirectorySize(filePath);
|
|
210
|
-
} else {
|
|
211
|
-
totalSize += stats.size;
|
|
212
|
-
}
|
|
213
|
-
});
|
|
214
|
-
} catch {
|
|
215
|
-
// Silently ignore errors
|
|
216
|
-
}
|
|
217
|
-
return totalSize;
|
|
218
|
-
};
|
|
219
|
-
|
|
220
|
-
getDirectorySize(frameworkPath);
|
|
221
|
-
const frameworkSizeMB = (totalSize / (1024 * 1024)).toFixed(2);
|
|
222
|
-
|
|
223
|
-
log(`All framework files present (${frameworkSizeMB}MB)`, 'success');
|
|
224
|
-
return true;
|
|
225
|
-
} else {
|
|
226
|
-
log(
|
|
227
|
-
`Missing framework files (${missingFiles.length}/${requiredFiles.length}):`,
|
|
228
|
-
'error'
|
|
229
|
-
);
|
|
230
|
-
missingFiles.forEach((file) => {
|
|
231
|
-
log(` - ${file}`, 'error');
|
|
232
|
-
});
|
|
233
|
-
return false;
|
|
234
|
-
}
|
|
235
|
-
}
|
|
236
|
-
|
|
237
|
-
/**
|
|
238
|
-
* Step 2: Download iOS framework (only on macOS)
|
|
239
|
-
*/
|
|
240
|
-
function downloadIOSFramework() {
|
|
241
|
-
// Only download on macOS since it's iOS-specific
|
|
242
|
-
if (process.platform !== 'darwin') {
|
|
243
|
-
log('Skipping iOS framework download (not on macOS)', 'info');
|
|
244
|
-
return true;
|
|
245
|
-
}
|
|
246
|
-
|
|
247
|
-
log('Step 2: Downloading iOS framework...', 'info');
|
|
248
|
-
|
|
249
|
-
const frameworkPath = path.join(
|
|
250
|
-
__dirname,
|
|
251
|
-
'..',
|
|
252
|
-
'ios',
|
|
253
|
-
'Frameworks',
|
|
254
|
-
'sherpa_onnx.xcframework'
|
|
255
|
-
);
|
|
256
|
-
|
|
257
|
-
// Check if framework already exists
|
|
258
|
-
if (fs.existsSync(frameworkPath)) {
|
|
259
|
-
log('iOS framework already present, verifying...', 'success');
|
|
260
|
-
console.log('');
|
|
261
|
-
return verifyIOSFramework();
|
|
262
|
-
}
|
|
263
|
-
|
|
264
|
-
try {
|
|
265
|
-
// Call the shell script directly to avoid yarn dependency in consuming apps
|
|
266
|
-
const downloadResult = runCommand('bash scripts/setup-ios-framework.sh');
|
|
267
|
-
|
|
268
|
-
if (downloadResult.ok) {
|
|
269
|
-
log('iOS framework downloaded successfully', 'success');
|
|
270
|
-
|
|
271
|
-
// Verify framework after download
|
|
272
|
-
console.log('');
|
|
273
|
-
return verifyIOSFramework();
|
|
274
|
-
}
|
|
275
|
-
|
|
276
|
-
log('iOS framework download command reported failure', 'error');
|
|
277
|
-
return false;
|
|
278
|
-
} catch {
|
|
279
|
-
log('iOS framework download failed', 'error');
|
|
280
|
-
return false;
|
|
281
|
-
}
|
|
282
|
-
}
|
|
283
|
-
|
|
284
|
-
/**
|
|
285
|
-
* Main setup function
|
|
286
|
-
*/
|
|
287
|
-
function setup() {
|
|
288
|
-
console.log('');
|
|
289
|
-
log('='.repeat(60), 'info');
|
|
290
|
-
log('SherpaOnnx SDK Setup Starting', 'info');
|
|
291
|
-
log('='.repeat(60), 'info');
|
|
292
|
-
console.log('');
|
|
293
|
-
|
|
294
|
-
let success = true;
|
|
295
|
-
|
|
296
|
-
// Step 1: Copy headers (critical for both Android and iOS)
|
|
297
|
-
if (!copyHeaders()) {
|
|
298
|
-
success = false;
|
|
299
|
-
}
|
|
300
|
-
|
|
301
|
-
console.log('');
|
|
302
|
-
|
|
303
|
-
// Step 2: Download iOS framework (macOS only)
|
|
304
|
-
if (!downloadIOSFramework()) {
|
|
305
|
-
success = false;
|
|
306
|
-
}
|
|
307
|
-
|
|
308
|
-
console.log('');
|
|
309
|
-
if (success) {
|
|
310
|
-
log('='.repeat(60), 'success');
|
|
311
|
-
log('Setup completed successfully!', 'success');
|
|
312
|
-
log('='.repeat(60), 'success');
|
|
313
|
-
console.log('');
|
|
314
|
-
process.exit(0);
|
|
315
|
-
} else {
|
|
316
|
-
log('Setup failed (see logs above)', 'error');
|
|
317
|
-
console.log('');
|
|
318
|
-
process.exit(1);
|
|
319
|
-
}
|
|
320
|
-
}
|
|
321
|
-
|
|
322
|
-
// Run setup
|
|
323
|
-
setup();
|