react-native-nitro-mlx 0.2.2 → 0.4.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/MLXReactNative.podspec +7 -1
- package/ios/Sources/AudioCaptureManager.swift +110 -0
- package/ios/Sources/HybridLLM.swift +518 -42
- package/ios/Sources/HybridSTT.swift +202 -0
- package/ios/Sources/HybridTTS.swift +145 -0
- package/ios/Sources/JSONHelpers.swift +9 -0
- package/ios/Sources/ModelDownloader.swift +26 -12
- package/ios/Sources/StreamEventEmitter.swift +132 -0
- package/ios/Sources/ThinkingStateMachine.swift +206 -0
- package/lib/module/index.js +3 -0
- package/lib/module/index.js.map +1 -1
- package/lib/module/llm.js +72 -4
- package/lib/module/llm.js.map +1 -1
- package/lib/module/models.js +97 -26
- package/lib/module/models.js.map +1 -1
- package/lib/module/specs/STT.nitro.js +4 -0
- package/lib/module/specs/STT.nitro.js.map +1 -0
- package/lib/module/specs/TTS.nitro.js +4 -0
- package/lib/module/specs/TTS.nitro.js.map +1 -0
- package/lib/module/stt.js +49 -0
- package/lib/module/stt.js.map +1 -0
- package/lib/module/tool-utils.js +56 -0
- package/lib/module/tool-utils.js.map +1 -0
- package/lib/module/tts.js +40 -0
- package/lib/module/tts.js.map +1 -0
- package/lib/typescript/src/index.d.ts +8 -3
- package/lib/typescript/src/index.d.ts.map +1 -1
- package/lib/typescript/src/llm.d.ts +46 -4
- package/lib/typescript/src/llm.d.ts.map +1 -1
- package/lib/typescript/src/models.d.ts +13 -4
- package/lib/typescript/src/models.d.ts.map +1 -1
- package/lib/typescript/src/specs/LLM.nitro.d.ts +79 -7
- package/lib/typescript/src/specs/LLM.nitro.d.ts.map +1 -1
- package/lib/typescript/src/specs/STT.nitro.d.ts +28 -0
- package/lib/typescript/src/specs/STT.nitro.d.ts.map +1 -0
- package/lib/typescript/src/specs/TTS.nitro.d.ts +22 -0
- package/lib/typescript/src/specs/TTS.nitro.d.ts.map +1 -0
- package/lib/typescript/src/stt.d.ts +16 -0
- package/lib/typescript/src/stt.d.ts.map +1 -0
- package/lib/typescript/src/tool-utils.d.ts +13 -0
- package/lib/typescript/src/tool-utils.d.ts.map +1 -0
- package/lib/typescript/src/tts.d.ts +13 -0
- package/lib/typescript/src/tts.d.ts.map +1 -0
- package/nitrogen/generated/ios/MLXReactNative+autolinking.rb +1 -1
- package/nitrogen/generated/ios/MLXReactNative-Swift-Cxx-Bridge.cpp +76 -1
- package/nitrogen/generated/ios/MLXReactNative-Swift-Cxx-Bridge.hpp +338 -1
- package/nitrogen/generated/ios/MLXReactNative-Swift-Cxx-Umbrella.hpp +28 -1
- package/nitrogen/generated/ios/MLXReactNativeAutolinking.mm +17 -1
- package/nitrogen/generated/ios/MLXReactNativeAutolinking.swift +31 -1
- package/nitrogen/generated/ios/c++/HybridLLMSpecSwift.cpp +1 -1
- package/nitrogen/generated/ios/c++/HybridLLMSpecSwift.hpp +18 -3
- package/nitrogen/generated/ios/c++/HybridModelManagerSpecSwift.cpp +1 -1
- package/nitrogen/generated/ios/c++/HybridModelManagerSpecSwift.hpp +1 -1
- package/nitrogen/generated/ios/c++/HybridSTTSpecSwift.cpp +11 -0
- package/nitrogen/generated/ios/c++/HybridSTTSpecSwift.hpp +149 -0
- package/nitrogen/generated/ios/c++/HybridTTSSpecSwift.cpp +11 -0
- package/nitrogen/generated/ios/c++/HybridTTSSpecSwift.hpp +128 -0
- package/nitrogen/generated/ios/swift/Func_std__shared_ptr_Promise_std__shared_ptr_Promise_std__shared_ptr_AnyMap______std__shared_ptr_AnyMap_.swift +62 -0
- package/nitrogen/generated/ios/swift/Func_void.swift +1 -1
- package/nitrogen/generated/ios/swift/Func_void_bool.swift +1 -1
- package/nitrogen/generated/ios/swift/Func_void_double.swift +1 -1
- package/nitrogen/generated/ios/swift/Func_void_std__exception_ptr.swift +1 -1
- package/nitrogen/generated/ios/swift/Func_void_std__shared_ptr_AnyMap_.swift +47 -0
- package/nitrogen/generated/ios/swift/Func_void_std__shared_ptr_ArrayBuffer_.swift +47 -0
- package/nitrogen/generated/ios/swift/Func_void_std__shared_ptr_Promise_std__shared_ptr_AnyMap___.swift +67 -0
- package/nitrogen/generated/ios/swift/Func_void_std__string.swift +1 -1
- package/nitrogen/generated/ios/swift/Func_void_std__string_std__string.swift +47 -0
- package/nitrogen/generated/ios/swift/Func_void_std__vector_std__string_.swift +1 -1
- package/nitrogen/generated/ios/swift/GenerationStats.swift +14 -3
- package/nitrogen/generated/ios/swift/HybridLLMSpec.swift +3 -2
- package/nitrogen/generated/ios/swift/HybridLLMSpec_cxx.swift +38 -2
- package/nitrogen/generated/ios/swift/HybridModelManagerSpec.swift +1 -1
- package/nitrogen/generated/ios/swift/HybridModelManagerSpec_cxx.swift +1 -1
- package/nitrogen/generated/ios/swift/HybridSTTSpec.swift +66 -0
- package/nitrogen/generated/ios/swift/HybridSTTSpec_cxx.swift +286 -0
- package/nitrogen/generated/ios/swift/HybridTTSSpec.swift +63 -0
- package/nitrogen/generated/ios/swift/HybridTTSSpec_cxx.swift +229 -0
- package/nitrogen/generated/ios/swift/LLMLoadOptions.swift +44 -2
- package/nitrogen/generated/ios/swift/LLMMessage.swift +1 -1
- package/nitrogen/generated/ios/swift/STTLoadOptions.swift +66 -0
- package/nitrogen/generated/ios/swift/TTSGenerateOptions.swift +78 -0
- package/nitrogen/generated/ios/swift/TTSLoadOptions.swift +66 -0
- package/nitrogen/generated/ios/swift/ToolDefinition.swift +113 -0
- package/nitrogen/generated/ios/swift/ToolParameter.swift +69 -0
- package/nitrogen/generated/shared/c++/GenerationStats.hpp +7 -3
- package/nitrogen/generated/shared/c++/HybridLLMSpec.cpp +2 -1
- package/nitrogen/generated/shared/c++/HybridLLMSpec.hpp +3 -2
- package/nitrogen/generated/shared/c++/HybridModelManagerSpec.cpp +1 -1
- package/nitrogen/generated/shared/c++/HybridModelManagerSpec.hpp +1 -1
- package/nitrogen/generated/shared/c++/HybridSTTSpec.cpp +32 -0
- package/nitrogen/generated/shared/c++/HybridSTTSpec.hpp +78 -0
- package/nitrogen/generated/shared/c++/HybridTTSSpec.cpp +29 -0
- package/nitrogen/generated/shared/c++/HybridTTSSpec.hpp +78 -0
- package/nitrogen/generated/shared/c++/LLMLoadOptions.hpp +10 -3
- package/nitrogen/generated/shared/c++/LLMMessage.hpp +1 -1
- package/nitrogen/generated/shared/c++/STTLoadOptions.hpp +76 -0
- package/nitrogen/generated/shared/c++/TTSGenerateOptions.hpp +80 -0
- package/nitrogen/generated/shared/c++/TTSLoadOptions.hpp +76 -0
- package/nitrogen/generated/shared/c++/ToolDefinition.hpp +93 -0
- package/nitrogen/generated/shared/c++/ToolParameter.hpp +87 -0
- package/package.json +13 -8
- package/src/index.ts +40 -3
- package/src/llm.ts +90 -5
- package/src/models.ts +81 -1
- package/src/specs/LLM.nitro.ts +111 -7
- package/src/specs/STT.nitro.ts +35 -0
- package/src/specs/TTS.nitro.ts +30 -0
- package/src/stt.ts +67 -0
- package/src/tool-utils.ts +74 -0
- package/src/tts.ts +60 -0
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
/// MLXReactNativeAutolinking.swift
|
|
3
3
|
/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
|
|
4
4
|
/// https://github.com/mrousavy/nitro
|
|
5
|
-
/// Copyright ©
|
|
5
|
+
/// Copyright © 2026 Marc Rousavy @ Margelo
|
|
6
6
|
///
|
|
7
7
|
|
|
8
8
|
public final class MLXReactNativeAutolinking {
|
|
@@ -37,4 +37,34 @@ public final class MLXReactNativeAutolinking {
|
|
|
37
37
|
return __cxxWrapped.getCxxPart()
|
|
38
38
|
}()
|
|
39
39
|
}
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Creates an instance of a Swift class that implements `HybridTTSSpec`,
|
|
43
|
+
* and wraps it in a Swift class that can directly interop with C++ (`HybridTTSSpec_cxx`)
|
|
44
|
+
*
|
|
45
|
+
* This is generated by Nitrogen and will initialize the class specified
|
|
46
|
+
* in the `"autolinking"` property of `nitro.json` (in this case, `HybridTTS`).
|
|
47
|
+
*/
|
|
48
|
+
public static func createTTS() -> bridge.std__shared_ptr_HybridTTSSpec_ {
|
|
49
|
+
let hybridObject = HybridTTS()
|
|
50
|
+
return { () -> bridge.std__shared_ptr_HybridTTSSpec_ in
|
|
51
|
+
let __cxxWrapped = hybridObject.getCxxWrapper()
|
|
52
|
+
return __cxxWrapped.getCxxPart()
|
|
53
|
+
}()
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Creates an instance of a Swift class that implements `HybridSTTSpec`,
|
|
58
|
+
* and wraps it in a Swift class that can directly interop with C++ (`HybridSTTSpec_cxx`)
|
|
59
|
+
*
|
|
60
|
+
* This is generated by Nitrogen and will initialize the class specified
|
|
61
|
+
* in the `"autolinking"` property of `nitro.json` (in this case, `HybridSTT`).
|
|
62
|
+
*/
|
|
63
|
+
public static func createSTT() -> bridge.std__shared_ptr_HybridSTTSpec_ {
|
|
64
|
+
let hybridObject = HybridSTT()
|
|
65
|
+
return { () -> bridge.std__shared_ptr_HybridSTTSpec_ in
|
|
66
|
+
let __cxxWrapped = hybridObject.getCxxWrapper()
|
|
67
|
+
return __cxxWrapped.getCxxPart()
|
|
68
|
+
}()
|
|
69
|
+
}
|
|
40
70
|
}
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
/// HybridLLMSpecSwift.cpp
|
|
3
3
|
/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
|
|
4
4
|
/// https://github.com/mrousavy/nitro
|
|
5
|
-
/// Copyright ©
|
|
5
|
+
/// Copyright © 2026 Marc Rousavy @ Margelo
|
|
6
6
|
///
|
|
7
7
|
|
|
8
8
|
#include "HybridLLMSpecSwift.hpp"
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
/// HybridLLMSpecSwift.hpp
|
|
3
3
|
/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
|
|
4
4
|
/// https://github.com/mrousavy/nitro
|
|
5
|
-
/// Copyright ©
|
|
5
|
+
/// Copyright © 2026 Marc Rousavy @ Margelo
|
|
6
6
|
///
|
|
7
7
|
|
|
8
8
|
#pragma once
|
|
@@ -16,6 +16,10 @@ namespace MLXReactNative { class HybridLLMSpec_cxx; }
|
|
|
16
16
|
namespace margelo::nitro::mlxreactnative { struct LLMLoadOptions; }
|
|
17
17
|
// Forward declaration of `LLMMessage` to properly resolve imports.
|
|
18
18
|
namespace margelo::nitro::mlxreactnative { struct LLMMessage; }
|
|
19
|
+
// Forward declaration of `ToolDefinition` to properly resolve imports.
|
|
20
|
+
namespace margelo::nitro::mlxreactnative { struct ToolDefinition; }
|
|
21
|
+
// Forward declaration of `ToolParameter` to properly resolve imports.
|
|
22
|
+
namespace margelo::nitro::mlxreactnative { struct ToolParameter; }
|
|
19
23
|
// Forward declaration of `GenerationStats` to properly resolve imports.
|
|
20
24
|
namespace margelo::nitro::mlxreactnative { struct GenerationStats; }
|
|
21
25
|
|
|
@@ -26,6 +30,9 @@ namespace margelo::nitro::mlxreactnative { struct GenerationStats; }
|
|
|
26
30
|
#include <functional>
|
|
27
31
|
#include "LLMMessage.hpp"
|
|
28
32
|
#include <vector>
|
|
33
|
+
#include "ToolDefinition.hpp"
|
|
34
|
+
#include "ToolParameter.hpp"
|
|
35
|
+
#include <NitroModules/AnyMap.hpp>
|
|
29
36
|
#include "GenerationStats.hpp"
|
|
30
37
|
|
|
31
38
|
#include "MLXReactNative-Swift-Cxx-Umbrella.hpp"
|
|
@@ -110,8 +117,16 @@ namespace margelo::nitro::mlxreactnative {
|
|
|
110
117
|
auto __value = std::move(__result.value());
|
|
111
118
|
return __value;
|
|
112
119
|
}
|
|
113
|
-
inline std::shared_ptr<Promise<std::string>> stream(const std::string& prompt, const std::function<void(const std::string& /* token */)>& onToken) override {
|
|
114
|
-
auto __result = _swiftPart.stream(prompt, onToken);
|
|
120
|
+
inline std::shared_ptr<Promise<std::string>> stream(const std::string& prompt, const std::function<void(const std::string& /* token */)>& onToken, const std::optional<std::function<void(const std::string& /* toolName */, const std::string& /* args */)>>& onToolCall) override {
|
|
121
|
+
auto __result = _swiftPart.stream(prompt, onToken, onToolCall);
|
|
122
|
+
if (__result.hasError()) [[unlikely]] {
|
|
123
|
+
std::rethrow_exception(__result.error());
|
|
124
|
+
}
|
|
125
|
+
auto __value = std::move(__result.value());
|
|
126
|
+
return __value;
|
|
127
|
+
}
|
|
128
|
+
inline std::shared_ptr<Promise<std::string>> streamWithEvents(const std::string& prompt, const std::function<void(const std::string& /* eventJson */)>& onEvent) override {
|
|
129
|
+
auto __result = _swiftPart.streamWithEvents(prompt, onEvent);
|
|
115
130
|
if (__result.hasError()) [[unlikely]] {
|
|
116
131
|
std::rethrow_exception(__result.error());
|
|
117
132
|
}
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
/// HybridModelManagerSpecSwift.cpp
|
|
3
3
|
/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
|
|
4
4
|
/// https://github.com/mrousavy/nitro
|
|
5
|
-
/// Copyright ©
|
|
5
|
+
/// Copyright © 2026 Marc Rousavy @ Margelo
|
|
6
6
|
///
|
|
7
7
|
|
|
8
8
|
#include "HybridModelManagerSpecSwift.hpp"
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
///
|
|
2
|
+
/// HybridSTTSpecSwift.cpp
|
|
3
|
+
/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
|
|
4
|
+
/// https://github.com/mrousavy/nitro
|
|
5
|
+
/// Copyright © 2026 Marc Rousavy @ Margelo
|
|
6
|
+
///
|
|
7
|
+
|
|
8
|
+
#include "HybridSTTSpecSwift.hpp"
|
|
9
|
+
|
|
10
|
+
namespace margelo::nitro::mlxreactnative {
|
|
11
|
+
} // namespace margelo::nitro::mlxreactnative
|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
///
|
|
2
|
+
/// HybridSTTSpecSwift.hpp
|
|
3
|
+
/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
|
|
4
|
+
/// https://github.com/mrousavy/nitro
|
|
5
|
+
/// Copyright © 2026 Marc Rousavy @ Margelo
|
|
6
|
+
///
|
|
7
|
+
|
|
8
|
+
#pragma once
|
|
9
|
+
|
|
10
|
+
#include "HybridSTTSpec.hpp"
|
|
11
|
+
|
|
12
|
+
// Forward declaration of `HybridSTTSpec_cxx` to properly resolve imports.
|
|
13
|
+
namespace MLXReactNative { class HybridSTTSpec_cxx; }
|
|
14
|
+
|
|
15
|
+
// Forward declaration of `STTLoadOptions` to properly resolve imports.
|
|
16
|
+
namespace margelo::nitro::mlxreactnative { struct STTLoadOptions; }
|
|
17
|
+
// Forward declaration of `ArrayBufferHolder` to properly resolve imports.
|
|
18
|
+
namespace NitroModules { class ArrayBufferHolder; }
|
|
19
|
+
|
|
20
|
+
#include <string>
|
|
21
|
+
#include <NitroModules/Promise.hpp>
|
|
22
|
+
#include "STTLoadOptions.hpp"
|
|
23
|
+
#include <optional>
|
|
24
|
+
#include <functional>
|
|
25
|
+
#include <NitroModules/ArrayBuffer.hpp>
|
|
26
|
+
#include <NitroModules/ArrayBufferHolder.hpp>
|
|
27
|
+
|
|
28
|
+
#include "MLXReactNative-Swift-Cxx-Umbrella.hpp"
|
|
29
|
+
|
|
30
|
+
namespace margelo::nitro::mlxreactnative {
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* The C++ part of HybridSTTSpec_cxx.swift.
|
|
34
|
+
*
|
|
35
|
+
* HybridSTTSpecSwift (C++) accesses HybridSTTSpec_cxx (Swift), and might
|
|
36
|
+
* contain some additional bridging code for C++ <> Swift interop.
|
|
37
|
+
*
|
|
38
|
+
* Since this obviously introduces an overhead, I hope at some point in
|
|
39
|
+
* the future, HybridSTTSpec_cxx can directly inherit from the C++ class HybridSTTSpec
|
|
40
|
+
* to simplify the whole structure and memory management.
|
|
41
|
+
*/
|
|
42
|
+
class HybridSTTSpecSwift: public virtual HybridSTTSpec {
|
|
43
|
+
public:
|
|
44
|
+
// Constructor from a Swift instance
|
|
45
|
+
explicit HybridSTTSpecSwift(const MLXReactNative::HybridSTTSpec_cxx& swiftPart):
|
|
46
|
+
HybridObject(HybridSTTSpec::TAG),
|
|
47
|
+
_swiftPart(swiftPart) { }
|
|
48
|
+
|
|
49
|
+
public:
|
|
50
|
+
// Get the Swift part
|
|
51
|
+
inline MLXReactNative::HybridSTTSpec_cxx& getSwiftPart() noexcept {
|
|
52
|
+
return _swiftPart;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
public:
|
|
56
|
+
inline size_t getExternalMemorySize() noexcept override {
|
|
57
|
+
return _swiftPart.getMemorySize();
|
|
58
|
+
}
|
|
59
|
+
void dispose() noexcept override {
|
|
60
|
+
_swiftPart.dispose();
|
|
61
|
+
}
|
|
62
|
+
std::string toString() override {
|
|
63
|
+
return _swiftPart.toString();
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
public:
|
|
67
|
+
// Properties
|
|
68
|
+
inline bool getIsLoaded() noexcept override {
|
|
69
|
+
return _swiftPart.isLoaded();
|
|
70
|
+
}
|
|
71
|
+
inline bool getIsTranscribing() noexcept override {
|
|
72
|
+
return _swiftPart.isTranscribing();
|
|
73
|
+
}
|
|
74
|
+
inline bool getIsListening() noexcept override {
|
|
75
|
+
return _swiftPart.isListening();
|
|
76
|
+
}
|
|
77
|
+
inline std::string getModelId() noexcept override {
|
|
78
|
+
auto __result = _swiftPart.getModelId();
|
|
79
|
+
return __result;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
public:
|
|
83
|
+
// Methods
|
|
84
|
+
inline std::shared_ptr<Promise<void>> load(const std::string& modelId, const std::optional<STTLoadOptions>& options) override {
|
|
85
|
+
auto __result = _swiftPart.load(modelId, options);
|
|
86
|
+
if (__result.hasError()) [[unlikely]] {
|
|
87
|
+
std::rethrow_exception(__result.error());
|
|
88
|
+
}
|
|
89
|
+
auto __value = std::move(__result.value());
|
|
90
|
+
return __value;
|
|
91
|
+
}
|
|
92
|
+
inline std::shared_ptr<Promise<std::string>> transcribe(const std::shared_ptr<ArrayBuffer>& audio) override {
|
|
93
|
+
auto __result = _swiftPart.transcribe(ArrayBufferHolder(audio));
|
|
94
|
+
if (__result.hasError()) [[unlikely]] {
|
|
95
|
+
std::rethrow_exception(__result.error());
|
|
96
|
+
}
|
|
97
|
+
auto __value = std::move(__result.value());
|
|
98
|
+
return __value;
|
|
99
|
+
}
|
|
100
|
+
inline std::shared_ptr<Promise<std::string>> transcribeStream(const std::shared_ptr<ArrayBuffer>& audio, const std::function<void(const std::string& /* token */)>& onToken) override {
|
|
101
|
+
auto __result = _swiftPart.transcribeStream(ArrayBufferHolder(audio), onToken);
|
|
102
|
+
if (__result.hasError()) [[unlikely]] {
|
|
103
|
+
std::rethrow_exception(__result.error());
|
|
104
|
+
}
|
|
105
|
+
auto __value = std::move(__result.value());
|
|
106
|
+
return __value;
|
|
107
|
+
}
|
|
108
|
+
inline std::shared_ptr<Promise<void>> startListening() override {
|
|
109
|
+
auto __result = _swiftPart.startListening();
|
|
110
|
+
if (__result.hasError()) [[unlikely]] {
|
|
111
|
+
std::rethrow_exception(__result.error());
|
|
112
|
+
}
|
|
113
|
+
auto __value = std::move(__result.value());
|
|
114
|
+
return __value;
|
|
115
|
+
}
|
|
116
|
+
inline std::shared_ptr<Promise<std::string>> transcribeBuffer() override {
|
|
117
|
+
auto __result = _swiftPart.transcribeBuffer();
|
|
118
|
+
if (__result.hasError()) [[unlikely]] {
|
|
119
|
+
std::rethrow_exception(__result.error());
|
|
120
|
+
}
|
|
121
|
+
auto __value = std::move(__result.value());
|
|
122
|
+
return __value;
|
|
123
|
+
}
|
|
124
|
+
inline std::shared_ptr<Promise<std::string>> stopListening() override {
|
|
125
|
+
auto __result = _swiftPart.stopListening();
|
|
126
|
+
if (__result.hasError()) [[unlikely]] {
|
|
127
|
+
std::rethrow_exception(__result.error());
|
|
128
|
+
}
|
|
129
|
+
auto __value = std::move(__result.value());
|
|
130
|
+
return __value;
|
|
131
|
+
}
|
|
132
|
+
inline void stop() override {
|
|
133
|
+
auto __result = _swiftPart.stop();
|
|
134
|
+
if (__result.hasError()) [[unlikely]] {
|
|
135
|
+
std::rethrow_exception(__result.error());
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
inline void unload() override {
|
|
139
|
+
auto __result = _swiftPart.unload();
|
|
140
|
+
if (__result.hasError()) [[unlikely]] {
|
|
141
|
+
std::rethrow_exception(__result.error());
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
private:
|
|
146
|
+
MLXReactNative::HybridSTTSpec_cxx _swiftPart;
|
|
147
|
+
};
|
|
148
|
+
|
|
149
|
+
} // namespace margelo::nitro::mlxreactnative
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
///
|
|
2
|
+
/// HybridTTSSpecSwift.cpp
|
|
3
|
+
/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
|
|
4
|
+
/// https://github.com/mrousavy/nitro
|
|
5
|
+
/// Copyright © 2026 Marc Rousavy @ Margelo
|
|
6
|
+
///
|
|
7
|
+
|
|
8
|
+
#include "HybridTTSSpecSwift.hpp"
|
|
9
|
+
|
|
10
|
+
namespace margelo::nitro::mlxreactnative {
|
|
11
|
+
} // namespace margelo::nitro::mlxreactnative
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
///
|
|
2
|
+
/// HybridTTSSpecSwift.hpp
|
|
3
|
+
/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
|
|
4
|
+
/// https://github.com/mrousavy/nitro
|
|
5
|
+
/// Copyright © 2026 Marc Rousavy @ Margelo
|
|
6
|
+
///
|
|
7
|
+
|
|
8
|
+
#pragma once
|
|
9
|
+
|
|
10
|
+
#include "HybridTTSSpec.hpp"
|
|
11
|
+
|
|
12
|
+
// Forward declaration of `HybridTTSSpec_cxx` to properly resolve imports.
|
|
13
|
+
namespace MLXReactNative { class HybridTTSSpec_cxx; }
|
|
14
|
+
|
|
15
|
+
// Forward declaration of `TTSLoadOptions` to properly resolve imports.
|
|
16
|
+
namespace margelo::nitro::mlxreactnative { struct TTSLoadOptions; }
|
|
17
|
+
// Forward declaration of `ArrayBufferHolder` to properly resolve imports.
|
|
18
|
+
namespace NitroModules { class ArrayBufferHolder; }
|
|
19
|
+
// Forward declaration of `TTSGenerateOptions` to properly resolve imports.
|
|
20
|
+
namespace margelo::nitro::mlxreactnative { struct TTSGenerateOptions; }
|
|
21
|
+
|
|
22
|
+
#include <string>
|
|
23
|
+
#include <NitroModules/Promise.hpp>
|
|
24
|
+
#include "TTSLoadOptions.hpp"
|
|
25
|
+
#include <optional>
|
|
26
|
+
#include <functional>
|
|
27
|
+
#include <NitroModules/ArrayBuffer.hpp>
|
|
28
|
+
#include <NitroModules/ArrayBufferHolder.hpp>
|
|
29
|
+
#include "TTSGenerateOptions.hpp"
|
|
30
|
+
|
|
31
|
+
#include "MLXReactNative-Swift-Cxx-Umbrella.hpp"
|
|
32
|
+
|
|
33
|
+
namespace margelo::nitro::mlxreactnative {
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* The C++ part of HybridTTSSpec_cxx.swift.
|
|
37
|
+
*
|
|
38
|
+
* HybridTTSSpecSwift (C++) accesses HybridTTSSpec_cxx (Swift), and might
|
|
39
|
+
* contain some additional bridging code for C++ <> Swift interop.
|
|
40
|
+
*
|
|
41
|
+
* Since this obviously introduces an overhead, I hope at some point in
|
|
42
|
+
* the future, HybridTTSSpec_cxx can directly inherit from the C++ class HybridTTSSpec
|
|
43
|
+
* to simplify the whole structure and memory management.
|
|
44
|
+
*/
|
|
45
|
+
class HybridTTSSpecSwift: public virtual HybridTTSSpec {
|
|
46
|
+
public:
|
|
47
|
+
// Constructor from a Swift instance
|
|
48
|
+
explicit HybridTTSSpecSwift(const MLXReactNative::HybridTTSSpec_cxx& swiftPart):
|
|
49
|
+
HybridObject(HybridTTSSpec::TAG),
|
|
50
|
+
_swiftPart(swiftPart) { }
|
|
51
|
+
|
|
52
|
+
public:
|
|
53
|
+
// Get the Swift part
|
|
54
|
+
inline MLXReactNative::HybridTTSSpec_cxx& getSwiftPart() noexcept {
|
|
55
|
+
return _swiftPart;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
public:
|
|
59
|
+
inline size_t getExternalMemorySize() noexcept override {
|
|
60
|
+
return _swiftPart.getMemorySize();
|
|
61
|
+
}
|
|
62
|
+
void dispose() noexcept override {
|
|
63
|
+
_swiftPart.dispose();
|
|
64
|
+
}
|
|
65
|
+
std::string toString() override {
|
|
66
|
+
return _swiftPart.toString();
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
public:
|
|
70
|
+
// Properties
|
|
71
|
+
inline bool getIsLoaded() noexcept override {
|
|
72
|
+
return _swiftPart.isLoaded();
|
|
73
|
+
}
|
|
74
|
+
inline bool getIsGenerating() noexcept override {
|
|
75
|
+
return _swiftPart.isGenerating();
|
|
76
|
+
}
|
|
77
|
+
inline std::string getModelId() noexcept override {
|
|
78
|
+
auto __result = _swiftPart.getModelId();
|
|
79
|
+
return __result;
|
|
80
|
+
}
|
|
81
|
+
inline double getSampleRate() noexcept override {
|
|
82
|
+
return _swiftPart.getSampleRate();
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
public:
|
|
86
|
+
// Methods
|
|
87
|
+
inline std::shared_ptr<Promise<void>> load(const std::string& modelId, const std::optional<TTSLoadOptions>& options) override {
|
|
88
|
+
auto __result = _swiftPart.load(modelId, options);
|
|
89
|
+
if (__result.hasError()) [[unlikely]] {
|
|
90
|
+
std::rethrow_exception(__result.error());
|
|
91
|
+
}
|
|
92
|
+
auto __value = std::move(__result.value());
|
|
93
|
+
return __value;
|
|
94
|
+
}
|
|
95
|
+
inline std::shared_ptr<Promise<std::shared_ptr<ArrayBuffer>>> generate(const std::string& text, const std::optional<TTSGenerateOptions>& options) override {
|
|
96
|
+
auto __result = _swiftPart.generate(text, options);
|
|
97
|
+
if (__result.hasError()) [[unlikely]] {
|
|
98
|
+
std::rethrow_exception(__result.error());
|
|
99
|
+
}
|
|
100
|
+
auto __value = std::move(__result.value());
|
|
101
|
+
return __value;
|
|
102
|
+
}
|
|
103
|
+
inline std::shared_ptr<Promise<void>> stream(const std::string& text, const std::function<void(const std::shared_ptr<ArrayBuffer>& /* audio */)>& onAudioChunk, const std::optional<TTSGenerateOptions>& options) override {
|
|
104
|
+
auto __result = _swiftPart.stream(text, onAudioChunk, options);
|
|
105
|
+
if (__result.hasError()) [[unlikely]] {
|
|
106
|
+
std::rethrow_exception(__result.error());
|
|
107
|
+
}
|
|
108
|
+
auto __value = std::move(__result.value());
|
|
109
|
+
return __value;
|
|
110
|
+
}
|
|
111
|
+
inline void stop() override {
|
|
112
|
+
auto __result = _swiftPart.stop();
|
|
113
|
+
if (__result.hasError()) [[unlikely]] {
|
|
114
|
+
std::rethrow_exception(__result.error());
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
inline void unload() override {
|
|
118
|
+
auto __result = _swiftPart.unload();
|
|
119
|
+
if (__result.hasError()) [[unlikely]] {
|
|
120
|
+
std::rethrow_exception(__result.error());
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
private:
|
|
125
|
+
MLXReactNative::HybridTTSSpec_cxx _swiftPart;
|
|
126
|
+
};
|
|
127
|
+
|
|
128
|
+
} // namespace margelo::nitro::mlxreactnative
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
///
|
|
2
|
+
/// Func_std__shared_ptr_Promise_std__shared_ptr_Promise_std__shared_ptr_AnyMap______std__shared_ptr_AnyMap_.swift
|
|
3
|
+
/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
|
|
4
|
+
/// https://github.com/mrousavy/nitro
|
|
5
|
+
/// Copyright © 2026 Marc Rousavy @ Margelo
|
|
6
|
+
///
|
|
7
|
+
|
|
8
|
+
import Foundation
|
|
9
|
+
import NitroModules
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Wraps a Swift `(_ args: AnyMap) -> Promise<Promise<AnyMap>>` as a class.
|
|
13
|
+
* This class can be used from C++, e.g. to wrap the Swift closure as a `std::function`.
|
|
14
|
+
*/
|
|
15
|
+
public final class Func_std__shared_ptr_Promise_std__shared_ptr_Promise_std__shared_ptr_AnyMap______std__shared_ptr_AnyMap_ {
|
|
16
|
+
public typealias bridge = margelo.nitro.mlxreactnative.bridge.swift
|
|
17
|
+
|
|
18
|
+
private let closure: (_ args: AnyMap) -> Promise<Promise<AnyMap>>
|
|
19
|
+
|
|
20
|
+
public init(_ closure: @escaping (_ args: AnyMap) -> Promise<Promise<AnyMap>>) {
|
|
21
|
+
self.closure = closure
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
@inline(__always)
|
|
25
|
+
public func call(args: margelo.nitro.SharedAnyMap) -> bridge.std__shared_ptr_Promise_std__shared_ptr_Promise_std__shared_ptr_AnyMap_____ {
|
|
26
|
+
let __result: Promise<Promise<AnyMap>> = self.closure(AnyMap(withCppPart: args))
|
|
27
|
+
return { () -> bridge.std__shared_ptr_Promise_std__shared_ptr_Promise_std__shared_ptr_AnyMap_____ in
|
|
28
|
+
let __promise = bridge.create_std__shared_ptr_Promise_std__shared_ptr_Promise_std__shared_ptr_AnyMap_____()
|
|
29
|
+
let __promiseHolder = bridge.wrap_std__shared_ptr_Promise_std__shared_ptr_Promise_std__shared_ptr_AnyMap_____(__promise)
|
|
30
|
+
__result
|
|
31
|
+
.then({ __result in __promiseHolder.resolve({ () -> bridge.std__shared_ptr_Promise_std__shared_ptr_AnyMap___ in
|
|
32
|
+
let __promise = bridge.create_std__shared_ptr_Promise_std__shared_ptr_AnyMap___()
|
|
33
|
+
let __promiseHolder = bridge.wrap_std__shared_ptr_Promise_std__shared_ptr_AnyMap___(__promise)
|
|
34
|
+
__result
|
|
35
|
+
.then({ __result in __promiseHolder.resolve(__result.cppPart) })
|
|
36
|
+
.catch({ __error in __promiseHolder.reject(__error.toCpp()) })
|
|
37
|
+
return __promise
|
|
38
|
+
}()) })
|
|
39
|
+
.catch({ __error in __promiseHolder.reject(__error.toCpp()) })
|
|
40
|
+
return __promise
|
|
41
|
+
}()
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Casts this instance to a retained unsafe raw pointer.
|
|
46
|
+
* This acquires one additional strong reference on the object!
|
|
47
|
+
*/
|
|
48
|
+
@inline(__always)
|
|
49
|
+
public func toUnsafe() -> UnsafeMutableRawPointer {
|
|
50
|
+
return Unmanaged.passRetained(self).toOpaque()
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Casts an unsafe pointer to a `Func_std__shared_ptr_Promise_std__shared_ptr_Promise_std__shared_ptr_AnyMap______std__shared_ptr_AnyMap_`.
|
|
55
|
+
* The pointer has to be a retained opaque `Unmanaged<Func_std__shared_ptr_Promise_std__shared_ptr_Promise_std__shared_ptr_AnyMap______std__shared_ptr_AnyMap_>`.
|
|
56
|
+
* This removes one strong reference from the object!
|
|
57
|
+
*/
|
|
58
|
+
@inline(__always)
|
|
59
|
+
public static func fromUnsafe(_ pointer: UnsafeMutableRawPointer) -> Func_std__shared_ptr_Promise_std__shared_ptr_Promise_std__shared_ptr_AnyMap______std__shared_ptr_AnyMap_ {
|
|
60
|
+
return Unmanaged<Func_std__shared_ptr_Promise_std__shared_ptr_Promise_std__shared_ptr_AnyMap______std__shared_ptr_AnyMap_>.fromOpaque(pointer).takeRetainedValue()
|
|
61
|
+
}
|
|
62
|
+
}
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
/// Func_void_std__exception_ptr.swift
|
|
3
3
|
/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
|
|
4
4
|
/// https://github.com/mrousavy/nitro
|
|
5
|
-
/// Copyright ©
|
|
5
|
+
/// Copyright © 2026 Marc Rousavy @ Margelo
|
|
6
6
|
///
|
|
7
7
|
|
|
8
8
|
import Foundation
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
///
|
|
2
|
+
/// Func_void_std__shared_ptr_AnyMap_.swift
|
|
3
|
+
/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
|
|
4
|
+
/// https://github.com/mrousavy/nitro
|
|
5
|
+
/// Copyright © 2026 Marc Rousavy @ Margelo
|
|
6
|
+
///
|
|
7
|
+
|
|
8
|
+
import Foundation
|
|
9
|
+
import NitroModules
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Wraps a Swift `(_ value: AnyMap) -> Void` as a class.
|
|
13
|
+
* This class can be used from C++, e.g. to wrap the Swift closure as a `std::function`.
|
|
14
|
+
*/
|
|
15
|
+
public final class Func_void_std__shared_ptr_AnyMap_ {
|
|
16
|
+
public typealias bridge = margelo.nitro.mlxreactnative.bridge.swift
|
|
17
|
+
|
|
18
|
+
private let closure: (_ value: AnyMap) -> Void
|
|
19
|
+
|
|
20
|
+
public init(_ closure: @escaping (_ value: AnyMap) -> Void) {
|
|
21
|
+
self.closure = closure
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
@inline(__always)
|
|
25
|
+
public func call(value: margelo.nitro.SharedAnyMap) -> Void {
|
|
26
|
+
self.closure(AnyMap(withCppPart: value))
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Casts this instance to a retained unsafe raw pointer.
|
|
31
|
+
* This acquires one additional strong reference on the object!
|
|
32
|
+
*/
|
|
33
|
+
@inline(__always)
|
|
34
|
+
public func toUnsafe() -> UnsafeMutableRawPointer {
|
|
35
|
+
return Unmanaged.passRetained(self).toOpaque()
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Casts an unsafe pointer to a `Func_void_std__shared_ptr_AnyMap_`.
|
|
40
|
+
* The pointer has to be a retained opaque `Unmanaged<Func_void_std__shared_ptr_AnyMap_>`.
|
|
41
|
+
* This removes one strong reference from the object!
|
|
42
|
+
*/
|
|
43
|
+
@inline(__always)
|
|
44
|
+
public static func fromUnsafe(_ pointer: UnsafeMutableRawPointer) -> Func_void_std__shared_ptr_AnyMap_ {
|
|
45
|
+
return Unmanaged<Func_void_std__shared_ptr_AnyMap_>.fromOpaque(pointer).takeRetainedValue()
|
|
46
|
+
}
|
|
47
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
///
|
|
2
|
+
/// Func_void_std__shared_ptr_ArrayBuffer_.swift
|
|
3
|
+
/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
|
|
4
|
+
/// https://github.com/mrousavy/nitro
|
|
5
|
+
/// Copyright © 2026 Marc Rousavy @ Margelo
|
|
6
|
+
///
|
|
7
|
+
|
|
8
|
+
import Foundation
|
|
9
|
+
import NitroModules
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Wraps a Swift `(_ value: ArrayBuffer) -> Void` as a class.
|
|
13
|
+
* This class can be used from C++, e.g. to wrap the Swift closure as a `std::function`.
|
|
14
|
+
*/
|
|
15
|
+
public final class Func_void_std__shared_ptr_ArrayBuffer_ {
|
|
16
|
+
public typealias bridge = margelo.nitro.mlxreactnative.bridge.swift
|
|
17
|
+
|
|
18
|
+
private let closure: (_ value: ArrayBuffer) -> Void
|
|
19
|
+
|
|
20
|
+
public init(_ closure: @escaping (_ value: ArrayBuffer) -> Void) {
|
|
21
|
+
self.closure = closure
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
@inline(__always)
|
|
25
|
+
public func call(value: ArrayBuffer) -> Void {
|
|
26
|
+
self.closure(value)
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Casts this instance to a retained unsafe raw pointer.
|
|
31
|
+
* This acquires one additional strong reference on the object!
|
|
32
|
+
*/
|
|
33
|
+
@inline(__always)
|
|
34
|
+
public func toUnsafe() -> UnsafeMutableRawPointer {
|
|
35
|
+
return Unmanaged.passRetained(self).toOpaque()
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Casts an unsafe pointer to a `Func_void_std__shared_ptr_ArrayBuffer_`.
|
|
40
|
+
* The pointer has to be a retained opaque `Unmanaged<Func_void_std__shared_ptr_ArrayBuffer_>`.
|
|
41
|
+
* This removes one strong reference from the object!
|
|
42
|
+
*/
|
|
43
|
+
@inline(__always)
|
|
44
|
+
public static func fromUnsafe(_ pointer: UnsafeMutableRawPointer) -> Func_void_std__shared_ptr_ArrayBuffer_ {
|
|
45
|
+
return Unmanaged<Func_void_std__shared_ptr_ArrayBuffer_>.fromOpaque(pointer).takeRetainedValue()
|
|
46
|
+
}
|
|
47
|
+
}
|