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/SherpaOnnx.podspec
CHANGED
|
@@ -1,11 +1,41 @@
|
|
|
1
1
|
require "json"
|
|
2
2
|
|
|
3
3
|
package = JSON.parse(File.read(File.join(__dir__, "package.json")))
|
|
4
|
-
|
|
5
|
-
# Compute absolute paths
|
|
6
4
|
pod_root = __dir__
|
|
7
|
-
|
|
8
|
-
|
|
5
|
+
# Prefer libarchive_prebuilt layout (output of third_party/libarchive_prebuilt/build_libarchive_ios.sh).
|
|
6
|
+
# Fallback: download via setup-ios-libarchive.sh to ios/Downloads/libarchive (e.g. when using SDK from npm).
|
|
7
|
+
libarchive_prebuilt = File.join(pod_root, "third_party", "libarchive_prebuilt", "libarchive-ios-layout")
|
|
8
|
+
libarchive_downloads = File.join(pod_root, "ios", "Downloads", "libarchive")
|
|
9
|
+
unless File.directory?(libarchive_prebuilt) && Dir.glob(File.join(libarchive_prebuilt, "*.c")).any?
|
|
10
|
+
libarchive_script = File.join(pod_root, "ios", "scripts", "setup-ios-libarchive.sh")
|
|
11
|
+
if File.exist?(libarchive_script)
|
|
12
|
+
unless system("bash", libarchive_script)
|
|
13
|
+
abort("[SherpaOnnx] setup-ios-libarchive.sh failed. Check that third_party/libarchive_prebuilt/IOS_RELEASE_TAG exists and the release is available (network). Run the script manually: bash #{libarchive_script}")
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
libarchive_dir = (File.directory?(libarchive_prebuilt) && Dir.glob(File.join(libarchive_prebuilt, "*.c")).any?) ? libarchive_prebuilt : libarchive_downloads
|
|
18
|
+
# Patch libarchive .c files (copy to ios/patched_libarchive with stdio.h/unistd.h added) so we don't modify the submodule.
|
|
19
|
+
patched_dir = File.join(pod_root, "ios", "patched_libarchive")
|
|
20
|
+
patch_script = File.join(pod_root, "ios", "scripts", "patch-libarchive-includes.sh")
|
|
21
|
+
if File.directory?(libarchive_dir) && File.exist?(patch_script)
|
|
22
|
+
unless system("bash", patch_script, libarchive_dir)
|
|
23
|
+
abort("[SherpaOnnx] patch-libarchive-includes.sh failed. Check that #{libarchive_dir} contains libarchive .c/.h files.")
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
# Libarchive C sources: use patched copies (same exclude as before: test, windows, linux, sunos, freebsd).
|
|
27
|
+
libarchive_sources = if File.directory?(patched_dir)
|
|
28
|
+
Dir.glob(File.join(patched_dir, "*.c")).reject { |f|
|
|
29
|
+
base = File.basename(f, ".c")
|
|
30
|
+
File.basename(f) =~ /^test\./ || base.include?("windows") || base.include?("linux") || base.include?("sunos") || base.include?("freebsd")
|
|
31
|
+
}.map { |f| Pathname.new(f).relative_path_from(Pathname.new(pod_root)).to_s.gsub("\\", "/") }
|
|
32
|
+
else
|
|
33
|
+
[]
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
if libarchive_sources.empty?
|
|
37
|
+
abort("[SherpaOnnx] Libarchive sources missing. Ensure third_party/libarchive_prebuilt/libarchive-ios-layout exists (run third_party/libarchive_prebuilt/build_libarchive_ios.sh) or ios/scripts/setup-ios-libarchive.sh has run, and that ios/scripts/patch-libarchive-includes.sh succeeds. Check pod install logs for patch script errors.")
|
|
38
|
+
end
|
|
9
39
|
|
|
10
40
|
Pod::Spec.new do |s|
|
|
11
41
|
s.name = "SherpaOnnx"
|
|
@@ -17,68 +47,42 @@ Pod::Spec.new do |s|
|
|
|
17
47
|
|
|
18
48
|
s.platforms = { :ios => min_ios_version_supported }
|
|
19
49
|
s.source = { :git => "https://github.com/XDcobra/react-native-sherpa-onnx.git", :tag => "#{s.version}" }
|
|
20
|
-
|
|
21
|
-
#
|
|
22
|
-
|
|
23
|
-
s.
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
s.private_header_files =
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
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
|
-
|
|
50
|
+
|
|
51
|
+
# Download sherpa-onnx XCFramework from GitHub Releases before pod install (uses IOS_RELEASE_TAG for pinned version).
|
|
52
|
+
setup_script = File.join(pod_root, "scripts", "setup-ios-framework.sh")
|
|
53
|
+
s.prepare_command = "bash \"#{setup_script}\""
|
|
54
|
+
|
|
55
|
+
s.source_files = ["ios/**/*.{h,m,mm,swift,cpp}", *libarchive_sources]
|
|
56
|
+
s.private_header_files = "ios/**/*.h"
|
|
57
|
+
|
|
58
|
+
s.frameworks = "Foundation", "Accelerate", "CoreML"
|
|
59
|
+
s.vendored_frameworks = "ios/Frameworks/sherpa_onnx.xcframework"
|
|
60
|
+
# Absolute paths so headers are found regardless of PODS_TARGET_SRCROOT (e.g. when building via React Native CLI).
|
|
61
|
+
xcframework_root = File.join(pod_root, "ios", "Frameworks", "sherpa_onnx.xcframework")
|
|
62
|
+
simulator_headers = File.join(xcframework_root, "ios-arm64_x86_64-simulator", "Headers")
|
|
63
|
+
device_headers = File.join(xcframework_root, "ios-arm64", "Headers")
|
|
64
|
+
simulator_slice = File.join(xcframework_root, "ios-arm64_x86_64-simulator")
|
|
65
|
+
device_slice = File.join(xcframework_root, "ios-arm64")
|
|
66
|
+
|
|
72
67
|
s.pod_target_xcconfig = {
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
68
|
+
"HEADER_SEARCH_PATHS" => "$(inherited) \"#{pod_root}/ios\" \"#{pod_root}/ios/archive\" \"#{pod_root}/ios/model_detect\" \"#{pod_root}/ios/stt\" \"#{pod_root}/ios/tts\" \"#{libarchive_dir}\" \"#{device_headers}\" \"#{simulator_headers}\"",
|
|
69
|
+
"GCC_PREPROCESSOR_DEFINITIONS" => '$(inherited) PLATFORM_CONFIG_H=\\"libarchive_darwin_config.h\\"',
|
|
70
|
+
"CLANG_CXX_LANGUAGE_STANDARD" => "c++17",
|
|
71
|
+
"CLANG_CXX_LIBRARY" => "libc++",
|
|
72
|
+
"LIBRARY_SEARCH_PATHS[sdk=iphoneos*]" => "$(inherited) \"#{device_slice}\"",
|
|
73
|
+
"LIBRARY_SEARCH_PATHS[sdk=iphonesimulator*]" => "$(inherited) \"#{simulator_slice}\"",
|
|
74
|
+
"OTHER_LDFLAGS" => "$(inherited) -lsherpa-onnx"
|
|
76
75
|
}
|
|
77
|
-
|
|
76
|
+
|
|
78
77
|
s.user_target_xcconfig = {
|
|
79
|
-
|
|
80
|
-
|
|
78
|
+
"CLANG_CXX_LANGUAGE_STANDARD" => "c++17",
|
|
79
|
+
"CLANG_CXX_LIBRARY" => "libc++",
|
|
80
|
+
"LIBRARY_SEARCH_PATHS[sdk=iphoneos*]" => "$(inherited) \"#{device_slice}\"",
|
|
81
|
+
"LIBRARY_SEARCH_PATHS[sdk=iphonesimulator*]" => "$(inherited) \"#{simulator_slice}\"",
|
|
82
|
+
"OTHER_LDFLAGS" => "$(inherited) -lsherpa-onnx"
|
|
81
83
|
}
|
|
82
|
-
|
|
84
|
+
|
|
85
|
+
s.libraries = "c++", "z"
|
|
86
|
+
|
|
83
87
|
install_modules_dependencies(s)
|
|
84
|
-
end
|
|
88
|
+
end
|
package/android/build.gradle
CHANGED
|
@@ -1,193 +1,183 @@
|
|
|
1
|
-
//
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
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
|
|
1
|
+
// Prebuilt versions (sherpa-onnx, FFmpeg, libarchive) from prebuilt-versions.gradle.
|
|
2
|
+
// Resolution: env → ANDROID_RELEASE_TAG files → project property → default.
|
|
3
|
+
apply from: file("${project.projectDir}/prebuilt-versions.gradle")
|
|
4
|
+
|
|
5
|
+
// Used by dependencies below and by prebuilt-download.gradle (extractSherpaOnnxClasses, downloadNativeLibsIfNeeded).
|
|
6
|
+
def sherpaOnnxClassesDir = file("${buildDir}/sherpa-onnx-classes")
|
|
7
|
+
|
|
8
|
+
buildscript {
|
|
9
|
+
ext.SherpaOnnx = [
|
|
10
|
+
kotlinVersion: "2.0.21",
|
|
11
|
+
minSdkVersion: 24,
|
|
12
|
+
compileSdkVersion: 36,
|
|
13
|
+
targetSdkVersion: 36
|
|
14
|
+
]
|
|
15
|
+
|
|
16
|
+
ext.getExtOrDefault = { prop ->
|
|
17
|
+
if (rootProject.ext.has(prop)) {
|
|
18
|
+
return rootProject.ext.get(prop)
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
return SherpaOnnx[prop]
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
repositories {
|
|
25
|
+
google()
|
|
26
|
+
mavenCentral()
|
|
27
|
+
maven { url 'https://plugins.gradle.org/m2/' }
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
dependencies {
|
|
31
|
+
classpath "com.android.tools.build:gradle:8.7.2"
|
|
32
|
+
// noinspection DifferentKotlinGradleVersion
|
|
33
|
+
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:${getExtOrDefault('kotlinVersion')}"
|
|
34
|
+
// Node Gradle plugin for running node/npx reliably from Gradle
|
|
35
|
+
classpath "com.github.node-gradle:gradle-node-plugin:7.1.0"
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
apply plugin: "com.android.library"
|
|
41
|
+
apply plugin: "kotlin-android"
|
|
42
|
+
|
|
43
|
+
// Standalone AAR build: set in root build.gradle (ext.standaloneAarBuild = true) or via -PstandaloneAarBuild=true
|
|
44
|
+
def isStandaloneAarBuild = rootProject.findProperty("standaloneAarBuild") in [true, "true"]
|
|
45
|
+
// Only apply React Native plugin when building inside a React Native app (e.g. example app).
|
|
46
|
+
if (!isStandaloneAarBuild) {
|
|
47
|
+
apply plugin: "com.facebook.react"
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
android {
|
|
51
|
+
namespace "com.sherpaonnx"
|
|
52
|
+
|
|
53
|
+
compileSdkVersion getExtOrDefault("compileSdkVersion")
|
|
54
|
+
|
|
55
|
+
// Native .so and headers: filled by prebuilt-download.gradle (local jniLibs, Maven AAR, or GitHub release).
|
|
56
|
+
// Alternatively by third_party/*/copy_prebuilts_to_sdk.js or shipped in npm package.
|
|
57
|
+
|
|
58
|
+
// Codegen Java output: always use the flat path. For app builds RNGP writes here directly;
|
|
59
|
+
// for standalone AAR builds the codegen task normalises the nested output to this path.
|
|
60
|
+
sourceSets.main.java.srcDirs += file("${buildDir}/generated/source/codegen/java")
|
|
61
|
+
|
|
62
|
+
defaultConfig {
|
|
63
|
+
minSdkVersion getExtOrDefault("minSdkVersion")
|
|
64
|
+
targetSdkVersion getExtOrDefault("targetSdkVersion")
|
|
65
|
+
|
|
66
|
+
// ProGuard rules to preserve classes/methods called from JNI
|
|
67
|
+
consumerProguardFiles 'proguard-rules.pro'
|
|
68
|
+
|
|
69
|
+
// NDK configuration
|
|
70
|
+
ndkVersion getExtOrDefault("ndkVersion")
|
|
71
|
+
externalNativeBuild {
|
|
72
|
+
cmake {
|
|
73
|
+
cppFlags "-std=c++17", "-Wall", "-Wextra", "-fvisibility=hidden"
|
|
74
|
+
arguments "-DANDROID_STL=c++_shared"
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
// Supported ABIs
|
|
79
|
+
ndk {
|
|
80
|
+
abiFilters "arm64-v8a", "armeabi-v7a", "x86", "x86_64"
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
buildFeatures {
|
|
85
|
+
buildConfig true
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
// CMake configuration
|
|
89
|
+
externalNativeBuild {
|
|
90
|
+
cmake {
|
|
91
|
+
path "src/main/cpp/CMakeLists.txt"
|
|
92
|
+
version "3.22.1"
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
buildTypes {
|
|
97
|
+
release {
|
|
98
|
+
minifyEnabled false
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
lint {
|
|
103
|
+
disable "GradleCompatible"
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
compileOptions {
|
|
107
|
+
sourceCompatibility JavaVersion.VERSION_17
|
|
108
|
+
targetCompatibility JavaVersion.VERSION_17
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
kotlinOptions {
|
|
112
|
+
jvmTarget = '17'
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
repositories {
|
|
117
|
+
mavenCentral()
|
|
118
|
+
google()
|
|
119
|
+
maven { url "https://xdcobra.github.io/maven" }
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
// Configurations used by prebuilt-download.gradle: downloadNativeLibsIfNeeded (AAR → jniLibs + headers),
|
|
123
|
+
// extractSherpaOnnxClasses (sherpa-onnx classes.jar), extractOnnxruntimeClasses (onnxruntime classes.jar).
|
|
124
|
+
configurations { sherpaOnnxAar; ffmpegAar; libarchiveAar; onnxruntimeAar }
|
|
125
|
+
|
|
126
|
+
// Registers downloadNativeLibsIfNeeded, checkJniLibs, extractSherpaOnnxClasses, extractOnnxruntimeClasses; wires preBuild.dependsOn checkJniLibs.
|
|
127
|
+
apply from: file("${project.projectDir}/prebuilt-download.gradle")
|
|
128
|
+
|
|
129
|
+
def kotlin_version = getExtOrDefault("kotlinVersion")
|
|
130
|
+
|
|
131
|
+
dependencies {
|
|
132
|
+
// React Native dependency: explicit version ensures IDE (VS Code Kotlin LSP) and standalone
|
|
133
|
+
// AAR builds can resolve com.facebook.react types. When consumed by a React Native app,
|
|
134
|
+
// Gradle's dependency resolution picks the app's react-android version (typically higher).
|
|
135
|
+
implementation "com.facebook.react:react-android:0.83.0"
|
|
136
|
+
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
|
|
137
|
+
|
|
138
|
+
// Versions from prebuilt-versions.gradle; AARs used by prebuilt-download.gradle tasks.
|
|
139
|
+
sherpaOnnxAar "com.xdcobra.sherpa:sherpa-onnx:${sherpaOnnxVersion}@aar"
|
|
140
|
+
ffmpegAar "com.xdcobra.sherpa:ffmpeg:${ffmpegVersion}@aar"
|
|
141
|
+
libarchiveAar "com.xdcobra.sherpa:libarchive:${libarchiveVersion}@aar"
|
|
142
|
+
onnxruntimeAar "com.xdcobra.sherpa:onnxruntime:${ortVersion}@aar"
|
|
143
|
+
|
|
144
|
+
// sherpa-onnx Java API: extractSherpaOnnxClasses (in prebuilt-download.gradle) fills sherpaOnnxClassesDir.
|
|
145
|
+
// Source: local third_party | Maven AAR | GitHub release. Native .so from same prebuilt pipeline.
|
|
146
|
+
implementation fileTree(dir: sherpaOnnxClassesDir, include: '*.jar').builtBy(tasks.named('extractSherpaOnnxClasses'))
|
|
147
|
+
|
|
148
|
+
// ORT Java API (OrtEnvironment, OrtSession, OrtProvider) for getAvailableProviders/getQnnSupport/etc.
|
|
149
|
+
// Extracted classes.jar from onnxruntime AAR (no compileOnly needed; bundled directly in the SDK).
|
|
150
|
+
// libonnxruntime4j_jni.so is also extracted to jniLibs so the Java bridge works at runtime.
|
|
151
|
+
def onnxruntimeClassesDir = file("${buildDir}/onnxruntime-classes")
|
|
152
|
+
implementation fileTree(dir: onnxruntimeClassesDir, include: '*.jar').builtBy(tasks.named('extractOnnxruntimeClasses'))
|
|
153
|
+
|
|
154
|
+
// Play Asset Delivery: optional for getAssetPackPath (returns null if not used)
|
|
155
|
+
implementation "com.google.android.play:asset-delivery:2.3.0"
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
// TurboModule codegen; separate script to avoid Gradle 9 Groovy "source is null" with NodeTask.
|
|
159
|
+
apply from: file("${project.projectDir}/codegen.gradle")
|
|
160
|
+
|
|
161
|
+
// Wire prebuilt tasks: extractSherpaOnnxClasses → downloadNativeLibsIfNeeded when not standalone;
|
|
162
|
+
// CMake/compile tasks depend on extractSherpaOnnxClasses and checkJniLibs.
|
|
163
|
+
afterEvaluate {
|
|
164
|
+
if (!isStandaloneAarBuild && tasks.findByName("downloadNativeLibsIfNeeded") != null) {
|
|
165
|
+
tasks.named("extractSherpaOnnxClasses").configure { dependsOn tasks.named("downloadNativeLibsIfNeeded") }
|
|
166
|
+
tasks.named("extractOnnxruntimeClasses").configure { dependsOn tasks.named("downloadNativeLibsIfNeeded") }
|
|
167
|
+
}
|
|
168
|
+
tasks.matching { it.name.contains("configureCMake") || it.name.contains("externalNativeBuild") }.configureEach {
|
|
169
|
+
dependsOn tasks.named("extractSherpaOnnxClasses")
|
|
170
|
+
dependsOn tasks.named("extractOnnxruntimeClasses")
|
|
171
|
+
dependsOn tasks.named("checkJniLibs")
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
// With includesGeneratedCode=false, codegen is always run by our custom task (not RNGP).
|
|
175
|
+
// Kotlin compile must depend on it for both standalone AAR and app-dependency builds.
|
|
176
|
+
def codegenJavaDir = project.file("${project.buildDir}/generated/source/codegen/java")
|
|
177
|
+
tasks.matching { it.name == "compileReleaseKotlin" || it.name == "compileDebugKotlin" }.configureEach {
|
|
178
|
+
dependsOn tasks.named("extractSherpaOnnxClasses")
|
|
179
|
+
dependsOn tasks.named("extractOnnxruntimeClasses")
|
|
180
|
+
dependsOn tasks.named('generateCodegenSpec')
|
|
181
|
+
inputs.dir(codegenJavaDir)
|
|
182
|
+
}
|
|
193
183
|
}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
// With includesGeneratedCode=false, RNGP does not run codegen for this library when it
|
|
2
|
+
// is built as a dependency (e.g. example app). Run codegen whenever this module is built
|
|
3
|
+
// (standalone AAR or as part of an app) so that NativeSherpaOnnxSpec exists for Kotlin compile.
|
|
4
|
+
// Uses Exec + node (no Node Gradle plugin) to avoid classloader/DSL issues in applied script.
|
|
5
|
+
def libraryRoot = project.projectDir.parentFile
|
|
6
|
+
def outDir = file("${project.buildDir}/generated/source/codegen")
|
|
7
|
+
def codegenJavaDir = file("${project.buildDir}/generated/source/codegen/java")
|
|
8
|
+
|
|
9
|
+
codegenJavaDir.mkdirs()
|
|
10
|
+
|
|
11
|
+
def codegenScript = file("${libraryRoot}/node_modules/react-native/scripts/generate-codegen-artifacts.js")
|
|
12
|
+
def outDirPath = outDir.absolutePath.replace("\\", "/")
|
|
13
|
+
def libraryRootPath = libraryRoot.absolutePath.replace("\\", "/")
|
|
14
|
+
|
|
15
|
+
tasks.register("generateCodegenSpecNode", Exec) {
|
|
16
|
+
onlyIf { !project.hasProperty('useNpx') || project.property('useNpx') != 'true' }
|
|
17
|
+
workingDir = libraryRoot
|
|
18
|
+
inputs.dir(file("${libraryRoot}/src"))
|
|
19
|
+
inputs.file(file("${libraryRoot}/package.json"))
|
|
20
|
+
outputs.dir(codegenJavaDir)
|
|
21
|
+
|
|
22
|
+
doFirst {
|
|
23
|
+
if (!file("${libraryRoot}/node_modules/react-native").exists()) {
|
|
24
|
+
throw new RuntimeException(
|
|
25
|
+
"Codegen requires node_modules at library root. Run 'yarn install' (or npm install) in ${libraryRoot}, then rebuild."
|
|
26
|
+
)
|
|
27
|
+
}
|
|
28
|
+
outDir.mkdirs()
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
commandLine(
|
|
32
|
+
'node',
|
|
33
|
+
codegenScript.absolutePath,
|
|
34
|
+
'-p', libraryRootPath,
|
|
35
|
+
'-t', 'android',
|
|
36
|
+
'-o', outDirPath,
|
|
37
|
+
'-s', 'library'
|
|
38
|
+
)
|
|
39
|
+
environment 'CI': 'true'
|
|
40
|
+
|
|
41
|
+
doLast {
|
|
42
|
+
def nestedJava = file("${outDir}/android/app/build/generated/source/codegen/java")
|
|
43
|
+
if (nestedJava.exists()) {
|
|
44
|
+
project.copy {
|
|
45
|
+
from nestedJava
|
|
46
|
+
into codegenJavaDir
|
|
47
|
+
}
|
|
48
|
+
println "[codegen] Normalised spec output -> ${codegenJavaDir}"
|
|
49
|
+
} else {
|
|
50
|
+
println "[codegen] WARNING: expected nested output at ${nestedJava} not found"
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
tasks.register('generateCodegenSpec') {
|
|
56
|
+
dependsOn tasks.named('generateCodegenSpecNode')
|
|
57
|
+
}
|