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/lib/module/tts/types.js
CHANGED
|
@@ -1,4 +1,89 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
/**
|
|
4
|
+
* Supported TTS model types.
|
|
5
|
+
*
|
|
6
|
+
* - 'vits': VITS models (includes Piper, Coqui, MeloTTS, MMS variants)
|
|
7
|
+
* - 'matcha': Matcha models (acoustic model + vocoder)
|
|
8
|
+
* - 'kokoro': Kokoro models (multi-speaker, multi-language)
|
|
9
|
+
* - 'kitten': KittenTTS models (lightweight, multi-speaker)
|
|
10
|
+
* - 'pocket': Pocket TTS models
|
|
11
|
+
* - 'zipvoice': Zipvoice models (voice cloning capable)
|
|
12
|
+
* - 'auto': Auto-detect model type based on files present (default)
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
/** Runtime list of supported TTS model types. */
|
|
16
|
+
export const TTS_MODEL_TYPES = ['vits', 'matcha', 'kokoro', 'kitten', 'pocket', 'zipvoice', 'auto'];
|
|
17
|
+
|
|
18
|
+
// ========== Model-specific options (only applied when that model type is loaded) ==========
|
|
19
|
+
|
|
20
|
+
/** Options for VITS models. Applied only when modelType is 'vits'. Kotlin OfflineTtsVitsModelConfig. */
|
|
21
|
+
|
|
22
|
+
/** Options for Matcha models. Applied only when modelType is 'matcha'. Kotlin OfflineTtsMatchaModelConfig. */
|
|
23
|
+
|
|
24
|
+
/** Options for Kokoro models. Applied only when modelType is 'kokoro'. Kotlin OfflineTtsKokoroModelConfig. */
|
|
25
|
+
|
|
26
|
+
/** Options for KittenTTS models. Applied only when modelType is 'kitten'. Kotlin OfflineTtsKittenModelConfig. */
|
|
27
|
+
|
|
28
|
+
/** Options for Pocket TTS models. Applied only when modelType is 'pocket'. Kotlin has no init-time model config for pocket; reserved for future use. */
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Model-specific TTS options. Only the block for the actually loaded model type is applied;
|
|
32
|
+
* others are ignored (e.g. vits options have no effect when a kokoro model is loaded).
|
|
33
|
+
*/
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Configuration for TTS initialization.
|
|
37
|
+
*/
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Options for updating TTS model parameters at runtime.
|
|
41
|
+
* Only the block for the given modelType is applied; flattened to native noiseScale / noiseScaleW / lengthScale.
|
|
42
|
+
*/
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Options for TTS generation. Maps to Kotlin GenerationConfig when reference
|
|
46
|
+
* audio or advanced options are used; otherwise simple sid/speed are used.
|
|
47
|
+
*/
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Generated audio data from TTS synthesis.
|
|
51
|
+
*
|
|
52
|
+
* The samples are normalized float values in the range [-1.0, 1.0].
|
|
53
|
+
* To save as a WAV file or play the audio, you'll need to convert
|
|
54
|
+
* these samples to the appropriate format for your use case.
|
|
55
|
+
*/
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* Subtitle/timestamp item for synthesized speech.
|
|
59
|
+
*/
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* Generated audio with subtitle/timestamp metadata.
|
|
63
|
+
*/
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* Streaming chunk event payload for TTS generation.
|
|
67
|
+
*/
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* Streaming end event payload.
|
|
71
|
+
*/
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* Streaming error event payload.
|
|
75
|
+
*/
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* Handlers for TTS streaming generation (chunk, end, error).
|
|
79
|
+
*/
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* Instance-based TTS engine returned by createTTS().
|
|
83
|
+
* Call destroy() when done to free native resources.
|
|
84
|
+
*/
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* Information about TTS model capabilities.
|
|
88
|
+
*/
|
|
4
89
|
//# sourceMappingURL=types.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":[],"sourceRoot":"
|
|
1
|
+
{"version":3,"names":["TTS_MODEL_TYPES"],"sourceRoot":"../../../src","sources":["tts/types.ts"],"mappings":";;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAUA;AACA,OAAO,MAAMA,eAAwC,GAAG,CACtD,MAAM,EACN,QAAQ,EACR,QAAQ,EACR,QAAQ,EACR,QAAQ,EACR,UAAU,EACV,MAAM,CACE;;AAEV;;AAEA;;AAUA;;AAQA;;AAMA;;AAMA;;AAKA;AACA;AACA;AACA;;AASA;AACA;AACA;;AAuEA;AACA;AACA;AACA;;AAcA;AACA;AACA;AACA;;AAsDA;AACA;AACA;AACA;AACA;AACA;AACA;;AAeA;AACA;AACA;;AAkBA;AACA;AACA;;AAaA;AACA;AACA;;AAUA;AACA;AACA;;AAOA;AACA;AACA;;AAOA;AACA;AACA;;AAOA;AACA;AACA;AACA;;AA8BA;AACA;AACA","ignoreList":[]}
|
package/lib/module/types.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":[],"sourceRoot":"
|
|
1
|
+
{"version":3,"names":[],"sourceRoot":"../../src","sources":["types.ts"],"mappings":"","ignoreList":[]}
|
package/lib/module/utils.js
CHANGED
|
@@ -3,22 +3,17 @@
|
|
|
3
3
|
import { Platform } from 'react-native';
|
|
4
4
|
import SherpaOnnx from "./NativeSherpaOnnx.js";
|
|
5
5
|
|
|
6
|
-
/**
|
|
7
|
-
* Utility functions for model path handling
|
|
6
|
+
/**
|
|
7
|
+
* Utility functions for model path handling
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
|
-
/**
|
|
11
|
-
*
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
/**
|
|
18
|
-
* Get the default model directory path for the current platform.
|
|
19
|
-
* This is a helper for apps that want to use a standard location.
|
|
20
|
-
*
|
|
21
|
-
* @returns Platform-specific default path
|
|
10
|
+
/**
|
|
11
|
+
* Get the default model directory path for the current platform.
|
|
12
|
+
* This is a logical name (e.g. `'Documents/models'` on iOS), not an absolute path.
|
|
13
|
+
* On iOS, when using file-based models without PAD, pass an absolute base path to
|
|
14
|
+
* `getFileModelPath` instead (e.g. `DocumentDirectoryPath + '/models'` from react-native-fs).
|
|
15
|
+
*
|
|
16
|
+
* @returns Platform-specific default path
|
|
22
17
|
*/
|
|
23
18
|
export function getDefaultModelPath() {
|
|
24
19
|
if (Platform.OS === 'ios') {
|
|
@@ -30,12 +25,12 @@ export function getDefaultModelPath() {
|
|
|
30
25
|
}
|
|
31
26
|
}
|
|
32
27
|
|
|
33
|
-
/**
|
|
34
|
-
* Create a model path configuration for asset models.
|
|
35
|
-
* Use this when models are bundled in your app's assets.
|
|
36
|
-
*
|
|
37
|
-
* @param assetPath - Path relative to assets (e.g., "models/sherpa-onnx-model")
|
|
38
|
-
* @returns Model path configuration
|
|
28
|
+
/**
|
|
29
|
+
* Create a model path configuration for asset models.
|
|
30
|
+
* Use this when models are bundled in your app's assets.
|
|
31
|
+
*
|
|
32
|
+
* @param assetPath - Path relative to assets (e.g., "models/sherpa-onnx-model")
|
|
33
|
+
* @returns Model path configuration
|
|
39
34
|
*/
|
|
40
35
|
export function assetModelPath(assetPath) {
|
|
41
36
|
return {
|
|
@@ -44,12 +39,14 @@ export function assetModelPath(assetPath) {
|
|
|
44
39
|
};
|
|
45
40
|
}
|
|
46
41
|
|
|
47
|
-
/**
|
|
48
|
-
* Create a model path configuration for file system models.
|
|
49
|
-
* Use this when models are downloaded or stored in file system.
|
|
50
|
-
*
|
|
51
|
-
* @param filePath - Absolute path to model directory
|
|
52
|
-
*
|
|
42
|
+
/**
|
|
43
|
+
* Create a model path configuration for file system models.
|
|
44
|
+
* Use this when models are downloaded or stored in file system.
|
|
45
|
+
*
|
|
46
|
+
* @param filePath - Absolute path to model directory. On iOS, use an absolute path
|
|
47
|
+
* (e.g. from react-native-fs: `DocumentDirectoryPath + '/models/' + modelName` when
|
|
48
|
+
* using getFileModelPath without PAD).
|
|
49
|
+
* @returns Model path configuration
|
|
53
50
|
*/
|
|
54
51
|
export function fileModelPath(filePath) {
|
|
55
52
|
return {
|
|
@@ -58,12 +55,12 @@ export function fileModelPath(filePath) {
|
|
|
58
55
|
};
|
|
59
56
|
}
|
|
60
57
|
|
|
61
|
-
/**
|
|
62
|
-
* Create a model path configuration with auto-detection.
|
|
63
|
-
* Tries asset first, then file system.
|
|
64
|
-
*
|
|
65
|
-
* @param path - Path to try (will be checked as both asset and file)
|
|
66
|
-
* @returns Model path configuration
|
|
58
|
+
/**
|
|
59
|
+
* Create a model path configuration with auto-detection.
|
|
60
|
+
* Tries asset first, then file system.
|
|
61
|
+
*
|
|
62
|
+
* @param path - Path to try (will be checked as both asset and file)
|
|
63
|
+
* @returns Model path configuration
|
|
67
64
|
*/
|
|
68
65
|
export function autoModelPath(path) {
|
|
69
66
|
return {
|
|
@@ -72,54 +69,70 @@ export function autoModelPath(path) {
|
|
|
72
69
|
};
|
|
73
70
|
}
|
|
74
71
|
|
|
75
|
-
/**
|
|
76
|
-
* Resolve model path based on configuration.
|
|
77
|
-
* This handles different path types (asset, file, auto) and returns
|
|
78
|
-
* a platform-specific absolute path that can be used by native code.
|
|
79
|
-
*
|
|
80
|
-
* @param config - Model path configuration
|
|
81
|
-
* @returns Promise resolving to absolute path usable by native code
|
|
72
|
+
/**
|
|
73
|
+
* Resolve model path based on configuration.
|
|
74
|
+
* This handles different path types (asset, file, auto) and returns
|
|
75
|
+
* a platform-specific absolute path that can be used by native code.
|
|
76
|
+
*
|
|
77
|
+
* @param config - Model path configuration
|
|
78
|
+
* @returns Promise resolving to absolute path usable by native code
|
|
82
79
|
*/
|
|
83
80
|
export async function resolveModelPath(config) {
|
|
84
|
-
// Backward compatibility: if string is passed, treat as auto
|
|
85
|
-
if (typeof config === 'string') {
|
|
86
|
-
return SherpaOnnx.resolveModelPath({
|
|
87
|
-
type: 'auto',
|
|
88
|
-
path: config
|
|
89
|
-
});
|
|
90
|
-
}
|
|
91
81
|
return SherpaOnnx.resolveModelPath(config);
|
|
92
82
|
}
|
|
93
83
|
|
|
94
|
-
/**
|
|
95
|
-
* List all model folders in the assets/models directory.
|
|
96
|
-
* Scans the platform-specific model directory and returns folder names.
|
|
97
|
-
*
|
|
98
|
-
* This is useful for discovering models at runtime without hardcoding paths.
|
|
99
|
-
* You can then use the returned folder names with resolveModelPath and initialize.
|
|
100
|
-
*
|
|
101
|
-
* @returns Promise resolving to array of model info objects
|
|
102
|
-
*
|
|
103
|
-
* @example
|
|
104
|
-
* ```typescript
|
|
105
|
-
* import { listAssetModels, resolveModelPath } from 'react-native-sherpa-onnx';
|
|
106
|
-
*
|
|
107
|
-
* // Get all model folders
|
|
108
|
-
* const models = await listAssetModels();
|
|
109
|
-
* console.log('Found models:', models);
|
|
110
|
-
* // Example output: [{ folder: 'sherpa-onnx-streaming-zipformer-en-2023-06-26', hint: 'stt' }, { folder: 'sherpa-onnx-matcha-icefall-en_US-ljspeech', hint: 'tts' }]
|
|
111
|
-
*
|
|
112
|
-
* // Initialize each model to detect types
|
|
113
|
-
* for (const model of models) {
|
|
114
|
-
* const path = await resolveModelPath({ type: 'asset', path: `models/${model.folder}` });
|
|
115
|
-
* const result = await
|
|
116
|
-
* if (result.success) {
|
|
117
|
-
* console.log(`Found models in ${model.folder}:`, result.detectedModels);
|
|
118
|
-
* }
|
|
119
|
-
* }
|
|
120
|
-
* ```
|
|
84
|
+
/**
|
|
85
|
+
* List all model folders in the assets/models directory.
|
|
86
|
+
* Scans the platform-specific model directory and returns folder names.
|
|
87
|
+
*
|
|
88
|
+
* This is useful for discovering models at runtime without hardcoding paths.
|
|
89
|
+
* You can then use the returned folder names with resolveModelPath and initialize.
|
|
90
|
+
*
|
|
91
|
+
* @returns Promise resolving to array of model info objects
|
|
92
|
+
*
|
|
93
|
+
* @example
|
|
94
|
+
* ```typescript
|
|
95
|
+
* import { listAssetModels, resolveModelPath } from 'react-native-sherpa-onnx';
|
|
96
|
+
*
|
|
97
|
+
* // Get all model folders
|
|
98
|
+
* const models = await listAssetModels();
|
|
99
|
+
* console.log('Found models:', models);
|
|
100
|
+
* // Example output: [{ folder: 'sherpa-onnx-streaming-zipformer-en-2023-06-26', hint: 'stt' }, { folder: 'sherpa-onnx-matcha-icefall-en_US-ljspeech', hint: 'tts' }]
|
|
101
|
+
*
|
|
102
|
+
* // Initialize each model to detect types
|
|
103
|
+
* for (const model of models) {
|
|
104
|
+
* const path = await resolveModelPath({ type: 'asset', path: `models/${model.folder}` });
|
|
105
|
+
* const result = await initializeStt(path);
|
|
106
|
+
* if (result.success) {
|
|
107
|
+
* console.log(`Found models in ${model.folder}:`, result.detectedModels);
|
|
108
|
+
* }
|
|
109
|
+
* }
|
|
110
|
+
* ```
|
|
121
111
|
*/
|
|
122
112
|
export async function listAssetModels() {
|
|
123
113
|
return SherpaOnnx.listAssetModels();
|
|
124
114
|
}
|
|
115
|
+
|
|
116
|
+
/**
|
|
117
|
+
* List model folders under a specific filesystem path.
|
|
118
|
+
* When recursive is true, returns relative folder paths under the base path.
|
|
119
|
+
*/
|
|
120
|
+
export async function listModelsAtPath(path, recursive = false) {
|
|
121
|
+
return SherpaOnnx.listModelsAtPath(path, recursive);
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
/**
|
|
125
|
+
* **Play Asset Delivery (PAD):** Returns the path to the models directory inside an
|
|
126
|
+
* Android asset pack, or null if the pack is not available.
|
|
127
|
+
* Use this to list and load models delivered via PAD (e.g. pack "sherpa_models").
|
|
128
|
+
* On iOS returns null.
|
|
129
|
+
*/
|
|
130
|
+
export async function getAssetPackPath(packName) {
|
|
131
|
+
return SherpaOnnx.getAssetPackPath(packName);
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
/**
|
|
135
|
+
* Alias for {@link getAssetPackPath}. Use for PAD (Play Asset Delivery) model discovery.
|
|
136
|
+
*/
|
|
137
|
+
export const getPlayAssetDeliveryModelsPath = getAssetPackPath;
|
|
125
138
|
//# sourceMappingURL=utils.js.map
|
package/lib/module/utils.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["Platform","SherpaOnnx","
|
|
1
|
+
{"version":3,"names":["Platform","SherpaOnnx","getDefaultModelPath","OS","assetModelPath","assetPath","type","path","fileModelPath","filePath","autoModelPath","resolveModelPath","config","listAssetModels","listModelsAtPath","recursive","getAssetPackPath","packName","getPlayAssetDeliveryModelsPath"],"sourceRoot":"../../src","sources":["utils.ts"],"mappings":";;AAAA,SAASA,QAAQ,QAAQ,cAAc;AAEvC,OAAOC,UAAU,MAAM,uBAAoB;;AAE3C;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASC,mBAAmBA,CAAA,EAAW;EAC5C,IAAIF,QAAQ,CAACG,EAAE,KAAK,KAAK,EAAE;IACzB;IACA,OAAO,kBAAkB;EAC3B,CAAC,MAAM;IACL;IACA,OAAO,QAAQ;EACjB;AACF;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASC,cAAcA,CAACC,SAAiB,EAAmB;EACjE,OAAO;IACLC,IAAI,EAAE,OAAO;IACbC,IAAI,EAAEF;EACR,CAAC;AACH;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASG,aAAaA,CAACC,QAAgB,EAAmB;EAC/D,OAAO;IACLH,IAAI,EAAE,MAAM;IACZC,IAAI,EAAEE;EACR,CAAC;AACH;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASC,aAAaA,CAACH,IAAY,EAAmB;EAC3D,OAAO;IACLD,IAAI,EAAE,MAAM;IACZC,IAAI,EAAEA;EACR,CAAC;AACH;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,eAAeI,gBAAgBA,CACpCC,MAAuB,EACN;EACjB,OAAOX,UAAU,CAACU,gBAAgB,CAACC,MAAM,CAAC;AAC5C;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,eAAeC,eAAeA,CAAA,EAEnC;EACA,OAAOZ,UAAU,CAACY,eAAe,CAAC,CAAC;AACrC;;AAEA;AACA;AACA;AACA;AACA,OAAO,eAAeC,gBAAgBA,CACpCP,IAAY,EACZQ,SAAS,GAAG,KAAK,EACoD;EACrE,OAAOd,UAAU,CAACa,gBAAgB,CAACP,IAAI,EAAEQ,SAAS,CAAC;AACrD;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,eAAeC,gBAAgBA,CACpCC,QAAgB,EACQ;EACxB,OAAOhB,UAAU,CAACe,gBAAgB,CAACC,QAAQ,CAAC;AAC9C;;AAEA;AACA;AACA;AACA,OAAO,MAAMC,8BAA8B,GAAGF,gBAAgB","ignoreList":[]}
|
package/lib/module/vad/index.js
CHANGED
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
* // Future usage:
|
|
13
13
|
* import { initializeVAD, detectVoiceActivity } from 'react-native-sherpa-onnx/vad';
|
|
14
14
|
*
|
|
15
|
-
* await initializeVAD({ modelPath: 'models/vad-model' });
|
|
15
|
+
* await initializeVAD({ modelPath: { type: 'auto', path: 'models/vad-model' } });
|
|
16
16
|
* const segments = await detectVoiceActivity('path/to/audio.wav');
|
|
17
17
|
* ```
|
|
18
18
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["initializeVAD","_options","Error","detectVoiceActivity","_filePath","unloadVAD"],"sourceRoot":"
|
|
1
|
+
{"version":3,"names":["initializeVAD","_options","Error","detectVoiceActivity","_filePath","unloadVAD"],"sourceRoot":"../../../src","sources":["vad/index.ts"],"mappings":";;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAIA;AACA;AACA;;AAMA;AACA;AACA;;AAOA;AACA;AACA;AACA;AACA;AACA,OAAO,eAAeA,aAAaA,CACjCC,QAA8B,EACf;EACf,MAAM,IAAIC,KAAK,CACb,mEACF,CAAC;AACH;;AAEA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASC,mBAAmBA,CACjCC,SAAiB,EACQ;EACzB,MAAM,IAAIF,KAAK,CACb,mEACF,CAAC;AACH;;AAEA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASG,SAASA,CAAA,EAAkB;EACzC,MAAM,IAAIH,KAAK,CACb,mEACF,CAAC;AACH","ignoreList":[]}
|