react-native-sherpa-onnx 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +20 -0
- package/README.md +402 -0
- package/SherpaOnnx.podspec +84 -0
- package/android/build.gradle +193 -0
- package/android/src/main/AndroidManifest.xml +2 -0
- package/android/src/main/cpp/CMakeLists.txt +121 -0
- package/android/src/main/cpp/include/sherpa-onnx/c-api/c-api.h +1918 -0
- package/android/src/main/cpp/include/sherpa-onnx/c-api/cxx-api.h +841 -0
- package/android/src/main/cpp/jni/sherpa-onnx-jni.cpp +129 -0
- package/android/src/main/cpp/jni/sherpa-onnx-wrapper.cpp +649 -0
- package/android/src/main/cpp/jni/sherpa-onnx-wrapper.h +56 -0
- package/android/src/main/java/com/sherpaonnx/SherpaOnnxModule.kt +316 -0
- package/android/src/main/java/com/sherpaonnx/SherpaOnnxPackage.kt +33 -0
- package/ios/Frameworks/sherpa_onnx.xcframework.zip +0 -0
- package/ios/SherpaOnnx.h +5 -0
- package/ios/SherpaOnnx.mm +293 -0
- package/ios/SherpaOnnx.xcconfig +19 -0
- package/ios/include/sherpa-onnx/c-api/c-api.h +1918 -0
- package/ios/include/sherpa-onnx/c-api/cxx-api.h +841 -0
- package/ios/sherpa-onnx-wrapper.h +57 -0
- package/ios/sherpa-onnx-wrapper.mm +432 -0
- package/lib/module/NativeSherpaOnnx.js +5 -0
- package/lib/module/NativeSherpaOnnx.js.map +1 -0
- package/lib/module/diarization/index.js +54 -0
- package/lib/module/diarization/index.js.map +1 -0
- package/lib/module/enhancement/index.js +54 -0
- package/lib/module/enhancement/index.js.map +1 -0
- package/lib/module/index.js +25 -0
- package/lib/module/index.js.map +1 -0
- package/lib/module/package.json +1 -0
- package/lib/module/separation/index.js +54 -0
- package/lib/module/separation/index.js.map +1 -0
- package/lib/module/stt/index.js +79 -0
- package/lib/module/stt/index.js.map +1 -0
- package/lib/module/stt/types.js +4 -0
- package/lib/module/stt/types.js.map +1 -0
- package/lib/module/tts/index.js +54 -0
- package/lib/module/tts/index.js.map +1 -0
- package/lib/module/types.js +2 -0
- package/lib/module/types.js.map +1 -0
- package/lib/module/utils.js +93 -0
- package/lib/module/utils.js.map +1 -0
- package/lib/module/vad/index.js +54 -0
- package/lib/module/vad/index.js.map +1 -0
- package/lib/typescript/package.json +1 -0
- package/lib/typescript/src/NativeSherpaOnnx.d.ts +39 -0
- package/lib/typescript/src/NativeSherpaOnnx.d.ts.map +1 -0
- package/lib/typescript/src/diarization/index.d.ts +49 -0
- package/lib/typescript/src/diarization/index.d.ts.map +1 -0
- package/lib/typescript/src/enhancement/index.d.ts +47 -0
- package/lib/typescript/src/enhancement/index.d.ts.map +1 -0
- package/lib/typescript/src/index.d.ts +9 -0
- package/lib/typescript/src/index.d.ts.map +1 -0
- package/lib/typescript/src/separation/index.d.ts +48 -0
- package/lib/typescript/src/separation/index.d.ts.map +1 -0
- package/lib/typescript/src/stt/index.d.ts +53 -0
- package/lib/typescript/src/stt/index.d.ts.map +1 -0
- package/lib/typescript/src/stt/types.d.ts +39 -0
- package/lib/typescript/src/stt/types.d.ts.map +1 -0
- package/lib/typescript/src/tts/index.d.ts +47 -0
- package/lib/typescript/src/tts/index.d.ts.map +1 -0
- package/lib/typescript/src/types.d.ts +59 -0
- package/lib/typescript/src/types.d.ts.map +1 -0
- package/lib/typescript/src/utils.d.ts +53 -0
- package/lib/typescript/src/utils.d.ts.map +1 -0
- package/lib/typescript/src/vad/index.d.ts +48 -0
- package/lib/typescript/src/vad/index.d.ts.map +1 -0
- package/package.json +221 -0
- package/scripts/copy-headers.js +184 -0
- package/scripts/setup-assets.js +323 -0
- package/scripts/setup-ios-framework.sh +282 -0
- package/scripts/switch-registry.js +75 -0
- package/src/NativeSherpaOnnx.ts +44 -0
- package/src/diarization/index.ts +69 -0
- package/src/enhancement/index.ts +67 -0
- package/src/index.tsx +30 -0
- package/src/separation/index.ts +68 -0
- package/src/stt/index.ts +83 -0
- package/src/stt/types.ts +42 -0
- package/src/tts/index.ts +67 -0
- package/src/types.ts +73 -0
- package/src/utils.ts +97 -0
- package/src/vad/index.ts +70 -0
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
// Include standard library headers first to avoid conflicts with jni.h
|
|
2
|
+
#include <string>
|
|
3
|
+
#include <memory>
|
|
4
|
+
#include <optional>
|
|
5
|
+
|
|
6
|
+
// Then include JNI headers
|
|
7
|
+
#include <jni.h>
|
|
8
|
+
#include <android/log.h>
|
|
9
|
+
|
|
10
|
+
// Finally include our wrapper
|
|
11
|
+
#include "sherpa-onnx-wrapper.h"
|
|
12
|
+
|
|
13
|
+
#define LOG_TAG "SherpaOnnxJNI"
|
|
14
|
+
#define LOGI(...) __android_log_print(ANDROID_LOG_INFO, LOG_TAG, __VA_ARGS__)
|
|
15
|
+
#define LOGE(...) __android_log_print(ANDROID_LOG_ERROR, LOG_TAG, __VA_ARGS__)
|
|
16
|
+
|
|
17
|
+
using namespace sherpaonnx;
|
|
18
|
+
|
|
19
|
+
// Global wrapper instance
|
|
20
|
+
static std::unique_ptr<SherpaOnnxWrapper> g_wrapper = nullptr;
|
|
21
|
+
|
|
22
|
+
extern "C" {
|
|
23
|
+
|
|
24
|
+
JNIEXPORT jboolean JNICALL
|
|
25
|
+
Java_com_sherpaonnx_SherpaOnnxModule_nativeInitialize(
|
|
26
|
+
JNIEnv *env,
|
|
27
|
+
jobject /* this */,
|
|
28
|
+
jstring modelDir,
|
|
29
|
+
jboolean preferInt8,
|
|
30
|
+
jboolean hasPreferInt8,
|
|
31
|
+
jstring modelType) {
|
|
32
|
+
try {
|
|
33
|
+
if (g_wrapper == nullptr) {
|
|
34
|
+
g_wrapper = std::make_unique<SherpaOnnxWrapper>();
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
const char *modelDirStr = env->GetStringUTFChars(modelDir, nullptr);
|
|
38
|
+
if (modelDirStr == nullptr) {
|
|
39
|
+
LOGE("Failed to get modelDir string from JNI");
|
|
40
|
+
return JNI_FALSE;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
const char *modelTypeStr = env->GetStringUTFChars(modelType, nullptr);
|
|
44
|
+
if (modelTypeStr == nullptr) {
|
|
45
|
+
LOGE("Failed to get modelType string from JNI");
|
|
46
|
+
env->ReleaseStringUTFChars(modelDir, modelDirStr);
|
|
47
|
+
return JNI_FALSE;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
std::string modelDirPath(modelDirStr);
|
|
51
|
+
std::string modelTypePath(modelTypeStr);
|
|
52
|
+
|
|
53
|
+
// Convert Java boolean to C++ optional<bool>
|
|
54
|
+
std::optional<bool> preferInt8Opt;
|
|
55
|
+
if (hasPreferInt8 == JNI_TRUE) {
|
|
56
|
+
preferInt8Opt = (preferInt8 == JNI_TRUE);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
// Convert model type string to optional
|
|
60
|
+
std::optional<std::string> modelTypeOpt;
|
|
61
|
+
if (modelTypePath != "auto" && !modelTypePath.empty()) {
|
|
62
|
+
modelTypeOpt = modelTypePath;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
bool result = g_wrapper->initialize(modelDirPath, preferInt8Opt, modelTypeOpt);
|
|
66
|
+
env->ReleaseStringUTFChars(modelDir, modelDirStr);
|
|
67
|
+
env->ReleaseStringUTFChars(modelType, modelTypeStr);
|
|
68
|
+
|
|
69
|
+
if (!result) {
|
|
70
|
+
LOGE("Native initialization failed for: %s", modelDirPath.c_str());
|
|
71
|
+
}
|
|
72
|
+
return result ? JNI_TRUE : JNI_FALSE;
|
|
73
|
+
} catch (const std::exception &e) {
|
|
74
|
+
LOGE("Exception in nativeInitialize: %s", e.what());
|
|
75
|
+
return JNI_FALSE;
|
|
76
|
+
} catch (...) {
|
|
77
|
+
LOGE("Unknown exception in nativeInitialize");
|
|
78
|
+
return JNI_FALSE;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
JNIEXPORT jstring JNICALL
|
|
83
|
+
Java_com_sherpaonnx_SherpaOnnxModule_nativeTranscribeFile(
|
|
84
|
+
JNIEnv *env,
|
|
85
|
+
jobject /* this */,
|
|
86
|
+
jstring filePath) {
|
|
87
|
+
try {
|
|
88
|
+
if (g_wrapper == nullptr || !g_wrapper->isInitialized()) {
|
|
89
|
+
LOGE("Not initialized. Call initialize() first.");
|
|
90
|
+
return env->NewStringUTF("");
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
const char *filePathStr = env->GetStringUTFChars(filePath, nullptr);
|
|
94
|
+
if (filePathStr == nullptr) {
|
|
95
|
+
LOGE("Failed to get filePath string");
|
|
96
|
+
return env->NewStringUTF("");
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
std::string result = g_wrapper->transcribeFile(std::string(filePathStr));
|
|
100
|
+
env->ReleaseStringUTFChars(filePath, filePathStr);
|
|
101
|
+
|
|
102
|
+
return env->NewStringUTF(result.c_str());
|
|
103
|
+
} catch (const std::exception &e) {
|
|
104
|
+
LOGE("Exception in nativeTranscribeFile: %s", e.what());
|
|
105
|
+
return env->NewStringUTF("");
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
JNIEXPORT void JNICALL
|
|
110
|
+
Java_com_sherpaonnx_SherpaOnnxModule_nativeRelease(
|
|
111
|
+
JNIEnv * /* env */,
|
|
112
|
+
jobject /* this */) {
|
|
113
|
+
try {
|
|
114
|
+
if (g_wrapper != nullptr) {
|
|
115
|
+
g_wrapper->release();
|
|
116
|
+
}
|
|
117
|
+
} catch (const std::exception &e) {
|
|
118
|
+
LOGE("Exception in nativeRelease: %s", e.what());
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
JNIEXPORT jstring JNICALL
|
|
123
|
+
Java_com_sherpaonnx_SherpaOnnxModule_nativeTestSherpaInit(
|
|
124
|
+
JNIEnv *env,
|
|
125
|
+
jobject /* this */) {
|
|
126
|
+
return env->NewStringUTF("Sherpa ONNX loaded!");
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
} // extern "C"
|