@siteed/sherpa-onnx.rn 1.0.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 +374 -0
- package/android/CMakeLists.txt +46 -0
- package/android/README.md +77 -0
- package/android/build.gradle +140 -0
- package/android/proguard-rules.pro +32 -0
- package/android/scripts/copy-libs.sh +55 -0
- package/android/src/androidTest/java/net/siteed/sherpaonnx/ArchitectureCompatibilityTest.kt +242 -0
- package/android/src/androidTest/java/net/siteed/sherpaonnx/ArchitectureSpecificTest.kt +397 -0
- package/android/src/androidTest/java/net/siteed/sherpaonnx/BasicIntegrationTest.kt +153 -0
- package/android/src/androidTest/java/net/siteed/sherpaonnx/ComprehensiveIntegrationTestSuite.kt +422 -0
- package/android/src/androidTest/java/net/siteed/sherpaonnx/MemoryAndPerformanceProfilerTest.kt +465 -0
- package/android/src/androidTest/java/net/siteed/sherpaonnx/RealAsrFunctionalityTest.kt +553 -0
- package/android/src/androidTest/java/net/siteed/sherpaonnx/RealTtsFunctionalityTest.kt +546 -0
- package/android/src/androidTest/java/net/siteed/sherpaonnx/SystemInfoTest.kt +175 -0
- package/android/src/androidTest/java/net/siteed/sherpaonnx/TestModelManagementTest.kt +130 -0
- package/android/src/androidTest/java/net/siteed/sherpaonnx/TtsIntegrationTest.kt +223 -0
- package/android/src/androidTest/java/net/siteed/sherpaonnx/utils/LightweightModelDownloader.kt +291 -0
- package/android/src/androidTest/java/net/siteed/sherpaonnx/utils/TestModelManager.kt +79 -0
- package/android/src/main/AndroidManifest.xml +7 -0
- package/android/src/main/jniLibs/arm64-v8a/libonnxruntime.so +0 -0
- package/android/src/main/jniLibs/arm64-v8a/libsherpa-onnx-jni.so +0 -0
- package/android/src/main/jniLibs/armeabi-v7a/libonnxruntime.so +0 -0
- package/android/src/main/jniLibs/armeabi-v7a/libsherpa-onnx-jni.so +0 -0
- package/android/src/main/jniLibs/x86_64/libonnxruntime.so +0 -0
- package/android/src/main/jniLibs/x86_64/libsherpa-onnx-jni.so +0 -0
- package/android/src/main/kotlin/com/k2fsa/sherpa/onnx/AudioTagging.kt +175 -0
- package/android/src/main/kotlin/com/k2fsa/sherpa/onnx/FeatureConfig.kt +11 -0
- package/android/src/main/kotlin/com/k2fsa/sherpa/onnx/HomophoneReplacerConfig.kt +7 -0
- package/android/src/main/kotlin/com/k2fsa/sherpa/onnx/KeywordSpotter.kt +150 -0
- package/android/src/main/kotlin/com/k2fsa/sherpa/onnx/OfflinePunctuation.kt +60 -0
- package/android/src/main/kotlin/com/k2fsa/sherpa/onnx/OfflineRecognizer.kt +620 -0
- package/android/src/main/kotlin/com/k2fsa/sherpa/onnx/OfflineSpeakerDiarization.kt +104 -0
- package/android/src/main/kotlin/com/k2fsa/sherpa/onnx/OfflineSpeechDenoiser.kt +82 -0
- package/android/src/main/kotlin/com/k2fsa/sherpa/onnx/OfflineStream.kt +32 -0
- package/android/src/main/kotlin/com/k2fsa/sherpa/onnx/OnlinePunctuation.kt +61 -0
- package/android/src/main/kotlin/com/k2fsa/sherpa/onnx/OnlineRecognizer.kt +464 -0
- package/android/src/main/kotlin/com/k2fsa/sherpa/onnx/OnlineStream.kt +36 -0
- package/android/src/main/kotlin/com/k2fsa/sherpa/onnx/QnnConfig.kt +7 -0
- package/android/src/main/kotlin/com/k2fsa/sherpa/onnx/Speaker.kt +157 -0
- package/android/src/main/kotlin/com/k2fsa/sherpa/onnx/SpeakerEmbeddingExtractorConfig.kt +8 -0
- package/android/src/main/kotlin/com/k2fsa/sherpa/onnx/SpokenLanguageIdentification.kt +103 -0
- package/android/src/main/kotlin/com/k2fsa/sherpa/onnx/Tts.kt +295 -0
- package/android/src/main/kotlin/com/k2fsa/sherpa/onnx/Vad.kt +123 -0
- package/android/src/main/kotlin/com/k2fsa/sherpa/onnx/VersionInfo.kt +22 -0
- package/android/src/main/kotlin/com/k2fsa/sherpa/onnx/WaveReader.kt +70 -0
- package/android/src/main/kotlin/net/siteed/sherpaonnx/AudioData.kt +33 -0
- package/android/src/main/kotlin/net/siteed/sherpaonnx/SherpaOnnxImpl.kt +453 -0
- package/android/src/main/kotlin/net/siteed/sherpaonnx/SherpaOnnxModule.kt +74 -0
- package/android/src/main/kotlin/net/siteed/sherpaonnx/SherpaOnnxPackage.kt +16 -0
- package/android/src/main/kotlin/net/siteed/sherpaonnx/SherpaOnnxTurboModule.kt +44 -0
- package/android/src/main/kotlin/net/siteed/sherpaonnx/SherpaOnnxTurboModuleImpl.kt +162 -0
- package/android/src/main/kotlin/net/siteed/sherpaonnx/handlers/ASRHandler.kt +1199 -0
- package/android/src/main/kotlin/net/siteed/sherpaonnx/handlers/ArchiveHandler.kt +64 -0
- package/android/src/main/kotlin/net/siteed/sherpaonnx/handlers/AudioTaggingHandler.kt +425 -0
- package/android/src/main/kotlin/net/siteed/sherpaonnx/handlers/DenoisingHandler.kt +157 -0
- package/android/src/main/kotlin/net/siteed/sherpaonnx/handlers/DiarizationHandler.kt +190 -0
- package/android/src/main/kotlin/net/siteed/sherpaonnx/handlers/KWSHandler.kt +295 -0
- package/android/src/main/kotlin/net/siteed/sherpaonnx/handlers/LanguageIdHandler.kt +197 -0
- package/android/src/main/kotlin/net/siteed/sherpaonnx/handlers/PunctuationHandler.kt +145 -0
- package/android/src/main/kotlin/net/siteed/sherpaonnx/handlers/SpeakerIdHandler.kt +589 -0
- package/android/src/main/kotlin/net/siteed/sherpaonnx/handlers/TtsHandler.kt +787 -0
- package/android/src/main/kotlin/net/siteed/sherpaonnx/handlers/VadHandler.kt +207 -0
- package/android/src/main/kotlin/net/siteed/sherpaonnx/utils/ArchiveUtils.kt +167 -0
- package/android/src/main/kotlin/net/siteed/sherpaonnx/utils/AssetUtils.kt +294 -0
- package/android/src/main/kotlin/net/siteed/sherpaonnx/utils/AudioExtractor.kt +143 -0
- package/android/src/main/kotlin/net/siteed/sherpaonnx/utils/AudioUtils.kt +446 -0
- package/android/src/newarch/kotlin/net/siteed/sherpaonnx/SherpaOnnxTurboModule.kt +41 -0
- package/android/src/newarch/kotlin/net/siteed/sherpaonnx/SherpaOnnxTurboModuleImpl.kt +150 -0
- package/android/src/test/resources/README.md +43 -0
- package/build-all.sh +31 -0
- package/build-sherpa-android.sh +59 -0
- package/build-sherpa-ios.sh +106 -0
- package/cpp/dummy/dummy.cpp +622 -0
- package/install.js +164 -0
- package/ios/SherpaOnnxTests/BasicIntegrationTest.swift +40 -0
- package/ios/SherpaOnnxTests/Info.plist +22 -0
- package/ios/SherpaOnnxTests/SystemInfoIntegrationTest.swift +209 -0
- package/ios/SherpaOnnxTests/TtsIntegrationTests.swift +73 -0
- package/ios/bridge/SherpaOnnxLegacySpec.h +145 -0
- package/ios/bridge/SherpaOnnxRnModule.h +36 -0
- package/ios/bridge/SherpaOnnxRnModule.mm +1290 -0
- package/ios/codegen/SherpaOnnxSpec/SherpaOnnxSpec-generated.mm +299 -0
- package/ios/codegen/SherpaOnnxSpec/SherpaOnnxSpec.h +645 -0
- package/ios/handlers/SherpaOnnxASRHandler.swift +588 -0
- package/ios/handlers/SherpaOnnxAudioTaggingHandler.swift +231 -0
- package/ios/handlers/SherpaOnnxDenoisingHandler.swift +119 -0
- package/ios/handlers/SherpaOnnxDiarizationHandler.swift +141 -0
- package/ios/handlers/SherpaOnnxKWSHandler.swift +214 -0
- package/ios/handlers/SherpaOnnxLanguageIdHandler.swift +200 -0
- package/ios/handlers/SherpaOnnxPunctuationHandler.swift +131 -0
- package/ios/handlers/SherpaOnnxSpeakerIdHandler.swift +363 -0
- package/ios/handlers/SherpaOnnxTtsHandler.swift +527 -0
- package/ios/handlers/SherpaOnnxVADHandler.swift +161 -0
- package/ios/native/SherpaOnnxClasses.swift +25 -0
- package/ios/sherpa-onnx-rn.swift +2 -0
- package/ios/test_models/README.md +36 -0
- package/ios/utils/SherpaOnnxArchiveExtractor.h +40 -0
- package/ios/utils/SherpaOnnxArchiveExtractor.m +486 -0
- package/lib/commonjs/NativeSherpaOnnxSpec.js +28 -0
- package/lib/commonjs/NativeSherpaOnnxSpec.js.map +1 -0
- package/lib/commonjs/SherpaOnnxAPI.js +278 -0
- package/lib/commonjs/SherpaOnnxAPI.js.map +1 -0
- package/lib/commonjs/WebSherpaOnnxImpl.js +23 -0
- package/lib/commonjs/WebSherpaOnnxImpl.js.map +1 -0
- package/lib/commonjs/index.js +109 -0
- package/lib/commonjs/index.js.map +1 -0
- package/lib/commonjs/services/ArchiveService.js +128 -0
- package/lib/commonjs/services/ArchiveService.js.map +1 -0
- package/lib/commonjs/services/AsrService.js +140 -0
- package/lib/commonjs/services/AsrService.js.map +1 -0
- package/lib/commonjs/services/AudioTaggingService.js +90 -0
- package/lib/commonjs/services/AudioTaggingService.js.map +1 -0
- package/lib/commonjs/services/DenoisingService.js +85 -0
- package/lib/commonjs/services/DenoisingService.js.map +1 -0
- package/lib/commonjs/services/DiarizationService.js +92 -0
- package/lib/commonjs/services/DiarizationService.js.map +1 -0
- package/lib/commonjs/services/KWSService.js +146 -0
- package/lib/commonjs/services/KWSService.js.map +1 -0
- package/lib/commonjs/services/LanguageIdService.js +110 -0
- package/lib/commonjs/services/LanguageIdService.js.map +1 -0
- package/lib/commonjs/services/PunctuationService.js +87 -0
- package/lib/commonjs/services/PunctuationService.js.map +1 -0
- package/lib/commonjs/services/SpeakerIdService.js +383 -0
- package/lib/commonjs/services/SpeakerIdService.js.map +1 -0
- package/lib/commonjs/services/TtsService.js +239 -0
- package/lib/commonjs/services/TtsService.js.map +1 -0
- package/lib/commonjs/services/VadService.js +109 -0
- package/lib/commonjs/services/VadService.js.map +1 -0
- package/lib/commonjs/types/api.js +6 -0
- package/lib/commonjs/types/api.js.map +1 -0
- package/lib/commonjs/types/expo-modules-core-shim.d.js +2 -0
- package/lib/commonjs/types/expo-modules-core-shim.d.js.map +1 -0
- package/lib/commonjs/types/interfaces.js +6 -0
- package/lib/commonjs/types/interfaces.js.map +1 -0
- package/lib/commonjs/utils/fileUtils.js +18 -0
- package/lib/commonjs/utils/fileUtils.js.map +1 -0
- package/lib/commonjs/web/audioUtils.js +156 -0
- package/lib/commonjs/web/audioUtils.js.map +1 -0
- package/lib/commonjs/web/features/asr.js +239 -0
- package/lib/commonjs/web/features/asr.js.map +1 -0
- package/lib/commonjs/web/features/audioTagging.js +149 -0
- package/lib/commonjs/web/features/audioTagging.js.map +1 -0
- package/lib/commonjs/web/features/denoising.js +109 -0
- package/lib/commonjs/web/features/denoising.js.map +1 -0
- package/lib/commonjs/web/features/diagnostics.js +122 -0
- package/lib/commonjs/web/features/diagnostics.js.map +1 -0
- package/lib/commonjs/web/features/diarization.js +128 -0
- package/lib/commonjs/web/features/diarization.js.map +1 -0
- package/lib/commonjs/web/features/kws.js +220 -0
- package/lib/commonjs/web/features/kws.js.map +1 -0
- package/lib/commonjs/web/features/languageId.js +136 -0
- package/lib/commonjs/web/features/languageId.js.map +1 -0
- package/lib/commonjs/web/features/mixinUtils.js +50 -0
- package/lib/commonjs/web/features/mixinUtils.js.map +1 -0
- package/lib/commonjs/web/features/punctuation.js +94 -0
- package/lib/commonjs/web/features/punctuation.js.map +1 -0
- package/lib/commonjs/web/features/speakerId.js +305 -0
- package/lib/commonjs/web/features/speakerId.js.map +1 -0
- package/lib/commonjs/web/features/tts.js +109 -0
- package/lib/commonjs/web/features/tts.js.map +1 -0
- package/lib/commonjs/web/features/vad.js +124 -0
- package/lib/commonjs/web/features/vad.js.map +1 -0
- package/lib/commonjs/web/wasmLoader.js +231 -0
- package/lib/commonjs/web/wasmLoader.js.map +1 -0
- package/lib/commonjs/web/wasmTypes.js +2 -0
- package/lib/commonjs/web/wasmTypes.js.map +1 -0
- package/lib/module/NativeSherpaOnnxSpec.js +24 -0
- package/lib/module/NativeSherpaOnnxSpec.js.map +1 -0
- package/lib/module/SherpaOnnxAPI.js +273 -0
- package/lib/module/SherpaOnnxAPI.js.map +1 -0
- package/lib/module/WebSherpaOnnxImpl.js +19 -0
- package/lib/module/WebSherpaOnnxImpl.js.map +1 -0
- package/lib/module/index.js +66 -0
- package/lib/module/index.js.map +1 -0
- package/lib/module/services/ArchiveService.js +123 -0
- package/lib/module/services/ArchiveService.js.map +1 -0
- package/lib/module/services/AsrService.js +136 -0
- package/lib/module/services/AsrService.js.map +1 -0
- package/lib/module/services/AudioTaggingService.js +86 -0
- package/lib/module/services/AudioTaggingService.js.map +1 -0
- package/lib/module/services/DenoisingService.js +80 -0
- package/lib/module/services/DenoisingService.js.map +1 -0
- package/lib/module/services/DiarizationService.js +87 -0
- package/lib/module/services/DiarizationService.js.map +1 -0
- package/lib/module/services/KWSService.js +142 -0
- package/lib/module/services/KWSService.js.map +1 -0
- package/lib/module/services/LanguageIdService.js +105 -0
- package/lib/module/services/LanguageIdService.js.map +1 -0
- package/lib/module/services/PunctuationService.js +82 -0
- package/lib/module/services/PunctuationService.js.map +1 -0
- package/lib/module/services/SpeakerIdService.js +379 -0
- package/lib/module/services/SpeakerIdService.js.map +1 -0
- package/lib/module/services/TtsService.js +235 -0
- package/lib/module/services/TtsService.js.map +1 -0
- package/lib/module/services/VadService.js +104 -0
- package/lib/module/services/VadService.js.map +1 -0
- package/lib/module/types/api.js +4 -0
- package/lib/module/types/api.js.map +1 -0
- package/lib/module/types/expo-modules-core-shim.d.js +2 -0
- package/lib/module/types/expo-modules-core-shim.d.js.map +1 -0
- package/lib/module/types/interfaces.js +4 -0
- package/lib/module/types/interfaces.js.map +1 -0
- package/lib/module/utils/fileUtils.js +14 -0
- package/lib/module/utils/fileUtils.js.map +1 -0
- package/lib/module/web/audioUtils.js +148 -0
- package/lib/module/web/audioUtils.js.map +1 -0
- package/lib/module/web/features/asr.js +235 -0
- package/lib/module/web/features/asr.js.map +1 -0
- package/lib/module/web/features/audioTagging.js +145 -0
- package/lib/module/web/features/audioTagging.js.map +1 -0
- package/lib/module/web/features/denoising.js +105 -0
- package/lib/module/web/features/denoising.js.map +1 -0
- package/lib/module/web/features/diagnostics.js +118 -0
- package/lib/module/web/features/diagnostics.js.map +1 -0
- package/lib/module/web/features/diarization.js +124 -0
- package/lib/module/web/features/diarization.js.map +1 -0
- package/lib/module/web/features/kws.js +216 -0
- package/lib/module/web/features/kws.js.map +1 -0
- package/lib/module/web/features/languageId.js +132 -0
- package/lib/module/web/features/languageId.js.map +1 -0
- package/lib/module/web/features/mixinUtils.js +46 -0
- package/lib/module/web/features/mixinUtils.js.map +1 -0
- package/lib/module/web/features/punctuation.js +90 -0
- package/lib/module/web/features/punctuation.js.map +1 -0
- package/lib/module/web/features/speakerId.js +301 -0
- package/lib/module/web/features/speakerId.js.map +1 -0
- package/lib/module/web/features/tts.js +105 -0
- package/lib/module/web/features/tts.js.map +1 -0
- package/lib/module/web/features/vad.js +120 -0
- package/lib/module/web/features/vad.js.map +1 -0
- package/lib/module/web/wasmLoader.js +223 -0
- package/lib/module/web/wasmLoader.js.map +1 -0
- package/lib/module/web/wasmTypes.js +2 -0
- package/lib/module/web/wasmTypes.js.map +1 -0
- package/lib/typescript/commonjs/NativeSherpaOnnxSpec.d.ts +472 -0
- package/lib/typescript/commonjs/NativeSherpaOnnxSpec.d.ts.map +1 -0
- package/lib/typescript/commonjs/SherpaOnnxAPI.d.ts +3 -0
- package/lib/typescript/commonjs/SherpaOnnxAPI.d.ts.map +1 -0
- package/lib/typescript/commonjs/WebSherpaOnnxImpl.d.ts +214 -0
- package/lib/typescript/commonjs/WebSherpaOnnxImpl.d.ts.map +1 -0
- package/lib/typescript/commonjs/index.d.ts +27 -0
- package/lib/typescript/commonjs/index.d.ts.map +1 -0
- package/lib/typescript/commonjs/package.json +1 -0
- package/lib/typescript/commonjs/services/ArchiveService.d.ts +65 -0
- package/lib/typescript/commonjs/services/ArchiveService.d.ts.map +1 -0
- package/lib/typescript/commonjs/services/AsrService.d.ts +72 -0
- package/lib/typescript/commonjs/services/AsrService.d.ts.map +1 -0
- package/lib/typescript/commonjs/services/AudioTaggingService.d.ts +35 -0
- package/lib/typescript/commonjs/services/AudioTaggingService.d.ts.map +1 -0
- package/lib/typescript/commonjs/services/DenoisingService.d.ts +16 -0
- package/lib/typescript/commonjs/services/DenoisingService.d.ts.map +1 -0
- package/lib/typescript/commonjs/services/DiarizationService.d.ts +16 -0
- package/lib/typescript/commonjs/services/DiarizationService.d.ts.map +1 -0
- package/lib/typescript/commonjs/services/KWSService.d.ts +40 -0
- package/lib/typescript/commonjs/services/KWSService.d.ts.map +1 -0
- package/lib/typescript/commonjs/services/LanguageIdService.d.ts +15 -0
- package/lib/typescript/commonjs/services/LanguageIdService.d.ts.map +1 -0
- package/lib/typescript/commonjs/services/PunctuationService.d.ts +14 -0
- package/lib/typescript/commonjs/services/PunctuationService.d.ts.map +1 -0
- package/lib/typescript/commonjs/services/SpeakerIdService.d.ts +99 -0
- package/lib/typescript/commonjs/services/SpeakerIdService.d.ts.map +1 -0
- package/lib/typescript/commonjs/services/TtsService.d.ts +51 -0
- package/lib/typescript/commonjs/services/TtsService.d.ts.map +1 -0
- package/lib/typescript/commonjs/services/VadService.d.ts +17 -0
- package/lib/typescript/commonjs/services/VadService.d.ts.map +1 -0
- package/lib/typescript/commonjs/types/api.d.ts +192 -0
- package/lib/typescript/commonjs/types/api.d.ts.map +1 -0
- package/lib/typescript/commonjs/types/interfaces.d.ts +1066 -0
- package/lib/typescript/commonjs/types/interfaces.d.ts.map +1 -0
- package/lib/typescript/commonjs/utils/fileUtils.d.ts +5 -0
- package/lib/typescript/commonjs/utils/fileUtils.d.ts.map +1 -0
- package/lib/typescript/commonjs/web/audioUtils.d.ts +21 -0
- package/lib/typescript/commonjs/web/audioUtils.d.ts.map +1 -0
- package/lib/typescript/commonjs/web/features/asr.d.ts +34 -0
- package/lib/typescript/commonjs/web/features/asr.d.ts.map +1 -0
- package/lib/typescript/commonjs/web/features/audioTagging.d.ts +16 -0
- package/lib/typescript/commonjs/web/features/audioTagging.d.ts.map +1 -0
- package/lib/typescript/commonjs/web/features/denoising.d.ts +22 -0
- package/lib/typescript/commonjs/web/features/denoising.d.ts.map +1 -0
- package/lib/typescript/commonjs/web/features/diagnostics.d.ts +17 -0
- package/lib/typescript/commonjs/web/features/diagnostics.d.ts.map +1 -0
- package/lib/typescript/commonjs/web/features/diarization.d.ts +28 -0
- package/lib/typescript/commonjs/web/features/diarization.d.ts.map +1 -0
- package/lib/typescript/commonjs/web/features/kws.d.ts +27 -0
- package/lib/typescript/commonjs/web/features/kws.d.ts.map +1 -0
- package/lib/typescript/commonjs/web/features/languageId.d.ts +28 -0
- package/lib/typescript/commonjs/web/features/languageId.d.ts.map +1 -0
- package/lib/typescript/commonjs/web/features/mixinUtils.d.ts +9 -0
- package/lib/typescript/commonjs/web/features/mixinUtils.d.ts.map +1 -0
- package/lib/typescript/commonjs/web/features/punctuation.d.ts +21 -0
- package/lib/typescript/commonjs/web/features/punctuation.d.ts.map +1 -0
- package/lib/typescript/commonjs/web/features/speakerId.d.ts +25 -0
- package/lib/typescript/commonjs/web/features/speakerId.d.ts.map +1 -0
- package/lib/typescript/commonjs/web/features/tts.d.ts +20 -0
- package/lib/typescript/commonjs/web/features/tts.d.ts.map +1 -0
- package/lib/typescript/commonjs/web/features/vad.d.ts +26 -0
- package/lib/typescript/commonjs/web/features/vad.d.ts.map +1 -0
- package/lib/typescript/commonjs/web/wasmLoader.d.ts +18 -0
- package/lib/typescript/commonjs/web/wasmLoader.d.ts.map +1 -0
- package/lib/typescript/commonjs/web/wasmTypes.d.ts +470 -0
- package/lib/typescript/commonjs/web/wasmTypes.d.ts.map +1 -0
- package/lib/typescript/module/NativeSherpaOnnxSpec.d.ts +472 -0
- package/lib/typescript/module/NativeSherpaOnnxSpec.d.ts.map +1 -0
- package/lib/typescript/module/SherpaOnnxAPI.d.ts +3 -0
- package/lib/typescript/module/SherpaOnnxAPI.d.ts.map +1 -0
- package/lib/typescript/module/WebSherpaOnnxImpl.d.ts +214 -0
- package/lib/typescript/module/WebSherpaOnnxImpl.d.ts.map +1 -0
- package/lib/typescript/module/index.d.ts +27 -0
- package/lib/typescript/module/index.d.ts.map +1 -0
- package/lib/typescript/module/package.json +1 -0
- package/lib/typescript/module/services/ArchiveService.d.ts +65 -0
- package/lib/typescript/module/services/ArchiveService.d.ts.map +1 -0
- package/lib/typescript/module/services/AsrService.d.ts +72 -0
- package/lib/typescript/module/services/AsrService.d.ts.map +1 -0
- package/lib/typescript/module/services/AudioTaggingService.d.ts +35 -0
- package/lib/typescript/module/services/AudioTaggingService.d.ts.map +1 -0
- package/lib/typescript/module/services/DenoisingService.d.ts +16 -0
- package/lib/typescript/module/services/DenoisingService.d.ts.map +1 -0
- package/lib/typescript/module/services/DiarizationService.d.ts +16 -0
- package/lib/typescript/module/services/DiarizationService.d.ts.map +1 -0
- package/lib/typescript/module/services/KWSService.d.ts +40 -0
- package/lib/typescript/module/services/KWSService.d.ts.map +1 -0
- package/lib/typescript/module/services/LanguageIdService.d.ts +15 -0
- package/lib/typescript/module/services/LanguageIdService.d.ts.map +1 -0
- package/lib/typescript/module/services/PunctuationService.d.ts +14 -0
- package/lib/typescript/module/services/PunctuationService.d.ts.map +1 -0
- package/lib/typescript/module/services/SpeakerIdService.d.ts +99 -0
- package/lib/typescript/module/services/SpeakerIdService.d.ts.map +1 -0
- package/lib/typescript/module/services/TtsService.d.ts +51 -0
- package/lib/typescript/module/services/TtsService.d.ts.map +1 -0
- package/lib/typescript/module/services/VadService.d.ts +17 -0
- package/lib/typescript/module/services/VadService.d.ts.map +1 -0
- package/lib/typescript/module/types/api.d.ts +192 -0
- package/lib/typescript/module/types/api.d.ts.map +1 -0
- package/lib/typescript/module/types/interfaces.d.ts +1066 -0
- package/lib/typescript/module/types/interfaces.d.ts.map +1 -0
- package/lib/typescript/module/utils/fileUtils.d.ts +5 -0
- package/lib/typescript/module/utils/fileUtils.d.ts.map +1 -0
- package/lib/typescript/module/web/audioUtils.d.ts +21 -0
- package/lib/typescript/module/web/audioUtils.d.ts.map +1 -0
- package/lib/typescript/module/web/features/asr.d.ts +34 -0
- package/lib/typescript/module/web/features/asr.d.ts.map +1 -0
- package/lib/typescript/module/web/features/audioTagging.d.ts +16 -0
- package/lib/typescript/module/web/features/audioTagging.d.ts.map +1 -0
- package/lib/typescript/module/web/features/denoising.d.ts +22 -0
- package/lib/typescript/module/web/features/denoising.d.ts.map +1 -0
- package/lib/typescript/module/web/features/diagnostics.d.ts +17 -0
- package/lib/typescript/module/web/features/diagnostics.d.ts.map +1 -0
- package/lib/typescript/module/web/features/diarization.d.ts +28 -0
- package/lib/typescript/module/web/features/diarization.d.ts.map +1 -0
- package/lib/typescript/module/web/features/kws.d.ts +27 -0
- package/lib/typescript/module/web/features/kws.d.ts.map +1 -0
- package/lib/typescript/module/web/features/languageId.d.ts +28 -0
- package/lib/typescript/module/web/features/languageId.d.ts.map +1 -0
- package/lib/typescript/module/web/features/mixinUtils.d.ts +9 -0
- package/lib/typescript/module/web/features/mixinUtils.d.ts.map +1 -0
- package/lib/typescript/module/web/features/punctuation.d.ts +21 -0
- package/lib/typescript/module/web/features/punctuation.d.ts.map +1 -0
- package/lib/typescript/module/web/features/speakerId.d.ts +25 -0
- package/lib/typescript/module/web/features/speakerId.d.ts.map +1 -0
- package/lib/typescript/module/web/features/tts.d.ts +20 -0
- package/lib/typescript/module/web/features/tts.d.ts.map +1 -0
- package/lib/typescript/module/web/features/vad.d.ts +26 -0
- package/lib/typescript/module/web/features/vad.d.ts.map +1 -0
- package/lib/typescript/module/web/wasmLoader.d.ts +18 -0
- package/lib/typescript/module/web/wasmLoader.d.ts.map +1 -0
- package/lib/typescript/module/web/wasmTypes.d.ts +470 -0
- package/lib/typescript/module/web/wasmTypes.d.ts.map +1 -0
- package/package.json +211 -0
- package/react-native.config.js +19 -0
- package/setup.sh +50 -0
- package/sherpa-onnx-rn.podspec +205 -0
- package/src/NativeSherpaOnnxSpec.ts +537 -0
- package/src/SherpaOnnxAPI.ts +352 -0
- package/src/WebSherpaOnnxImpl.ts +39 -0
- package/src/index.ts +66 -0
- package/src/services/ArchiveService.ts +170 -0
- package/src/services/AsrService.ts +150 -0
- package/src/services/AudioTaggingService.ts +101 -0
- package/src/services/DenoisingService.ts +91 -0
- package/src/services/DiarizationService.ts +103 -0
- package/src/services/KWSService.ts +142 -0
- package/src/services/LanguageIdService.ts +117 -0
- package/src/services/PunctuationService.ts +92 -0
- package/src/services/SpeakerIdService.ts +415 -0
- package/src/services/TtsService.ts +256 -0
- package/src/services/VadService.ts +111 -0
- package/src/types/api.ts +235 -0
- package/src/types/expo-modules-core-shim.d.ts +10 -0
- package/src/types/interfaces.ts +1307 -0
- package/src/utils/fileUtils.ts +11 -0
- package/src/web/audioUtils.ts +158 -0
- package/src/web/features/asr.ts +222 -0
- package/src/web/features/audioTagging.ts +164 -0
- package/src/web/features/denoising.ts +127 -0
- package/src/web/features/diagnostics.ts +140 -0
- package/src/web/features/diarization.ts +145 -0
- package/src/web/features/kws.ts +216 -0
- package/src/web/features/languageId.ts +136 -0
- package/src/web/features/mixinUtils.ts +50 -0
- package/src/web/features/punctuation.ts +94 -0
- package/src/web/features/speakerId.ts +340 -0
- package/src/web/features/tts.ts +116 -0
- package/src/web/features/vad.ts +125 -0
- package/src/web/wasmLoader.ts +258 -0
- package/src/web/wasmTypes.ts +480 -0
package/README.md
ADDED
|
@@ -0,0 +1,374 @@
|
|
|
1
|
+
# @siteed/sherpa-onnx.rn
|
|
2
|
+
|
|
3
|
+
React Native wrapper for [sherpa-onnx](https://github.com/k2-fsa/sherpa-onnx) providing Text-to-Speech (TTS) and Speech-to-Text (STT) capabilities for mobile applications.
|
|
4
|
+
|
|
5
|
+
**Status: 🚧 In Development**
|
|
6
|
+
|
|
7
|
+
✅ **Native Integration Testing**: Complete framework with 100% test success rate
|
|
8
|
+
✅ **Model Management**: Lightweight strategy for CI to production environments
|
|
9
|
+
✅ **Cross-Platform**: Android support validated, iOS structure in place
|
|
10
|
+
⏳ **Architecture Support**: Old/New React Native architecture compatibility planned
|
|
11
|
+
|
|
12
|
+
## Features
|
|
13
|
+
|
|
14
|
+
- Speech-to-text (STT) using Sherpa-ONNX
|
|
15
|
+
- Streaming recognition support
|
|
16
|
+
- Low-level API for direct access to Sherpa-ONNX capabilities
|
|
17
|
+
- Support for both old and new React Native architectures
|
|
18
|
+
- Pre-built native libraries for Android and iOS
|
|
19
|
+
- **Web/WASM support** — all 10 features work in the browser via a combined WebAssembly build
|
|
20
|
+
|
|
21
|
+
## Installation
|
|
22
|
+
|
|
23
|
+
```sh
|
|
24
|
+
npm install @siteed/sherpa-onnx.rn
|
|
25
|
+
# or
|
|
26
|
+
yarn add @siteed/sherpa-onnx.rn
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
### Linking
|
|
30
|
+
|
|
31
|
+
This package is a native module and requires proper linking. For React Native 0.60 and above, linking should happen automatically through auto-linking.
|
|
32
|
+
|
|
33
|
+
If you're using Expo, you'll need to use a custom development client or eject to a bare workflow:
|
|
34
|
+
|
|
35
|
+
```sh
|
|
36
|
+
npx expo prebuild
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
### iOS
|
|
40
|
+
|
|
41
|
+
For iOS, run pod install:
|
|
42
|
+
|
|
43
|
+
```bash
|
|
44
|
+
cd ios && pod install
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
### Android
|
|
48
|
+
|
|
49
|
+
Android integration is handled automatically by the package.
|
|
50
|
+
|
|
51
|
+
## React Native Compatibility
|
|
52
|
+
|
|
53
|
+
This module is compatible with both the old and new React Native architectures. See [COMPATIBILITY.md](./COMPATIBILITY.md) for details on how this is achieved and considerations when using this module.
|
|
54
|
+
|
|
55
|
+
## Usage
|
|
56
|
+
|
|
57
|
+
### Text-to-Speech (TTS)
|
|
58
|
+
|
|
59
|
+
This example demonstrates how to use the TTS functionality:
|
|
60
|
+
|
|
61
|
+
```typescript
|
|
62
|
+
import SherpaOnnx, { TtsModelConfig } from '@siteed/sherpa-onnx.rn';
|
|
63
|
+
import { Audio } from 'expo-av';
|
|
64
|
+
import { Platform } from 'react-native';
|
|
65
|
+
|
|
66
|
+
// Initialize TTS
|
|
67
|
+
const initTts = async () => {
|
|
68
|
+
try {
|
|
69
|
+
// First validate the library is loaded
|
|
70
|
+
const validateResult = await SherpaOnnx.validateLibraryLoaded();
|
|
71
|
+
if (!validateResult.loaded) {
|
|
72
|
+
throw new Error(`Library validation failed: ${validateResult.status}`);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
// Configure TTS with your model
|
|
76
|
+
const modelConfig: TtsModelConfig = {
|
|
77
|
+
modelDir: 'assets/tts/kokoro-en-v0_19',
|
|
78
|
+
modelName: 'model.onnx',
|
|
79
|
+
voices: 'voices.bin',
|
|
80
|
+
dataDir: 'assets/tts/kokoro-en-v0_19/espeak-ng-data',
|
|
81
|
+
};
|
|
82
|
+
|
|
83
|
+
// Initialize TTS
|
|
84
|
+
const initResult = await SherpaOnnx.initTts(modelConfig);
|
|
85
|
+
console.log(`TTS initialized with ${initResult.numSpeakers} speakers at ${initResult.sampleRate}Hz`);
|
|
86
|
+
return initResult;
|
|
87
|
+
} catch (error) {
|
|
88
|
+
console.error('Failed to initialize TTS:', error);
|
|
89
|
+
throw error;
|
|
90
|
+
}
|
|
91
|
+
};
|
|
92
|
+
|
|
93
|
+
// Generate speech
|
|
94
|
+
const generateSpeech = async (text: string) => {
|
|
95
|
+
try {
|
|
96
|
+
// Generate TTS without playing (we'll play with Expo AV)
|
|
97
|
+
const result = await SherpaOnnx.generateTts(text, {
|
|
98
|
+
speakerId: 0,
|
|
99
|
+
speakingRate: 1.0,
|
|
100
|
+
playAudio: false
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
// Play with Expo AV
|
|
104
|
+
const { sound } = await Audio.Sound.createAsync({
|
|
105
|
+
uri: Platform.OS === 'ios' ? result.filePath : `file://${result.filePath}`
|
|
106
|
+
});
|
|
107
|
+
await sound.playAsync();
|
|
108
|
+
|
|
109
|
+
return { sound, result };
|
|
110
|
+
} catch (error) {
|
|
111
|
+
console.error('Failed to generate speech:', error);
|
|
112
|
+
throw error;
|
|
113
|
+
}
|
|
114
|
+
};
|
|
115
|
+
|
|
116
|
+
// Clean up resources
|
|
117
|
+
const cleanup = async () => {
|
|
118
|
+
await SherpaOnnx.releaseTts();
|
|
119
|
+
};
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
### Basic Speech-to-Text
|
|
123
|
+
|
|
124
|
+
```typescript
|
|
125
|
+
import { SherpaOnnxAPI } from '@siteed/sherpa-onnx.rn';
|
|
126
|
+
|
|
127
|
+
// Initialize the API
|
|
128
|
+
const sherpaOnnx = new SherpaOnnxAPI({
|
|
129
|
+
modelPath: '/path/to/models',
|
|
130
|
+
sampleRate: 16000,
|
|
131
|
+
channels: 1,
|
|
132
|
+
language: 'en',
|
|
133
|
+
});
|
|
134
|
+
|
|
135
|
+
// Initialize the recognizer
|
|
136
|
+
await sherpaOnnx.initialize();
|
|
137
|
+
|
|
138
|
+
// Convert speech to text from audio buffer
|
|
139
|
+
const audioData = [...]; // Array of audio samples
|
|
140
|
+
const result = await sherpaOnnx.speechToText(audioData);
|
|
141
|
+
console.log('Recognized text:', result.text);
|
|
142
|
+
|
|
143
|
+
// Or from an audio file
|
|
144
|
+
const fileResult = await sherpaOnnx.speechToText('/path/to/audio.wav');
|
|
145
|
+
console.log('Recognized text from file:', fileResult.text);
|
|
146
|
+
|
|
147
|
+
// Clean up when done
|
|
148
|
+
await sherpaOnnx.release();
|
|
149
|
+
```
|
|
150
|
+
|
|
151
|
+
### Streaming Recognition
|
|
152
|
+
|
|
153
|
+
```typescript
|
|
154
|
+
import { SherpaOnnxAPI } from '@siteed/sherpa-onnx.rn';
|
|
155
|
+
|
|
156
|
+
const sherpaOnnx = new SherpaOnnxAPI({
|
|
157
|
+
modelPath: '/path/to/models',
|
|
158
|
+
sampleRate: 16000,
|
|
159
|
+
});
|
|
160
|
+
|
|
161
|
+
// Initialize
|
|
162
|
+
await sherpaOnnx.initialize();
|
|
163
|
+
|
|
164
|
+
// Start streaming
|
|
165
|
+
await sherpaOnnx.startStreaming();
|
|
166
|
+
|
|
167
|
+
// Feed audio chunks
|
|
168
|
+
const audioChunk = [...]; // Array of audio samples from microphone
|
|
169
|
+
const partialResult = await sherpaOnnx.feedAudioContent(audioChunk);
|
|
170
|
+
console.log('Partial result:', partialResult.text);
|
|
171
|
+
|
|
172
|
+
// Stop streaming when done
|
|
173
|
+
const finalResult = await sherpaOnnx.stopStreaming();
|
|
174
|
+
console.log('Final result:', finalResult.text);
|
|
175
|
+
|
|
176
|
+
// Clean up
|
|
177
|
+
await sherpaOnnx.release();
|
|
178
|
+
```
|
|
179
|
+
|
|
180
|
+
### Low-level API
|
|
181
|
+
|
|
182
|
+
For advanced usage, you can access the low-level API that maps directly to Sherpa-ONNX functions:
|
|
183
|
+
|
|
184
|
+
```typescript
|
|
185
|
+
import { NativeModules } from 'react-native';
|
|
186
|
+
const { SherpaOnnx } = NativeModules;
|
|
187
|
+
|
|
188
|
+
// Create a recognizer
|
|
189
|
+
const config = {
|
|
190
|
+
sampleRate: 16000,
|
|
191
|
+
featureDim: 80,
|
|
192
|
+
modelType: 'transducer',
|
|
193
|
+
transducer: {
|
|
194
|
+
encoder: '/path/to/encoder.onnx',
|
|
195
|
+
decoder: '/path/to/decoder.onnx',
|
|
196
|
+
joiner: '/path/to/joiner.onnx',
|
|
197
|
+
},
|
|
198
|
+
tokens: '/path/to/tokens.txt',
|
|
199
|
+
enableEndpoint: true,
|
|
200
|
+
};
|
|
201
|
+
|
|
202
|
+
const recognizerId = await SherpaOnnx.createRecognizer(config);
|
|
203
|
+
|
|
204
|
+
// Create a stream
|
|
205
|
+
const streamId = await SherpaOnnx.createStream(recognizerId, '');
|
|
206
|
+
|
|
207
|
+
// Process audio
|
|
208
|
+
const samples = [...]; // Float array of audio samples
|
|
209
|
+
await SherpaOnnx.acceptWaveform(streamId, samples, 16000);
|
|
210
|
+
await SherpaOnnx.decode(recognizerId, streamId);
|
|
211
|
+
|
|
212
|
+
// Get results
|
|
213
|
+
const result = await SherpaOnnx.getResult(recognizerId, streamId);
|
|
214
|
+
console.log('Text:', result.text);
|
|
215
|
+
|
|
216
|
+
// Clean up
|
|
217
|
+
await SherpaOnnx.releaseStream(streamId);
|
|
218
|
+
await SherpaOnnx.releaseRecognizer(recognizerId);
|
|
219
|
+
```
|
|
220
|
+
|
|
221
|
+
## Models
|
|
222
|
+
|
|
223
|
+
You need to provide Sherpa-ONNX model files to use this library. You can download pre-trained models from the [Sherpa-ONNX](https://github.com/k2-fsa/sherpa-onnx) repository or train your own.
|
|
224
|
+
|
|
225
|
+
The most common model types are:
|
|
226
|
+
- Transducer models (encoder, decoder, joiner)
|
|
227
|
+
- CTC models (single model file)
|
|
228
|
+
- Paraformer models (encoder, decoder)
|
|
229
|
+
|
|
230
|
+
## Building from Source
|
|
231
|
+
|
|
232
|
+
If you need to build the native libraries yourself:
|
|
233
|
+
|
|
234
|
+
```bash
|
|
235
|
+
# Clone the repository
|
|
236
|
+
git clone https://github.com/yourusername/yourrepo.git
|
|
237
|
+
cd yourrepo/packages/sherpa-onnx.rn
|
|
238
|
+
|
|
239
|
+
# Set up dependencies
|
|
240
|
+
./setup.sh
|
|
241
|
+
|
|
242
|
+
# Build for all platforms
|
|
243
|
+
./build-all.sh
|
|
244
|
+
```
|
|
245
|
+
|
|
246
|
+
## API Reference
|
|
247
|
+
|
|
248
|
+
### Library Validation
|
|
249
|
+
|
|
250
|
+
#### `validateLibraryLoaded()`
|
|
251
|
+
|
|
252
|
+
Validates if the Sherpa ONNX library is properly loaded.
|
|
253
|
+
|
|
254
|
+
**Returns:** Promise<ValidateResult>
|
|
255
|
+
|
|
256
|
+
### Text-to-Speech
|
|
257
|
+
|
|
258
|
+
#### `initTts(config: TtsModelConfig)`
|
|
259
|
+
|
|
260
|
+
Initializes the TTS engine with the provided model configuration.
|
|
261
|
+
|
|
262
|
+
**Parameters:**
|
|
263
|
+
- `config`: TTS model configuration
|
|
264
|
+
|
|
265
|
+
**Returns:** Promise<TtsInitResult>
|
|
266
|
+
|
|
267
|
+
#### `generateTts(text: string, options?: TtsOptions)`
|
|
268
|
+
|
|
269
|
+
Generates speech from the given text.
|
|
270
|
+
|
|
271
|
+
**Parameters:**
|
|
272
|
+
- `text`: Text to synthesize
|
|
273
|
+
- `options`: TTS generation options (optional)
|
|
274
|
+
|
|
275
|
+
**Returns:** Promise<TtsGenerateResult>
|
|
276
|
+
|
|
277
|
+
#### `stopTts()`
|
|
278
|
+
|
|
279
|
+
Stops any ongoing TTS generation.
|
|
280
|
+
|
|
281
|
+
**Returns:** Promise<{ stopped: boolean; message?: string }>
|
|
282
|
+
|
|
283
|
+
#### `releaseTts()`
|
|
284
|
+
|
|
285
|
+
Releases TTS resources.
|
|
286
|
+
|
|
287
|
+
**Returns:** Promise<{ released: boolean }>
|
|
288
|
+
|
|
289
|
+
## Model Configuration
|
|
290
|
+
|
|
291
|
+
### TtsModelConfig
|
|
292
|
+
|
|
293
|
+
```typescript
|
|
294
|
+
interface TtsModelConfig {
|
|
295
|
+
// Directory containing model files
|
|
296
|
+
modelDir: string;
|
|
297
|
+
|
|
298
|
+
// Model file name for VITS models
|
|
299
|
+
modelName?: string;
|
|
300
|
+
|
|
301
|
+
// Acoustic model file name for Matcha models
|
|
302
|
+
acousticModelName?: string;
|
|
303
|
+
|
|
304
|
+
// Vocoder file name for Matcha models
|
|
305
|
+
vocoder?: string;
|
|
306
|
+
|
|
307
|
+
// Voices file name for Kokoro models
|
|
308
|
+
voices?: string;
|
|
309
|
+
|
|
310
|
+
// Lexicon file name
|
|
311
|
+
lexicon?: string;
|
|
312
|
+
|
|
313
|
+
// Data directory path
|
|
314
|
+
dataDir?: string;
|
|
315
|
+
|
|
316
|
+
// Dictionary directory path
|
|
317
|
+
dictDir?: string;
|
|
318
|
+
|
|
319
|
+
// Rule FSTs file paths (comma-separated)
|
|
320
|
+
ruleFsts?: string;
|
|
321
|
+
|
|
322
|
+
// Rule FARs file paths (comma-separated)
|
|
323
|
+
ruleFars?: string;
|
|
324
|
+
|
|
325
|
+
// Number of threads to use for processing
|
|
326
|
+
numThreads?: number;
|
|
327
|
+
}
|
|
328
|
+
```
|
|
329
|
+
|
|
330
|
+
## Troubleshooting
|
|
331
|
+
|
|
332
|
+
### Android
|
|
333
|
+
|
|
334
|
+
If you're having issues with the Android build, check that:
|
|
335
|
+
|
|
336
|
+
1. The Kotlin standard library is properly included in your app's `build.gradle`
|
|
337
|
+
2. JNI libraries are properly included in the build
|
|
338
|
+
|
|
339
|
+
### iOS
|
|
340
|
+
|
|
341
|
+
For iOS, ensure that:
|
|
342
|
+
|
|
343
|
+
1. The necessary static libraries are included in your Xcode project
|
|
344
|
+
2. The pod installation completed successfully
|
|
345
|
+
|
|
346
|
+
## Documentation
|
|
347
|
+
|
|
348
|
+
- **[Web/WASM Guide](docs/WEB.md)** - How to deploy on web: setup, model customization, feature selection
|
|
349
|
+
- **[WASM Build Guide](docs/WASM_BUILD.md)** - Building the WASM binary from source
|
|
350
|
+
- **[Testing Framework](docs/testing/)** - Native integration testing documentation
|
|
351
|
+
- **[Architecture](docs/architecture/)** - React Native architecture support and planning
|
|
352
|
+
- **[Integration](docs/integration/)** - Platform integration guides
|
|
353
|
+
- **[Compatibility](COMPATIBILITY.md)** - React Native version and platform compatibility
|
|
354
|
+
|
|
355
|
+
## Development Status
|
|
356
|
+
|
|
357
|
+
### ✅ Completed
|
|
358
|
+
- Native integration testing framework (12 tests, 100% success rate)
|
|
359
|
+
- Model management strategy for testing environments
|
|
360
|
+
- Android native library integration validation
|
|
361
|
+
- Cross-platform documentation structure
|
|
362
|
+
|
|
363
|
+
### ⏳ In Progress / Planned
|
|
364
|
+
- React Native architecture-specific validation (Old vs New Architecture)
|
|
365
|
+
- Real ONNX model functionality testing
|
|
366
|
+
- iOS integration validation
|
|
367
|
+
|
|
368
|
+
## Contributing
|
|
369
|
+
|
|
370
|
+
See the testing framework in [`docs/testing/`](docs/testing/) for validation methodology and development workflow.
|
|
371
|
+
|
|
372
|
+
## License
|
|
373
|
+
|
|
374
|
+
MIT
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
cmake_minimum_required(VERSION 3.4.1)
|
|
2
|
+
|
|
3
|
+
# Set path to prebuilt libraries
|
|
4
|
+
set(PREBUILT_DIR ${CMAKE_CURRENT_SOURCE_DIR}/src/main/jniLibs)
|
|
5
|
+
|
|
6
|
+
# Include C++ header files
|
|
7
|
+
include_directories(${PREBUILT_DIR}/include)
|
|
8
|
+
|
|
9
|
+
# Add sherpa-onnx-jni library
|
|
10
|
+
add_library(sherpa-onnx-jni SHARED IMPORTED)
|
|
11
|
+
set_target_properties(sherpa-onnx-jni PROPERTIES IMPORTED_LOCATION
|
|
12
|
+
${PREBUILT_DIR}/${ANDROID_ABI}/libsherpa-onnx-jni.so)
|
|
13
|
+
|
|
14
|
+
# Add onnxruntime library
|
|
15
|
+
add_library(onnxruntime SHARED IMPORTED)
|
|
16
|
+
set_target_properties(onnxruntime PROPERTIES IMPORTED_LOCATION
|
|
17
|
+
${PREBUILT_DIR}/${ANDROID_ABI}/libonnxruntime.so)
|
|
18
|
+
|
|
19
|
+
# Add dummy implementation to help with IDE resolving
|
|
20
|
+
add_library(sherpa-onnx-dummy SHARED
|
|
21
|
+
${CMAKE_CURRENT_SOURCE_DIR}/../cpp/dummy/dummy.cpp
|
|
22
|
+
)
|
|
23
|
+
|
|
24
|
+
# 16KB page size alignment for Android 15+ (required for Play Store)
|
|
25
|
+
target_link_options(sherpa-onnx-dummy PRIVATE "-Wl,-z,max-page-size=16384")
|
|
26
|
+
|
|
27
|
+
# Check if we should include TurboModule support
|
|
28
|
+
if(${NEW_ARCHITECTURE_ENABLED})
|
|
29
|
+
# These paths would be needed for TurboModule implementation
|
|
30
|
+
include_directories(
|
|
31
|
+
"${NODE_MODULES_DIR}/react-native/ReactCommon"
|
|
32
|
+
"${NODE_MODULES_DIR}/react-native/ReactCommon/callinvoker"
|
|
33
|
+
"${NODE_MODULES_DIR}/react-native/ReactCommon/jsi"
|
|
34
|
+
"${NODE_MODULES_DIR}/react-native/ReactCommon/turbomodule/core"
|
|
35
|
+
"${NODE_MODULES_DIR}/react-native/ReactCommon/react/nativemodule/core"
|
|
36
|
+
)
|
|
37
|
+
endif()
|
|
38
|
+
|
|
39
|
+
# If we need to add our own native code, uncomment and customize:
|
|
40
|
+
# add_library(sherpa-onnx-extra SHARED
|
|
41
|
+
# src/main/cpp/sherpa-onnx-extra.cpp
|
|
42
|
+
# )
|
|
43
|
+
|
|
44
|
+
# Create an interface library for the JNI libraries
|
|
45
|
+
add_library(sherpa-onnx-rn INTERFACE)
|
|
46
|
+
target_link_libraries(sherpa-onnx-rn INTERFACE sherpa-onnx-jni onnxruntime sherpa-onnx-dummy)
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
# Android Implementation for @siteed/sherpa-onnx.rn
|
|
2
|
+
|
|
3
|
+
This directory contains the Android native implementation for the Sherpa ONNX React Native module.
|
|
4
|
+
|
|
5
|
+
## Architecture
|
|
6
|
+
|
|
7
|
+
The implementation consists of:
|
|
8
|
+
|
|
9
|
+
1. **Kotlin Native Module** (`SherpaOnnxModule.kt`): A simple React Native module implementation that loads the Sherpa ONNX JNI library and provides placeholder methods for the JavaScript API.
|
|
10
|
+
|
|
11
|
+
2. **JNI Libraries** (in `src/main/jniLibs/`): Native `.so` libraries for different architectures that implement the actual speech recognition functionality.
|
|
12
|
+
|
|
13
|
+
3. **New Architecture Compatibility** (in `build/generated/source/codegen/jni/`): Placeholder C++ files to ensure compatibility with React Native's New Architecture.
|
|
14
|
+
|
|
15
|
+
## Building the Module
|
|
16
|
+
|
|
17
|
+
The module has been set up with automated scripts to handle the build process:
|
|
18
|
+
|
|
19
|
+
1. **setup.sh**: Clones the Sherpa ONNX repository into `third_party/`.
|
|
20
|
+
|
|
21
|
+
2. **build-sherpa-android.sh**: Builds the Sherpa ONNX native libraries for Android using the Sherpa ONNX build scripts.
|
|
22
|
+
|
|
23
|
+
3. **copy-libs.sh**: Copies the built native libraries to the correct location in the Android project.
|
|
24
|
+
|
|
25
|
+
## Build Process
|
|
26
|
+
|
|
27
|
+
The standard build process is:
|
|
28
|
+
|
|
29
|
+
1. Run `npm run setup` to clone the Sherpa ONNX repository.
|
|
30
|
+
2. Run `npm run build:android` to build the Sherpa ONNX native libraries.
|
|
31
|
+
3. Run `npm run copy:libs` to copy the libraries to the correct locations.
|
|
32
|
+
|
|
33
|
+
These steps are automated as part of the module's `postinstall` script.
|
|
34
|
+
|
|
35
|
+
## Compatibility with React Native
|
|
36
|
+
|
|
37
|
+
The module supports both the Old and New React Native architectures:
|
|
38
|
+
|
|
39
|
+
- **Old Architecture**: Uses Kotlin implementation via `ReactContextBaseJavaModule`.
|
|
40
|
+
- **New Architecture**: Uses placeholder C++ files to satisfy build requirements.
|
|
41
|
+
|
|
42
|
+
## Implementing Speech Recognition
|
|
43
|
+
|
|
44
|
+
The current implementation provides a minimal set of placeholder methods. To implement actual speech recognition functionality, you'll need to:
|
|
45
|
+
|
|
46
|
+
1. Call the Sherpa ONNX JNI methods directly from the Kotlin code
|
|
47
|
+
2. Process audio data and return results
|
|
48
|
+
3. Update the TypeScript interfaces to match your implementation
|
|
49
|
+
|
|
50
|
+
## JVM Compatibility
|
|
51
|
+
|
|
52
|
+
The module is configured to use Java 17, which is required for modern React Native applications. This is set in the `build.gradle` file:
|
|
53
|
+
|
|
54
|
+
```gradle
|
|
55
|
+
compileOptions {
|
|
56
|
+
sourceCompatibility JavaVersion.VERSION_17
|
|
57
|
+
targetCompatibility JavaVersion.VERSION_17
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
kotlinOptions {
|
|
61
|
+
jvmTarget = '17'
|
|
62
|
+
}
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
## Troubleshooting
|
|
66
|
+
|
|
67
|
+
### Missing JNI Libraries
|
|
68
|
+
If you encounter errors about missing native libraries, make sure you've run:
|
|
69
|
+
```
|
|
70
|
+
npm run build:android
|
|
71
|
+
npm run copy:libs
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
### New Architecture Compatibility
|
|
75
|
+
If you have build errors in a New Architecture app, check that:
|
|
76
|
+
1. The placeholder C++ files exist in `build/generated/source/codegen/jni/`
|
|
77
|
+
2. Your app's gradle version is compatible with the module's configuration
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
buildscript {
|
|
2
|
+
ext.safeExtGet = { prop, fallback ->
|
|
3
|
+
rootProject.ext.has(prop) ? rootProject.ext.get(prop) : fallback
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
repositories {
|
|
7
|
+
google()
|
|
8
|
+
mavenCentral()
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
dependencies {
|
|
12
|
+
classpath("com.android.tools.build:gradle:7.2.1")
|
|
13
|
+
classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:1.8.0")
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
// For backwards compatibility with older React Native versions
|
|
18
|
+
def REACT_NATIVE_VERSION = safeExtGet('reactNativeVersion', '+')
|
|
19
|
+
|
|
20
|
+
apply plugin: 'com.android.library'
|
|
21
|
+
apply plugin: 'com.facebook.react'
|
|
22
|
+
apply plugin: 'kotlin-android'
|
|
23
|
+
apply plugin: 'kotlin-parcelize'
|
|
24
|
+
|
|
25
|
+
android {
|
|
26
|
+
namespace "net.siteed.sherpaonnx"
|
|
27
|
+
compileSdkVersion safeExtGet('compileSdkVersion', 34)
|
|
28
|
+
buildToolsVersion safeExtGet('buildToolsVersion', '34.0.0')
|
|
29
|
+
|
|
30
|
+
defaultConfig {
|
|
31
|
+
minSdkVersion safeExtGet('minSdkVersion', 21)
|
|
32
|
+
targetSdkVersion safeExtGet('targetSdkVersion', 34)
|
|
33
|
+
versionCode 1
|
|
34
|
+
versionName "1.0"
|
|
35
|
+
|
|
36
|
+
// Test instrumentation runner for integration tests
|
|
37
|
+
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
|
|
38
|
+
|
|
39
|
+
ndk {
|
|
40
|
+
abiFilters 'arm64-v8a', 'armeabi-v7a', 'x86_64'
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
sourceSets {
|
|
45
|
+
main {
|
|
46
|
+
// Include prebuilt libraries in the correct location
|
|
47
|
+
jniLibs.srcDirs = ['src/main/jniLibs']
|
|
48
|
+
|
|
49
|
+
// Add Java source directory for compatibility
|
|
50
|
+
java.srcDirs = ['src/main/java']
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
// Configure Kotlin source directories
|
|
55
|
+
kotlin {
|
|
56
|
+
sourceSets {
|
|
57
|
+
main {
|
|
58
|
+
kotlin.srcDirs = ['src/main/kotlin']
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
buildTypes {
|
|
64
|
+
release {
|
|
65
|
+
minifyEnabled false
|
|
66
|
+
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
// IMPORTANT: These Java compatibility settings must match the React Native app
|
|
71
|
+
compileOptions {
|
|
72
|
+
sourceCompatibility JavaVersion.VERSION_17
|
|
73
|
+
targetCompatibility JavaVersion.VERSION_17
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
kotlinOptions {
|
|
77
|
+
jvmTarget = '17'
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
// This ensures the library is compiled as an AAR with the JNI libraries included
|
|
81
|
+
packagingOptions {
|
|
82
|
+
pickFirst '**/*.so'
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
// Add local project sources for Sherpa ONNX Kotlin classes
|
|
86
|
+
externalNativeBuild {
|
|
87
|
+
cmake {
|
|
88
|
+
path "CMakeLists.txt"
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
|
|
94
|
+
repositories {
|
|
95
|
+
google()
|
|
96
|
+
mavenCentral()
|
|
97
|
+
mavenLocal()
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
dependencies {
|
|
101
|
+
// Kotlin standard library must come first - this is critical
|
|
102
|
+
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.8.0"
|
|
103
|
+
implementation "org.jetbrains.kotlin:kotlin-stdlib:1.8.0"
|
|
104
|
+
implementation "org.jetbrains.kotlin:kotlin-stdlib-common:1.8.0"
|
|
105
|
+
implementation "org.jetbrains.kotlin:kotlin-reflect:1.8.0"
|
|
106
|
+
|
|
107
|
+
// React Native dependencies
|
|
108
|
+
implementation "com.facebook.react:react-native:${REACT_NATIVE_VERSION}"
|
|
109
|
+
|
|
110
|
+
// Android support libraries
|
|
111
|
+
implementation "androidx.annotation:annotation:1.5.0"
|
|
112
|
+
implementation "androidx.core:core-ktx:1.9.0"
|
|
113
|
+
implementation "androidx.media:media:1.6.0" // For AudioTrack and related classes
|
|
114
|
+
|
|
115
|
+
// Apache Commons Compress for tar.bz2 extraction
|
|
116
|
+
implementation "org.apache.commons:commons-compress:1.23.0"
|
|
117
|
+
|
|
118
|
+
// OkHttp for model downloads
|
|
119
|
+
implementation "com.squareup.okhttp3:okhttp:4.11.0"
|
|
120
|
+
|
|
121
|
+
// Kotlin coroutines for async operations
|
|
122
|
+
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:1.7.3"
|
|
123
|
+
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:1.7.3"
|
|
124
|
+
|
|
125
|
+
// Make sure we have the actual sherpa-onnx library dependencies
|
|
126
|
+
// First check if there are prebuilt libraries in the jniLibs folder
|
|
127
|
+
if (file("src/main/jniLibs").exists()) {
|
|
128
|
+
println("Using prebuilt sherpa-onnx libraries from jniLibs directory")
|
|
129
|
+
} else {
|
|
130
|
+
println("WARNING: No prebuilt libraries found in jniLibs directory!")
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
// Test dependencies
|
|
134
|
+
testImplementation "junit:junit:4.13.2"
|
|
135
|
+
androidTestImplementation "androidx.test.ext:junit:1.1.5"
|
|
136
|
+
androidTestImplementation "androidx.test.espresso:espresso-core:3.5.1"
|
|
137
|
+
androidTestImplementation "androidx.test:runner:1.5.2"
|
|
138
|
+
androidTestImplementation "androidx.test:rules:1.5.0"
|
|
139
|
+
|
|
140
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
# Keep sherpa-onnx JNI classes
|
|
2
|
+
-keep class com.k2fsa.sherpa.onnx.** { *; }
|
|
3
|
+
|
|
4
|
+
# Keep React Native related code
|
|
5
|
+
-keep,allowobfuscation @interface com.facebook.proguard.annotations.DoNotStrip
|
|
6
|
+
-keep,allowobfuscation @interface com.facebook.proguard.annotations.KeepGettersAndSetters
|
|
7
|
+
-keep,allowobfuscation @interface com.facebook.common.internal.DoNotStrip
|
|
8
|
+
|
|
9
|
+
-keep @com.facebook.proguard.annotations.DoNotStrip class *
|
|
10
|
+
-keep @com.facebook.common.internal.DoNotStrip class *
|
|
11
|
+
-keepclassmembers class * {
|
|
12
|
+
@com.facebook.proguard.annotations.DoNotStrip *;
|
|
13
|
+
@com.facebook.common.internal.DoNotStrip *;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
-keepclassmembers @com.facebook.proguard.annotations.KeepGettersAndSetters class * {
|
|
17
|
+
void set*(***);
|
|
18
|
+
*** get*();
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
# Keep JNI methods
|
|
22
|
+
-keepclasseswithmembernames class * {
|
|
23
|
+
native <methods>;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
# Keep native libraries
|
|
27
|
+
-keepclasseswithmembernames class * {
|
|
28
|
+
native <methods>;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
# Keep all classes in our namespace
|
|
32
|
+
-keep class net.siteed.sherpaonnx.** { *; }
|