cactus-react-native 1.7.0 → 1.10.1
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 +61 -0
- package/android/gradle.properties +1 -1
- package/android/src/main/jniLibs/arm64-v8a/libcactus.a +0 -0
- package/cpp/HybridCactus.cpp +49 -1
- package/cpp/HybridCactus.hpp +5 -0
- package/cpp/cactus_ffi.h +14 -1
- package/ios/cactus.xcframework/ios-arm64/cactus.framework/Headers/cactus_cloud.h +48 -0
- package/ios/cactus.xcframework/ios-arm64/cactus.framework/Headers/cactus_ffi.h +14 -1
- package/ios/cactus.xcframework/ios-arm64/cactus.framework/Headers/cactus_utils.h +304 -66
- package/ios/cactus.xcframework/ios-arm64/cactus.framework/Headers/engine.h +32 -4
- package/ios/cactus.xcframework/ios-arm64/cactus.framework/Headers/graph.h +75 -11
- package/ios/cactus.xcframework/ios-arm64/cactus.framework/Headers/kernel.h +123 -4
- package/ios/cactus.xcframework/ios-arm64/cactus.framework/Headers/kernel_utils.h +37 -3
- package/ios/cactus.xcframework/ios-arm64/cactus.framework/Info.plist +0 -0
- package/ios/cactus.xcframework/ios-arm64/cactus.framework/cactus +0 -0
- package/ios/cactus.xcframework/ios-arm64-simulator/cactus.framework/Headers/cactus_cloud.h +48 -0
- package/ios/cactus.xcframework/ios-arm64-simulator/cactus.framework/Headers/cactus_ffi.h +14 -1
- package/ios/cactus.xcframework/ios-arm64-simulator/cactus.framework/Headers/cactus_utils.h +304 -66
- package/ios/cactus.xcframework/ios-arm64-simulator/cactus.framework/Headers/engine.h +32 -4
- package/ios/cactus.xcframework/ios-arm64-simulator/cactus.framework/Headers/graph.h +75 -11
- package/ios/cactus.xcframework/ios-arm64-simulator/cactus.framework/Headers/kernel.h +123 -4
- package/ios/cactus.xcframework/ios-arm64-simulator/cactus.framework/Headers/kernel_utils.h +37 -3
- package/ios/cactus.xcframework/ios-arm64-simulator/cactus.framework/Info.plist +0 -0
- package/ios/cactus.xcframework/ios-arm64-simulator/cactus.framework/_CodeSignature/CodeResources +1 -1
- package/ios/cactus.xcframework/ios-arm64-simulator/cactus.framework/cactus +0 -0
- package/lib/module/classes/CactusSTT.js +15 -0
- package/lib/module/classes/CactusSTT.js.map +1 -1
- package/lib/module/index.js +3 -0
- package/lib/module/index.js.map +1 -1
- package/lib/module/modelRegistry.js +27 -2
- package/lib/module/modelRegistry.js.map +1 -1
- package/lib/module/native/Cactus.js +18 -0
- package/lib/module/native/Cactus.js.map +1 -1
- package/lib/typescript/src/classes/CactusSTT.d.ts +2 -1
- package/lib/typescript/src/classes/CactusSTT.d.ts.map +1 -1
- package/lib/typescript/src/index.d.ts +2 -1
- package/lib/typescript/src/index.d.ts.map +1 -1
- package/lib/typescript/src/native/Cactus.d.ts +2 -1
- package/lib/typescript/src/native/Cactus.d.ts.map +1 -1
- package/lib/typescript/src/specs/Cactus.nitro.d.ts +1 -0
- package/lib/typescript/src/specs/Cactus.nitro.d.ts.map +1 -1
- package/lib/typescript/src/types/CactusSTT.d.ts +11 -0
- package/lib/typescript/src/types/CactusSTT.d.ts.map +1 -1
- package/nitrogen/generated/shared/c++/HybridCactusSpec.cpp +1 -0
- package/nitrogen/generated/shared/c++/HybridCactusSpec.hpp +1 -0
- package/package.json +1 -1
- package/src/classes/CactusSTT.ts +20 -0
- package/src/index.tsx +6 -0
- package/src/modelRegistry.ts +42 -2
- package/src/native/Cactus.ts +32 -0
- package/src/specs/Cactus.nitro.ts +5 -0
- package/src/types/CactusSTT.ts +14 -0
package/README.md
CHANGED
|
@@ -1018,6 +1018,10 @@ Releases all resources associated with the model. Automatically calls `stop()` f
|
|
|
1018
1018
|
|
|
1019
1019
|
Returns available models.
|
|
1020
1020
|
|
|
1021
|
+
**`getModelName(): string`**
|
|
1022
|
+
|
|
1023
|
+
Returns the model slug or path the instance was created with.
|
|
1024
|
+
|
|
1021
1025
|
### useCactusLM Hook
|
|
1022
1026
|
|
|
1023
1027
|
The `useCactusLM` hook manages a `CactusLM` instance with reactive state. When model parameters (`model`, `corpusDir`, `cacheIndex`, `options`) change, the hook creates a new instance and resets all state. The hook automatically cleans up resources when the component unmounts.
|
|
@@ -1111,6 +1115,15 @@ Feeds audio samples into the streaming session and returns the current transcrip
|
|
|
1111
1115
|
|
|
1112
1116
|
Stops the streaming session and returns the final confirmed transcription text. Throws an error if no session is active.
|
|
1113
1117
|
|
|
1118
|
+
**`detectLanguage(params: CactusSTTDetectLanguageParams): Promise<CactusSTTDetectLanguageResult>`**
|
|
1119
|
+
|
|
1120
|
+
Detects the spoken language in the given audio. Automatically calls `init()` if not already initialized. Throws an error if a generation is already in progress.
|
|
1121
|
+
|
|
1122
|
+
**Parameters:**
|
|
1123
|
+
- `audio` - Path to the audio file or raw PCM samples as a byte array.
|
|
1124
|
+
- `options`:
|
|
1125
|
+
- `useVad` - Whether to apply VAD before detection (default: `true`).
|
|
1126
|
+
|
|
1114
1127
|
**`audioEmbed(params: CactusSTTAudioEmbedParams): Promise<CactusSTTAudioEmbedResult>`**
|
|
1115
1128
|
|
|
1116
1129
|
Generates embeddings for the given audio file. Automatically calls `init()` if not already initialized. Throws an error if a generation is already in progress.
|
|
@@ -1134,6 +1147,10 @@ Releases all resources associated with the model. Stops any active streaming ses
|
|
|
1134
1147
|
|
|
1135
1148
|
Returns available speech-to-text models.
|
|
1136
1149
|
|
|
1150
|
+
**`getModelName(): string`**
|
|
1151
|
+
|
|
1152
|
+
Returns the model slug or path the instance was created with.
|
|
1153
|
+
|
|
1137
1154
|
### useCactusSTT Hook
|
|
1138
1155
|
|
|
1139
1156
|
The `useCactusSTT` hook manages a `CactusSTT` instance with reactive state. When model parameters (`model`, `options`) change, the hook creates a new instance and resets all state. The hook automatically cleans up resources when the component unmounts.
|
|
@@ -1216,6 +1233,10 @@ Releases all resources associated with the model. Safe to call even if the model
|
|
|
1216
1233
|
|
|
1217
1234
|
Returns available VAD models.
|
|
1218
1235
|
|
|
1236
|
+
**`getModelName(): string`**
|
|
1237
|
+
|
|
1238
|
+
Returns the model slug or path the instance was created with.
|
|
1239
|
+
|
|
1219
1240
|
### useCactusVAD Hook
|
|
1220
1241
|
|
|
1221
1242
|
The `useCactusVAD` hook manages a `CactusVAD` instance with reactive state. When model parameters (`model`, `options`) change, the hook creates a new instance and resets all state. The hook automatically cleans up resources when the component unmounts.
|
|
@@ -1314,6 +1335,20 @@ The `useCactusIndex` hook manages a `CactusIndex` instance with reactive state.
|
|
|
1314
1335
|
- `compact(): Promise<void>` - Optimizes the index. Sets `isProcessing` to `true` during operation.
|
|
1315
1336
|
- `destroy(): Promise<void>` - Releases all resources. Automatically called when the component unmounts.
|
|
1316
1337
|
|
|
1338
|
+
### getRegistry
|
|
1339
|
+
|
|
1340
|
+
**`getRegistry(): Promise<{ [key: string]: CactusModel }>`**
|
|
1341
|
+
|
|
1342
|
+
Returns all available models from HuggingFace, keyed by model slug. Result is cached across calls.
|
|
1343
|
+
|
|
1344
|
+
```typescript
|
|
1345
|
+
import { getRegistry } from 'cactus-react-native';
|
|
1346
|
+
|
|
1347
|
+
const registry = await getRegistry();
|
|
1348
|
+
const model = registry['qwen3-0.6b'];
|
|
1349
|
+
console.log(model.quantization.int4.url);
|
|
1350
|
+
```
|
|
1351
|
+
|
|
1317
1352
|
## Type Definitions
|
|
1318
1353
|
|
|
1319
1354
|
### CactusLMParams
|
|
@@ -1647,6 +1682,32 @@ interface CactusSTTStreamTranscribeStopResult {
|
|
|
1647
1682
|
}
|
|
1648
1683
|
```
|
|
1649
1684
|
|
|
1685
|
+
### CactusSTTDetectLanguageOptions
|
|
1686
|
+
|
|
1687
|
+
```typescript
|
|
1688
|
+
interface CactusSTTDetectLanguageOptions {
|
|
1689
|
+
useVad?: boolean;
|
|
1690
|
+
}
|
|
1691
|
+
```
|
|
1692
|
+
|
|
1693
|
+
### CactusSTTDetectLanguageParams
|
|
1694
|
+
|
|
1695
|
+
```typescript
|
|
1696
|
+
interface CactusSTTDetectLanguageParams {
|
|
1697
|
+
audio: string | number[];
|
|
1698
|
+
options?: CactusSTTDetectLanguageOptions;
|
|
1699
|
+
}
|
|
1700
|
+
```
|
|
1701
|
+
|
|
1702
|
+
### CactusSTTDetectLanguageResult
|
|
1703
|
+
|
|
1704
|
+
```typescript
|
|
1705
|
+
interface CactusSTTDetectLanguageResult {
|
|
1706
|
+
language: string;
|
|
1707
|
+
confidence?: number;
|
|
1708
|
+
}
|
|
1709
|
+
```
|
|
1710
|
+
|
|
1650
1711
|
### CactusVADParams
|
|
1651
1712
|
|
|
1652
1713
|
```typescript
|
|
Binary file
|
package/cpp/HybridCactus.cpp
CHANGED
|
@@ -212,6 +212,54 @@ std::shared_ptr<Promise<std::string>> HybridCactus::transcribe(
|
|
|
212
212
|
});
|
|
213
213
|
}
|
|
214
214
|
|
|
215
|
+
std::shared_ptr<Promise<std::string>> HybridCactus::detectLanguage(
|
|
216
|
+
const std::variant<std::vector<double>, std::string> &audio,
|
|
217
|
+
double responseBufferSize,
|
|
218
|
+
const std::optional<std::string> &optionsJson) {
|
|
219
|
+
return Promise<std::string>::async(
|
|
220
|
+
[this, audio, optionsJson, responseBufferSize]() -> std::string {
|
|
221
|
+
std::lock_guard<std::mutex> lock(this->_modelMutex);
|
|
222
|
+
|
|
223
|
+
if (!this->_model) {
|
|
224
|
+
throw std::runtime_error("Cactus model is not initialized");
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
std::string responseBuffer;
|
|
228
|
+
responseBuffer.resize(responseBufferSize);
|
|
229
|
+
|
|
230
|
+
int result;
|
|
231
|
+
if (std::holds_alternative<std::string>(audio)) {
|
|
232
|
+
result = cactus_detect_language(
|
|
233
|
+
this->_model, std::get<std::string>(audio).c_str(),
|
|
234
|
+
responseBuffer.data(), responseBufferSize,
|
|
235
|
+
optionsJson ? optionsJson->c_str() : nullptr, nullptr, 0);
|
|
236
|
+
} else {
|
|
237
|
+
const auto &audioDoubles = std::get<std::vector<double>>(audio);
|
|
238
|
+
|
|
239
|
+
std::vector<uint8_t> audioBytes;
|
|
240
|
+
audioBytes.reserve(audioDoubles.size());
|
|
241
|
+
|
|
242
|
+
for (double d : audioDoubles) {
|
|
243
|
+
d = std::clamp(d, 0.0, 255.0);
|
|
244
|
+
audioBytes.emplace_back(static_cast<uint8_t>(d));
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
result = cactus_detect_language(
|
|
248
|
+
this->_model, nullptr, responseBuffer.data(), responseBufferSize,
|
|
249
|
+
optionsJson ? optionsJson->c_str() : nullptr, audioBytes.data(),
|
|
250
|
+
audioBytes.size());
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
if (result < 0) {
|
|
254
|
+
throw std::runtime_error("Cactus detect language failed: " +
|
|
255
|
+
std::string(cactus_get_last_error()));
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
responseBuffer.resize(strlen(responseBuffer.c_str()));
|
|
259
|
+
return responseBuffer;
|
|
260
|
+
});
|
|
261
|
+
}
|
|
262
|
+
|
|
215
263
|
std::shared_ptr<Promise<void>> HybridCactus::streamTranscribeStart(
|
|
216
264
|
const std::optional<std::string> &optionsJson) {
|
|
217
265
|
return Promise<void>::async([this, optionsJson]() -> void {
|
|
@@ -477,7 +525,7 @@ std::shared_ptr<Promise<void>> HybridCactus::destroy() {
|
|
|
477
525
|
std::shared_ptr<Promise<void>>
|
|
478
526
|
HybridCactus::setTelemetryEnvironment(const std::string &cacheDir) {
|
|
479
527
|
return Promise<void>::async([cacheDir]() -> void {
|
|
480
|
-
cactus_set_telemetry_environment("react-native
|
|
528
|
+
cactus_set_telemetry_environment("react-native", cacheDir.c_str(), "1.10.0");
|
|
481
529
|
});
|
|
482
530
|
}
|
|
483
531
|
|
package/cpp/HybridCactus.hpp
CHANGED
|
@@ -39,6 +39,11 @@ public:
|
|
|
39
39
|
double /* tokenId */)>> &callback)
|
|
40
40
|
override;
|
|
41
41
|
|
|
42
|
+
std::shared_ptr<Promise<std::string>>
|
|
43
|
+
detectLanguage(const std::variant<std::vector<double>, std::string> &audio,
|
|
44
|
+
double responseBufferSize,
|
|
45
|
+
const std::optional<std::string> &optionsJson) override;
|
|
46
|
+
|
|
42
47
|
std::shared_ptr<Promise<void>>
|
|
43
48
|
streamTranscribeStart(const std::optional<std::string> &optionsJson) override;
|
|
44
49
|
|
package/cpp/cactus_ffi.h
CHANGED
|
@@ -76,6 +76,16 @@ CACTUS_FFI_EXPORT int cactus_transcribe(
|
|
|
76
76
|
size_t pcm_buffer_size
|
|
77
77
|
);
|
|
78
78
|
|
|
79
|
+
CACTUS_FFI_EXPORT int cactus_detect_language(
|
|
80
|
+
cactus_model_t model,
|
|
81
|
+
const char* audio_file_path, // NULL if using pcm_buffer
|
|
82
|
+
char* response_buffer,
|
|
83
|
+
size_t buffer_size,
|
|
84
|
+
const char* options_json, // optional
|
|
85
|
+
const uint8_t* pcm_buffer, // NULL if using audio_file_path
|
|
86
|
+
size_t pcm_buffer_size
|
|
87
|
+
);
|
|
88
|
+
|
|
79
89
|
CACTUS_FFI_EXPORT cactus_stream_transcribe_t cactus_stream_transcribe_start(
|
|
80
90
|
cactus_model_t model,
|
|
81
91
|
const char* options_json // optional
|
|
@@ -189,7 +199,10 @@ CACTUS_FFI_EXPORT void cactus_index_destroy(cactus_index_t index);
|
|
|
189
199
|
|
|
190
200
|
CACTUS_FFI_EXPORT const char* cactus_get_last_error(void);
|
|
191
201
|
|
|
192
|
-
CACTUS_FFI_EXPORT void cactus_set_telemetry_environment(const char* framework, const char* cache_location);
|
|
202
|
+
CACTUS_FFI_EXPORT void cactus_set_telemetry_environment(const char* framework, const char* cache_location, const char* version);
|
|
203
|
+
CACTUS_FFI_EXPORT void cactus_set_app_id(const char* app_id);
|
|
204
|
+
CACTUS_FFI_EXPORT void cactus_telemetry_flush(void);
|
|
205
|
+
CACTUS_FFI_EXPORT void cactus_telemetry_shutdown(void);
|
|
193
206
|
|
|
194
207
|
#ifdef __cplusplus
|
|
195
208
|
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
#ifndef CACTUS_CLOUD_H
|
|
2
|
+
#define CACTUS_CLOUD_H
|
|
3
|
+
|
|
4
|
+
#include "cactus_utils.h"
|
|
5
|
+
#include <string>
|
|
6
|
+
#include <vector>
|
|
7
|
+
|
|
8
|
+
namespace cactus {
|
|
9
|
+
namespace ffi {
|
|
10
|
+
|
|
11
|
+
struct CloudResponse {
|
|
12
|
+
std::string transcript;
|
|
13
|
+
std::string api_key_hash;
|
|
14
|
+
bool used_cloud = false;
|
|
15
|
+
std::string error;
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
struct CloudCompletionRequest {
|
|
19
|
+
std::vector<cactus::engine::ChatMessage> messages;
|
|
20
|
+
std::vector<ToolFunction> tools;
|
|
21
|
+
std::string local_output;
|
|
22
|
+
std::vector<std::string> local_function_calls;
|
|
23
|
+
bool has_images = false;
|
|
24
|
+
std::string cloud_key;
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
struct CloudCompletionResult {
|
|
28
|
+
bool ok = false;
|
|
29
|
+
bool used_cloud = false;
|
|
30
|
+
std::string response;
|
|
31
|
+
std::vector<std::string> function_calls;
|
|
32
|
+
std::string error;
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
std::string cloud_base64_encode(const uint8_t* data, size_t len);
|
|
36
|
+
std::vector<uint8_t> cloud_build_wav(const uint8_t* pcm, size_t pcm_bytes);
|
|
37
|
+
std::string resolve_cloud_api_key(const char* cloud_key_param);
|
|
38
|
+
CloudResponse cloud_transcribe_request(const std::string& audio_b64,
|
|
39
|
+
const std::string& fallback_text,
|
|
40
|
+
long timeout_seconds = 15L,
|
|
41
|
+
const char* cloud_key = nullptr);
|
|
42
|
+
CloudCompletionResult cloud_complete_request(const CloudCompletionRequest& request,
|
|
43
|
+
long timeout_ms);
|
|
44
|
+
|
|
45
|
+
} // namespace ffi
|
|
46
|
+
} // namespace cactus
|
|
47
|
+
|
|
48
|
+
#endif // CACTUS_CLOUD_H
|
|
@@ -76,6 +76,16 @@ CACTUS_FFI_EXPORT int cactus_transcribe(
|
|
|
76
76
|
size_t pcm_buffer_size
|
|
77
77
|
);
|
|
78
78
|
|
|
79
|
+
CACTUS_FFI_EXPORT int cactus_detect_language(
|
|
80
|
+
cactus_model_t model,
|
|
81
|
+
const char* audio_file_path, // NULL if using pcm_buffer
|
|
82
|
+
char* response_buffer,
|
|
83
|
+
size_t buffer_size,
|
|
84
|
+
const char* options_json, // optional
|
|
85
|
+
const uint8_t* pcm_buffer, // NULL if using audio_file_path
|
|
86
|
+
size_t pcm_buffer_size
|
|
87
|
+
);
|
|
88
|
+
|
|
79
89
|
CACTUS_FFI_EXPORT cactus_stream_transcribe_t cactus_stream_transcribe_start(
|
|
80
90
|
cactus_model_t model,
|
|
81
91
|
const char* options_json // optional
|
|
@@ -189,7 +199,10 @@ CACTUS_FFI_EXPORT void cactus_index_destroy(cactus_index_t index);
|
|
|
189
199
|
|
|
190
200
|
CACTUS_FFI_EXPORT const char* cactus_get_last_error(void);
|
|
191
201
|
|
|
192
|
-
CACTUS_FFI_EXPORT void cactus_set_telemetry_environment(const char* framework, const char* cache_location);
|
|
202
|
+
CACTUS_FFI_EXPORT void cactus_set_telemetry_environment(const char* framework, const char* cache_location, const char* version);
|
|
203
|
+
CACTUS_FFI_EXPORT void cactus_set_app_id(const char* app_id);
|
|
204
|
+
CACTUS_FFI_EXPORT void cactus_telemetry_flush(void);
|
|
205
|
+
CACTUS_FFI_EXPORT void cactus_telemetry_shutdown(void);
|
|
193
206
|
|
|
194
207
|
#ifdef __cplusplus
|
|
195
208
|
}
|