react-native-sherpa-onnx 0.3.2 → 0.3.3
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 +28 -15
- package/SherpaOnnx.podspec +13 -5
- package/android/prebuilt-download.gradle +18 -5
- package/android/prebuilt-versions.gradle +8 -4
- package/android/src/main/cpp/jni/model_detect/sherpa-onnx-model-detect-helper.cpp +43 -142
- package/android/src/main/cpp/jni/model_detect/sherpa-onnx-model-detect-helper.h +12 -4
- package/android/src/main/cpp/jni/model_detect/sherpa-onnx-model-detect-stt.cpp +694 -307
- package/android/src/main/cpp/jni/model_detect/sherpa-onnx-model-detect-tts.cpp +194 -99
- package/android/src/main/cpp/jni/model_detect/sherpa-onnx-model-detect.h +90 -0
- package/android/src/main/cpp/jni/model_detect/sherpa-onnx-stt-wrapper.cpp +3 -0
- package/android/src/main/java/com/sherpaonnx/SherpaOnnxModule.kt +70 -0
- package/android/src/main/java/com/sherpaonnx/SherpaOnnxPcmCapture.kt +150 -0
- package/android/src/main/java/com/sherpaonnx/SherpaOnnxSttHelper.kt +39 -19
- package/ios/SherpaOnnx+PcmLiveStream.mm +288 -0
- package/ios/SherpaOnnx+STT.mm +2 -0
- package/ios/SherpaOnnx.mm +1 -1
- package/ios/model_detect/sherpa-onnx-model-detect-helper.h +9 -3
- package/ios/model_detect/sherpa-onnx-model-detect-helper.mm +38 -54
- package/ios/model_detect/sherpa-onnx-model-detect-stt.mm +620 -267
- package/ios/model_detect/sherpa-onnx-model-detect-tts.mm +131 -28
- package/ios/model_detect/sherpa-onnx-model-detect.h +70 -0
- package/ios/stt/sherpa-onnx-stt-wrapper.mm +4 -0
- package/lib/module/NativeSherpaOnnx.js.map +1 -1
- package/lib/module/audio/index.js +52 -0
- package/lib/module/audio/index.js.map +1 -1
- package/lib/module/stt/streaming.js +6 -3
- package/lib/module/stt/streaming.js.map +1 -1
- package/lib/typescript/src/NativeSherpaOnnx.d.ts +16 -2
- package/lib/typescript/src/NativeSherpaOnnx.d.ts.map +1 -1
- package/lib/typescript/src/audio/index.d.ts +17 -0
- package/lib/typescript/src/audio/index.d.ts.map +1 -1
- package/lib/typescript/src/stt/streaming.d.ts.map +1 -1
- package/lib/typescript/src/stt/streamingTypes.d.ts +1 -1
- package/lib/typescript/src/stt/streamingTypes.d.ts.map +1 -1
- package/package.json +6 -1
- package/scripts/check-model-csvs.sh +72 -0
- package/scripts/setup-ios-framework.sh +48 -48
- package/src/NativeSherpaOnnx.ts +18 -2
- package/src/audio/index.ts +81 -0
- package/src/stt/streaming.ts +10 -5
- package/src/stt/streamingTypes.ts +1 -1
- package/third_party/sherpa-onnx-prebuilt/ANDROID_RELEASE_TAG +1 -1
- package/third_party/sherpa-onnx-prebuilt/IOS_RELEASE_TAG +1 -1
|
@@ -30,12 +30,16 @@ bool ContainsToken(const std::string& value, const std::string& token) {
|
|
|
30
30
|
return value.find(token) != std::string::npos;
|
|
31
31
|
}
|
|
32
32
|
|
|
33
|
+
static bool IsOnnxOrOrtFile(const FileEntry& entry) {
|
|
34
|
+
return EndsWith(entry.nameLower, ".onnx") || EndsWith(entry.nameLower, ".ort");
|
|
35
|
+
}
|
|
36
|
+
|
|
33
37
|
std::string ChooseLargest(const std::vector<FileEntry>& files,
|
|
34
38
|
const std::vector<std::string>& excludeTokens, bool onlyInt8, bool onlyNonInt8) {
|
|
35
39
|
std::string chosen;
|
|
36
40
|
std::uint64_t bestSize = 0;
|
|
37
41
|
for (const auto& entry : files) {
|
|
38
|
-
if (!
|
|
42
|
+
if (!IsOnnxOrOrtFile(entry)) continue;
|
|
39
43
|
bool hasExcluded = false;
|
|
40
44
|
for (const auto& token : excludeTokens) {
|
|
41
45
|
if (ContainsToken(entry.nameLower, token)) { hasExcluded = true; break; }
|
|
@@ -115,7 +119,7 @@ std::string FindOnnxByToken(const std::vector<FileEntry>& files,
|
|
|
115
119
|
std::string tokenLower = ToLower(token);
|
|
116
120
|
std::vector<FileEntry> matches;
|
|
117
121
|
for (const auto& entry : files) {
|
|
118
|
-
if (!
|
|
122
|
+
if (!IsOnnxOrOrtFile(entry)) continue;
|
|
119
123
|
if (ContainsToken(entry.nameLower, tokenLower)) matches.push_back(entry);
|
|
120
124
|
}
|
|
121
125
|
if (matches.empty()) return "";
|
|
@@ -136,6 +140,37 @@ std::string FindOnnxByAnyToken(const std::vector<FileEntry>& files,
|
|
|
136
140
|
return "";
|
|
137
141
|
}
|
|
138
142
|
|
|
143
|
+
std::string FindOnnxByAnyTokenExcluding(const std::vector<FileEntry>& files,
|
|
144
|
+
const std::vector<std::string>& tokens, const std::vector<std::string>& excludeInName,
|
|
145
|
+
const std::optional<bool>& preferInt8) {
|
|
146
|
+
for (const auto& token : tokens) {
|
|
147
|
+
std::string tokenLower = ToLower(token);
|
|
148
|
+
std::vector<FileEntry> matches;
|
|
149
|
+
for (const auto& entry : files) {
|
|
150
|
+
if (!IsOnnxOrOrtFile(entry)) continue;
|
|
151
|
+
if (!ContainsToken(entry.nameLower, tokenLower)) continue;
|
|
152
|
+
bool excluded = false;
|
|
153
|
+
for (const auto& ex : excludeInName) {
|
|
154
|
+
std::string exLower = ToLower(ex);
|
|
155
|
+
if (ContainsToken(entry.nameLower, exLower)) {
|
|
156
|
+
excluded = true;
|
|
157
|
+
break;
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
if (!excluded) matches.push_back(entry);
|
|
161
|
+
}
|
|
162
|
+
if (matches.empty()) continue;
|
|
163
|
+
std::vector<std::string> emptyTokens;
|
|
164
|
+
bool wantInt8 = preferInt8.has_value() && preferInt8.value();
|
|
165
|
+
bool wantNonInt8 = preferInt8.has_value() && !preferInt8.value();
|
|
166
|
+
std::string chosen = ChooseLargest(matches, emptyTokens, wantInt8, wantNonInt8);
|
|
167
|
+
if (!chosen.empty()) return chosen;
|
|
168
|
+
chosen = ChooseLargest(matches, emptyTokens, false, false);
|
|
169
|
+
if (!chosen.empty()) return chosen;
|
|
170
|
+
}
|
|
171
|
+
return "";
|
|
172
|
+
}
|
|
173
|
+
|
|
139
174
|
std::string FindFileEndingWith(const std::vector<FileEntry>& files, const std::string& suffix) {
|
|
140
175
|
std::string targetSuffix = ToLower(suffix);
|
|
141
176
|
for (const auto& entry : files) {
|
|
@@ -147,9 +182,8 @@ std::string FindFileEndingWith(const std::vector<FileEntry>& files, const std::s
|
|
|
147
182
|
return "";
|
|
148
183
|
}
|
|
149
184
|
|
|
150
|
-
std::string FindFileByName(const std::
|
|
185
|
+
std::string FindFileByName(const std::vector<FileEntry>& files, const std::string& fileName) {
|
|
151
186
|
std::string target = ToLower(fileName);
|
|
152
|
-
auto files = ListFilesRecursive(baseDir, maxDepth);
|
|
153
187
|
for (const auto& entry : files) {
|
|
154
188
|
if (entry.nameLower == target) return entry.path;
|
|
155
189
|
}
|
|
@@ -172,55 +206,5 @@ bool ContainsWord(const std::string& haystack, const std::string& word) {
|
|
|
172
206
|
return false;
|
|
173
207
|
}
|
|
174
208
|
|
|
175
|
-
std::string FindDirectoryByName(const std::string& baseDir, const std::string& dirName, int maxDepth) {
|
|
176
|
-
std::string target = ToLower(dirName);
|
|
177
|
-
std::vector<std::string> toVisit = ListDirectories(baseDir);
|
|
178
|
-
int depth = 0;
|
|
179
|
-
while (!toVisit.empty() && depth <= maxDepth) {
|
|
180
|
-
std::vector<std::string> next;
|
|
181
|
-
for (const auto& dir : toVisit) {
|
|
182
|
-
std::string name = fs::path(dir).filename().string();
|
|
183
|
-
if (ToLower(name) == target) return dir;
|
|
184
|
-
if (depth < maxDepth) {
|
|
185
|
-
auto nested = ListDirectories(dir);
|
|
186
|
-
next.insert(next.end(), nested.begin(), nested.end());
|
|
187
|
-
}
|
|
188
|
-
}
|
|
189
|
-
toVisit.swap(next);
|
|
190
|
-
depth += 1;
|
|
191
|
-
}
|
|
192
|
-
return "";
|
|
193
|
-
}
|
|
194
|
-
|
|
195
|
-
std::string ResolveTokenizerDir(const std::string& modelDir) {
|
|
196
|
-
std::string vocabInMain = modelDir + "/vocab.json";
|
|
197
|
-
if (FileExists(vocabInMain)) {
|
|
198
|
-
return modelDir;
|
|
199
|
-
}
|
|
200
|
-
|
|
201
|
-
try {
|
|
202
|
-
for (const auto& entry : fs::directory_iterator(modelDir)) {
|
|
203
|
-
if (entry.is_directory()) {
|
|
204
|
-
std::string dirName = entry.path().filename().string();
|
|
205
|
-
std::string dirNameLower = ToLower(dirName);
|
|
206
|
-
if (dirNameLower.find("qwen3") != std::string::npos) {
|
|
207
|
-
std::string vocabPath = entry.path().string() + "/vocab.json";
|
|
208
|
-
if (FileExists(vocabPath)) {
|
|
209
|
-
return entry.path().string();
|
|
210
|
-
}
|
|
211
|
-
}
|
|
212
|
-
}
|
|
213
|
-
}
|
|
214
|
-
} catch (const std::exception&) {
|
|
215
|
-
}
|
|
216
|
-
|
|
217
|
-
std::string commonPath = modelDir + "/Qwen3-0.6B";
|
|
218
|
-
if (FileExists(commonPath + "/vocab.json")) {
|
|
219
|
-
return commonPath;
|
|
220
|
-
}
|
|
221
|
-
|
|
222
|
-
return "";
|
|
223
|
-
}
|
|
224
|
-
|
|
225
209
|
} // namespace model_detect
|
|
226
210
|
} // namespace sherpaonnx
|