react-native-nitro-mlx 0.3.0 → 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 +309 -68
- 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 +2 -0
- package/lib/module/index.js.map +1 -1
- package/lib/module/llm.js +39 -1
- 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/tts.js +40 -0
- package/lib/module/tts.js.map +1 -0
- package/lib/typescript/src/index.d.ts +7 -3
- package/lib/typescript/src/index.d.ts.map +1 -1
- package/lib/typescript/src/llm.d.ts +32 -2
- 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 +49 -4
- 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/tts.d.ts +13 -0
- package/lib/typescript/src/tts.d.ts.map +1 -0
- package/nitrogen/generated/ios/MLXReactNative-Swift-Cxx-Bridge.cpp +42 -0
- package/nitrogen/generated/ios/MLXReactNative-Swift-Cxx-Bridge.hpp +165 -0
- package/nitrogen/generated/ios/MLXReactNative-Swift-Cxx-Umbrella.hpp +20 -0
- package/nitrogen/generated/ios/MLXReactNativeAutolinking.mm +16 -0
- package/nitrogen/generated/ios/MLXReactNativeAutolinking.swift +30 -0
- package/nitrogen/generated/ios/c++/HybridLLMSpecSwift.hpp +8 -0
- 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_void_std__shared_ptr_ArrayBuffer_.swift +47 -0
- package/nitrogen/generated/ios/swift/GenerationStats.swift +13 -2
- package/nitrogen/generated/ios/swift/HybridLLMSpec.swift +1 -0
- package/nitrogen/generated/ios/swift/HybridLLMSpec_cxx.swift +24 -0
- 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/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/shared/c++/GenerationStats.hpp +6 -2
- package/nitrogen/generated/shared/c++/HybridLLMSpec.cpp +1 -0
- package/nitrogen/generated/shared/c++/HybridLLMSpec.hpp +1 -0
- 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++/STTLoadOptions.hpp +76 -0
- package/nitrogen/generated/shared/c++/TTSGenerateOptions.hpp +80 -0
- package/nitrogen/generated/shared/c++/TTSLoadOptions.hpp +76 -0
- package/package.json +8 -4
- package/src/index.ts +31 -1
- package/src/llm.ts +48 -2
- package/src/models.ts +81 -1
- package/src/specs/LLM.nitro.ts +74 -4
- package/src/specs/STT.nitro.ts +35 -0
- package/src/specs/TTS.nitro.ts +30 -0
- package/src/stt.ts +67 -0
- package/src/tts.ts +60 -0
|
@@ -0,0 +1,229 @@
|
|
|
1
|
+
///
|
|
2
|
+
/// HybridTTSSpec_cxx.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
|
+
* A class implementation that bridges HybridTTSSpec over to C++.
|
|
13
|
+
* In C++, we cannot use Swift protocols - so we need to wrap it in a class to make it strongly defined.
|
|
14
|
+
*
|
|
15
|
+
* Also, some Swift types need to be bridged with special handling:
|
|
16
|
+
* - Enums need to be wrapped in Structs, otherwise they cannot be accessed bi-directionally (Swift bug: https://github.com/swiftlang/swift/issues/75330)
|
|
17
|
+
* - Other HybridObjects need to be wrapped/unwrapped from the Swift TCxx wrapper
|
|
18
|
+
* - Throwing methods need to be wrapped with a Result<T, Error> type, as exceptions cannot be propagated to C++
|
|
19
|
+
*/
|
|
20
|
+
open class HybridTTSSpec_cxx {
|
|
21
|
+
/**
|
|
22
|
+
* The Swift <> C++ bridge's namespace (`margelo::nitro::mlxreactnative::bridge::swift`)
|
|
23
|
+
* from `MLXReactNative-Swift-Cxx-Bridge.hpp`.
|
|
24
|
+
* This contains specialized C++ templates, and C++ helper functions that can be accessed from Swift.
|
|
25
|
+
*/
|
|
26
|
+
public typealias bridge = margelo.nitro.mlxreactnative.bridge.swift
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Holds an instance of the `HybridTTSSpec` Swift protocol.
|
|
30
|
+
*/
|
|
31
|
+
private var __implementation: any HybridTTSSpec
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Holds a weak pointer to the C++ class that wraps the Swift class.
|
|
35
|
+
*/
|
|
36
|
+
private var __cxxPart: bridge.std__weak_ptr_HybridTTSSpec_
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Create a new `HybridTTSSpec_cxx` that wraps the given `HybridTTSSpec`.
|
|
40
|
+
* All properties and methods bridge to C++ types.
|
|
41
|
+
*/
|
|
42
|
+
public init(_ implementation: any HybridTTSSpec) {
|
|
43
|
+
self.__implementation = implementation
|
|
44
|
+
self.__cxxPart = .init()
|
|
45
|
+
/* no base class */
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Get the actual `HybridTTSSpec` instance this class wraps.
|
|
50
|
+
*/
|
|
51
|
+
@inline(__always)
|
|
52
|
+
public func getHybridTTSSpec() -> any HybridTTSSpec {
|
|
53
|
+
return __implementation
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Casts this instance to a retained unsafe raw pointer.
|
|
58
|
+
* This acquires one additional strong reference on the object!
|
|
59
|
+
*/
|
|
60
|
+
public func toUnsafe() -> UnsafeMutableRawPointer {
|
|
61
|
+
return Unmanaged.passRetained(self).toOpaque()
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Casts an unsafe pointer to a `HybridTTSSpec_cxx`.
|
|
66
|
+
* The pointer has to be a retained opaque `Unmanaged<HybridTTSSpec_cxx>`.
|
|
67
|
+
* This removes one strong reference from the object!
|
|
68
|
+
*/
|
|
69
|
+
public class func fromUnsafe(_ pointer: UnsafeMutableRawPointer) -> HybridTTSSpec_cxx {
|
|
70
|
+
return Unmanaged<HybridTTSSpec_cxx>.fromOpaque(pointer).takeRetainedValue()
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* Gets (or creates) the C++ part of this Hybrid Object.
|
|
75
|
+
* The C++ part is a `std::shared_ptr<HybridTTSSpec>`.
|
|
76
|
+
*/
|
|
77
|
+
public func getCxxPart() -> bridge.std__shared_ptr_HybridTTSSpec_ {
|
|
78
|
+
let cachedCxxPart = self.__cxxPart.lock()
|
|
79
|
+
if Bool(fromCxx: cachedCxxPart) {
|
|
80
|
+
return cachedCxxPart
|
|
81
|
+
} else {
|
|
82
|
+
let newCxxPart = bridge.create_std__shared_ptr_HybridTTSSpec_(self.toUnsafe())
|
|
83
|
+
__cxxPart = bridge.weakify_std__shared_ptr_HybridTTSSpec_(newCxxPart)
|
|
84
|
+
return newCxxPart
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* Get the memory size of the Swift class (plus size of any other allocations)
|
|
92
|
+
* so the JS VM can properly track it and garbage-collect the JS object if needed.
|
|
93
|
+
*/
|
|
94
|
+
@inline(__always)
|
|
95
|
+
public var memorySize: Int {
|
|
96
|
+
return MemoryHelper.getSizeOf(self.__implementation) + self.__implementation.memorySize
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* Call dispose() on the Swift class.
|
|
101
|
+
* This _may_ be called manually from JS.
|
|
102
|
+
*/
|
|
103
|
+
@inline(__always)
|
|
104
|
+
public func dispose() {
|
|
105
|
+
self.__implementation.dispose()
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* Call toString() on the Swift class.
|
|
110
|
+
*/
|
|
111
|
+
@inline(__always)
|
|
112
|
+
public func toString() -> String {
|
|
113
|
+
return self.__implementation.toString()
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
// Properties
|
|
117
|
+
public final var isLoaded: Bool {
|
|
118
|
+
@inline(__always)
|
|
119
|
+
get {
|
|
120
|
+
return self.__implementation.isLoaded
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
public final var isGenerating: Bool {
|
|
125
|
+
@inline(__always)
|
|
126
|
+
get {
|
|
127
|
+
return self.__implementation.isGenerating
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
public final var modelId: std.string {
|
|
132
|
+
@inline(__always)
|
|
133
|
+
get {
|
|
134
|
+
return std.string(self.__implementation.modelId)
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
public final var sampleRate: Double {
|
|
139
|
+
@inline(__always)
|
|
140
|
+
get {
|
|
141
|
+
return self.__implementation.sampleRate
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
// Methods
|
|
146
|
+
@inline(__always)
|
|
147
|
+
public final func load(modelId: std.string, options: bridge.std__optional_TTSLoadOptions_) -> bridge.Result_std__shared_ptr_Promise_void___ {
|
|
148
|
+
do {
|
|
149
|
+
let __result = try self.__implementation.load(modelId: String(modelId), options: options.value)
|
|
150
|
+
let __resultCpp = { () -> bridge.std__shared_ptr_Promise_void__ in
|
|
151
|
+
let __promise = bridge.create_std__shared_ptr_Promise_void__()
|
|
152
|
+
let __promiseHolder = bridge.wrap_std__shared_ptr_Promise_void__(__promise)
|
|
153
|
+
__result
|
|
154
|
+
.then({ __result in __promiseHolder.resolve() })
|
|
155
|
+
.catch({ __error in __promiseHolder.reject(__error.toCpp()) })
|
|
156
|
+
return __promise
|
|
157
|
+
}()
|
|
158
|
+
return bridge.create_Result_std__shared_ptr_Promise_void___(__resultCpp)
|
|
159
|
+
} catch (let __error) {
|
|
160
|
+
let __exceptionPtr = __error.toCpp()
|
|
161
|
+
return bridge.create_Result_std__shared_ptr_Promise_void___(__exceptionPtr)
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
@inline(__always)
|
|
166
|
+
public final func generate(text: std.string, options: bridge.std__optional_TTSGenerateOptions_) -> bridge.Result_std__shared_ptr_Promise_std__shared_ptr_ArrayBuffer____ {
|
|
167
|
+
do {
|
|
168
|
+
let __result = try self.__implementation.generate(text: String(text), options: options.value)
|
|
169
|
+
let __resultCpp = { () -> bridge.std__shared_ptr_Promise_std__shared_ptr_ArrayBuffer___ in
|
|
170
|
+
let __promise = bridge.create_std__shared_ptr_Promise_std__shared_ptr_ArrayBuffer___()
|
|
171
|
+
let __promiseHolder = bridge.wrap_std__shared_ptr_Promise_std__shared_ptr_ArrayBuffer___(__promise)
|
|
172
|
+
__result
|
|
173
|
+
.then({ __result in __promiseHolder.resolve(__result.getArrayBuffer()) })
|
|
174
|
+
.catch({ __error in __promiseHolder.reject(__error.toCpp()) })
|
|
175
|
+
return __promise
|
|
176
|
+
}()
|
|
177
|
+
return bridge.create_Result_std__shared_ptr_Promise_std__shared_ptr_ArrayBuffer____(__resultCpp)
|
|
178
|
+
} catch (let __error) {
|
|
179
|
+
let __exceptionPtr = __error.toCpp()
|
|
180
|
+
return bridge.create_Result_std__shared_ptr_Promise_std__shared_ptr_ArrayBuffer____(__exceptionPtr)
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
@inline(__always)
|
|
185
|
+
public final func stream(text: std.string, onAudioChunk: bridge.Func_void_std__shared_ptr_ArrayBuffer_, options: bridge.std__optional_TTSGenerateOptions_) -> bridge.Result_std__shared_ptr_Promise_void___ {
|
|
186
|
+
do {
|
|
187
|
+
let __result = try self.__implementation.stream(text: String(text), onAudioChunk: { () -> (ArrayBuffer) -> Void in
|
|
188
|
+
let __wrappedFunction = bridge.wrap_Func_void_std__shared_ptr_ArrayBuffer_(onAudioChunk)
|
|
189
|
+
return { (__audio: ArrayBuffer) -> Void in
|
|
190
|
+
__wrappedFunction.call(__audio)
|
|
191
|
+
}
|
|
192
|
+
}(), options: options.value)
|
|
193
|
+
let __resultCpp = { () -> bridge.std__shared_ptr_Promise_void__ in
|
|
194
|
+
let __promise = bridge.create_std__shared_ptr_Promise_void__()
|
|
195
|
+
let __promiseHolder = bridge.wrap_std__shared_ptr_Promise_void__(__promise)
|
|
196
|
+
__result
|
|
197
|
+
.then({ __result in __promiseHolder.resolve() })
|
|
198
|
+
.catch({ __error in __promiseHolder.reject(__error.toCpp()) })
|
|
199
|
+
return __promise
|
|
200
|
+
}()
|
|
201
|
+
return bridge.create_Result_std__shared_ptr_Promise_void___(__resultCpp)
|
|
202
|
+
} catch (let __error) {
|
|
203
|
+
let __exceptionPtr = __error.toCpp()
|
|
204
|
+
return bridge.create_Result_std__shared_ptr_Promise_void___(__exceptionPtr)
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
@inline(__always)
|
|
209
|
+
public final func stop() -> bridge.Result_void_ {
|
|
210
|
+
do {
|
|
211
|
+
try self.__implementation.stop()
|
|
212
|
+
return bridge.create_Result_void_()
|
|
213
|
+
} catch (let __error) {
|
|
214
|
+
let __exceptionPtr = __error.toCpp()
|
|
215
|
+
return bridge.create_Result_void_(__exceptionPtr)
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
@inline(__always)
|
|
220
|
+
public final func unload() -> bridge.Result_void_ {
|
|
221
|
+
do {
|
|
222
|
+
try self.__implementation.unload()
|
|
223
|
+
return bridge.create_Result_void_()
|
|
224
|
+
} catch (let __error) {
|
|
225
|
+
let __exceptionPtr = __error.toCpp()
|
|
226
|
+
return bridge.create_Result_void_(__exceptionPtr)
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
///
|
|
2
|
+
/// STTLoadOptions.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
|
+
* Represents an instance of `STTLoadOptions`, backed by a C++ struct.
|
|
13
|
+
*/
|
|
14
|
+
public typealias STTLoadOptions = margelo.nitro.mlxreactnative.STTLoadOptions
|
|
15
|
+
|
|
16
|
+
public extension STTLoadOptions {
|
|
17
|
+
private typealias bridge = margelo.nitro.mlxreactnative.bridge.swift
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Create a new instance of `STTLoadOptions`.
|
|
21
|
+
*/
|
|
22
|
+
init(onProgress: ((_ progress: Double) -> Void)?) {
|
|
23
|
+
self.init({ () -> bridge.std__optional_std__function_void_double____progress______ in
|
|
24
|
+
if let __unwrappedValue = onProgress {
|
|
25
|
+
return bridge.create_std__optional_std__function_void_double____progress______({ () -> bridge.Func_void_double in
|
|
26
|
+
let __closureWrapper = Func_void_double(__unwrappedValue)
|
|
27
|
+
return bridge.create_Func_void_double(__closureWrapper.toUnsafe())
|
|
28
|
+
}())
|
|
29
|
+
} else {
|
|
30
|
+
return .init()
|
|
31
|
+
}
|
|
32
|
+
}())
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
var onProgress: ((_ progress: Double) -> Void)? {
|
|
36
|
+
@inline(__always)
|
|
37
|
+
get {
|
|
38
|
+
return { () -> ((_ progress: Double) -> Void)? in
|
|
39
|
+
if bridge.has_value_std__optional_std__function_void_double____progress______(self.__onProgress) {
|
|
40
|
+
let __unwrapped = bridge.get_std__optional_std__function_void_double____progress______(self.__onProgress)
|
|
41
|
+
return { () -> (Double) -> Void in
|
|
42
|
+
let __wrappedFunction = bridge.wrap_Func_void_double(__unwrapped)
|
|
43
|
+
return { (__progress: Double) -> Void in
|
|
44
|
+
__wrappedFunction.call(__progress)
|
|
45
|
+
}
|
|
46
|
+
}()
|
|
47
|
+
} else {
|
|
48
|
+
return nil
|
|
49
|
+
}
|
|
50
|
+
}()
|
|
51
|
+
}
|
|
52
|
+
@inline(__always)
|
|
53
|
+
set {
|
|
54
|
+
self.__onProgress = { () -> bridge.std__optional_std__function_void_double____progress______ in
|
|
55
|
+
if let __unwrappedValue = newValue {
|
|
56
|
+
return bridge.create_std__optional_std__function_void_double____progress______({ () -> bridge.Func_void_double in
|
|
57
|
+
let __closureWrapper = Func_void_double(__unwrappedValue)
|
|
58
|
+
return bridge.create_Func_void_double(__closureWrapper.toUnsafe())
|
|
59
|
+
}())
|
|
60
|
+
} else {
|
|
61
|
+
return .init()
|
|
62
|
+
}
|
|
63
|
+
}()
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
///
|
|
2
|
+
/// TTSGenerateOptions.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
|
+
* Represents an instance of `TTSGenerateOptions`, backed by a C++ struct.
|
|
13
|
+
*/
|
|
14
|
+
public typealias TTSGenerateOptions = margelo.nitro.mlxreactnative.TTSGenerateOptions
|
|
15
|
+
|
|
16
|
+
public extension TTSGenerateOptions {
|
|
17
|
+
private typealias bridge = margelo.nitro.mlxreactnative.bridge.swift
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Create a new instance of `TTSGenerateOptions`.
|
|
21
|
+
*/
|
|
22
|
+
init(voice: String?, speed: Double?) {
|
|
23
|
+
self.init({ () -> bridge.std__optional_std__string_ in
|
|
24
|
+
if let __unwrappedValue = voice {
|
|
25
|
+
return bridge.create_std__optional_std__string_(std.string(__unwrappedValue))
|
|
26
|
+
} else {
|
|
27
|
+
return .init()
|
|
28
|
+
}
|
|
29
|
+
}(), { () -> bridge.std__optional_double_ in
|
|
30
|
+
if let __unwrappedValue = speed {
|
|
31
|
+
return bridge.create_std__optional_double_(__unwrappedValue)
|
|
32
|
+
} else {
|
|
33
|
+
return .init()
|
|
34
|
+
}
|
|
35
|
+
}())
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
var voice: String? {
|
|
39
|
+
@inline(__always)
|
|
40
|
+
get {
|
|
41
|
+
return { () -> String? in
|
|
42
|
+
if bridge.has_value_std__optional_std__string_(self.__voice) {
|
|
43
|
+
let __unwrapped = bridge.get_std__optional_std__string_(self.__voice)
|
|
44
|
+
return String(__unwrapped)
|
|
45
|
+
} else {
|
|
46
|
+
return nil
|
|
47
|
+
}
|
|
48
|
+
}()
|
|
49
|
+
}
|
|
50
|
+
@inline(__always)
|
|
51
|
+
set {
|
|
52
|
+
self.__voice = { () -> bridge.std__optional_std__string_ in
|
|
53
|
+
if let __unwrappedValue = newValue {
|
|
54
|
+
return bridge.create_std__optional_std__string_(std.string(__unwrappedValue))
|
|
55
|
+
} else {
|
|
56
|
+
return .init()
|
|
57
|
+
}
|
|
58
|
+
}()
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
var speed: Double? {
|
|
63
|
+
@inline(__always)
|
|
64
|
+
get {
|
|
65
|
+
return self.__speed.value
|
|
66
|
+
}
|
|
67
|
+
@inline(__always)
|
|
68
|
+
set {
|
|
69
|
+
self.__speed = { () -> bridge.std__optional_double_ in
|
|
70
|
+
if let __unwrappedValue = newValue {
|
|
71
|
+
return bridge.create_std__optional_double_(__unwrappedValue)
|
|
72
|
+
} else {
|
|
73
|
+
return .init()
|
|
74
|
+
}
|
|
75
|
+
}()
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
///
|
|
2
|
+
/// TTSLoadOptions.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
|
+
* Represents an instance of `TTSLoadOptions`, backed by a C++ struct.
|
|
13
|
+
*/
|
|
14
|
+
public typealias TTSLoadOptions = margelo.nitro.mlxreactnative.TTSLoadOptions
|
|
15
|
+
|
|
16
|
+
public extension TTSLoadOptions {
|
|
17
|
+
private typealias bridge = margelo.nitro.mlxreactnative.bridge.swift
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Create a new instance of `TTSLoadOptions`.
|
|
21
|
+
*/
|
|
22
|
+
init(onProgress: ((_ progress: Double) -> Void)?) {
|
|
23
|
+
self.init({ () -> bridge.std__optional_std__function_void_double____progress______ in
|
|
24
|
+
if let __unwrappedValue = onProgress {
|
|
25
|
+
return bridge.create_std__optional_std__function_void_double____progress______({ () -> bridge.Func_void_double in
|
|
26
|
+
let __closureWrapper = Func_void_double(__unwrappedValue)
|
|
27
|
+
return bridge.create_Func_void_double(__closureWrapper.toUnsafe())
|
|
28
|
+
}())
|
|
29
|
+
} else {
|
|
30
|
+
return .init()
|
|
31
|
+
}
|
|
32
|
+
}())
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
var onProgress: ((_ progress: Double) -> Void)? {
|
|
36
|
+
@inline(__always)
|
|
37
|
+
get {
|
|
38
|
+
return { () -> ((_ progress: Double) -> Void)? in
|
|
39
|
+
if bridge.has_value_std__optional_std__function_void_double____progress______(self.__onProgress) {
|
|
40
|
+
let __unwrapped = bridge.get_std__optional_std__function_void_double____progress______(self.__onProgress)
|
|
41
|
+
return { () -> (Double) -> Void in
|
|
42
|
+
let __wrappedFunction = bridge.wrap_Func_void_double(__unwrapped)
|
|
43
|
+
return { (__progress: Double) -> Void in
|
|
44
|
+
__wrappedFunction.call(__progress)
|
|
45
|
+
}
|
|
46
|
+
}()
|
|
47
|
+
} else {
|
|
48
|
+
return nil
|
|
49
|
+
}
|
|
50
|
+
}()
|
|
51
|
+
}
|
|
52
|
+
@inline(__always)
|
|
53
|
+
set {
|
|
54
|
+
self.__onProgress = { () -> bridge.std__optional_std__function_void_double____progress______ in
|
|
55
|
+
if let __unwrappedValue = newValue {
|
|
56
|
+
return bridge.create_std__optional_std__function_void_double____progress______({ () -> bridge.Func_void_double in
|
|
57
|
+
let __closureWrapper = Func_void_double(__unwrappedValue)
|
|
58
|
+
return bridge.create_Func_void_double(__closureWrapper.toUnsafe())
|
|
59
|
+
}())
|
|
60
|
+
} else {
|
|
61
|
+
return .init()
|
|
62
|
+
}
|
|
63
|
+
}()
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
}
|
|
@@ -38,10 +38,11 @@ namespace margelo::nitro::mlxreactnative {
|
|
|
38
38
|
double tokensPerSecond SWIFT_PRIVATE;
|
|
39
39
|
double timeToFirstToken SWIFT_PRIVATE;
|
|
40
40
|
double totalTime SWIFT_PRIVATE;
|
|
41
|
+
double toolExecutionTime SWIFT_PRIVATE;
|
|
41
42
|
|
|
42
43
|
public:
|
|
43
44
|
GenerationStats() = default;
|
|
44
|
-
explicit GenerationStats(double tokenCount, double tokensPerSecond, double timeToFirstToken, double totalTime): tokenCount(tokenCount), tokensPerSecond(tokensPerSecond), timeToFirstToken(timeToFirstToken), totalTime(totalTime) {}
|
|
45
|
+
explicit GenerationStats(double tokenCount, double tokensPerSecond, double timeToFirstToken, double totalTime, double toolExecutionTime): tokenCount(tokenCount), tokensPerSecond(tokensPerSecond), timeToFirstToken(timeToFirstToken), totalTime(totalTime), toolExecutionTime(toolExecutionTime) {}
|
|
45
46
|
};
|
|
46
47
|
|
|
47
48
|
} // namespace margelo::nitro::mlxreactnative
|
|
@@ -57,7 +58,8 @@ namespace margelo::nitro {
|
|
|
57
58
|
JSIConverter<double>::fromJSI(runtime, obj.getProperty(runtime, "tokenCount")),
|
|
58
59
|
JSIConverter<double>::fromJSI(runtime, obj.getProperty(runtime, "tokensPerSecond")),
|
|
59
60
|
JSIConverter<double>::fromJSI(runtime, obj.getProperty(runtime, "timeToFirstToken")),
|
|
60
|
-
JSIConverter<double>::fromJSI(runtime, obj.getProperty(runtime, "totalTime"))
|
|
61
|
+
JSIConverter<double>::fromJSI(runtime, obj.getProperty(runtime, "totalTime")),
|
|
62
|
+
JSIConverter<double>::fromJSI(runtime, obj.getProperty(runtime, "toolExecutionTime"))
|
|
61
63
|
);
|
|
62
64
|
}
|
|
63
65
|
static inline jsi::Value toJSI(jsi::Runtime& runtime, const margelo::nitro::mlxreactnative::GenerationStats& arg) {
|
|
@@ -66,6 +68,7 @@ namespace margelo::nitro {
|
|
|
66
68
|
obj.setProperty(runtime, "tokensPerSecond", JSIConverter<double>::toJSI(runtime, arg.tokensPerSecond));
|
|
67
69
|
obj.setProperty(runtime, "timeToFirstToken", JSIConverter<double>::toJSI(runtime, arg.timeToFirstToken));
|
|
68
70
|
obj.setProperty(runtime, "totalTime", JSIConverter<double>::toJSI(runtime, arg.totalTime));
|
|
71
|
+
obj.setProperty(runtime, "toolExecutionTime", JSIConverter<double>::toJSI(runtime, arg.toolExecutionTime));
|
|
69
72
|
return obj;
|
|
70
73
|
}
|
|
71
74
|
static inline bool canConvert(jsi::Runtime& runtime, const jsi::Value& value) {
|
|
@@ -80,6 +83,7 @@ namespace margelo::nitro {
|
|
|
80
83
|
if (!JSIConverter<double>::canConvert(runtime, obj.getProperty(runtime, "tokensPerSecond"))) return false;
|
|
81
84
|
if (!JSIConverter<double>::canConvert(runtime, obj.getProperty(runtime, "timeToFirstToken"))) return false;
|
|
82
85
|
if (!JSIConverter<double>::canConvert(runtime, obj.getProperty(runtime, "totalTime"))) return false;
|
|
86
|
+
if (!JSIConverter<double>::canConvert(runtime, obj.getProperty(runtime, "toolExecutionTime"))) return false;
|
|
83
87
|
return true;
|
|
84
88
|
}
|
|
85
89
|
};
|
|
@@ -24,6 +24,7 @@ namespace margelo::nitro::mlxreactnative {
|
|
|
24
24
|
prototype.registerHybridMethod("load", &HybridLLMSpec::load);
|
|
25
25
|
prototype.registerHybridMethod("generate", &HybridLLMSpec::generate);
|
|
26
26
|
prototype.registerHybridMethod("stream", &HybridLLMSpec::stream);
|
|
27
|
+
prototype.registerHybridMethod("streamWithEvents", &HybridLLMSpec::streamWithEvents);
|
|
27
28
|
prototype.registerHybridMethod("stop", &HybridLLMSpec::stop);
|
|
28
29
|
prototype.registerHybridMethod("unload", &HybridLLMSpec::unload);
|
|
29
30
|
prototype.registerHybridMethod("getLastGenerationStats", &HybridLLMSpec::getLastGenerationStats);
|
|
@@ -69,6 +69,7 @@ namespace margelo::nitro::mlxreactnative {
|
|
|
69
69
|
virtual std::shared_ptr<Promise<void>> load(const std::string& modelId, const std::optional<LLMLoadOptions>& options) = 0;
|
|
70
70
|
virtual std::shared_ptr<Promise<std::string>> generate(const std::string& prompt) = 0;
|
|
71
71
|
virtual 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) = 0;
|
|
72
|
+
virtual std::shared_ptr<Promise<std::string>> streamWithEvents(const std::string& prompt, const std::function<void(const std::string& /* eventJson */)>& onEvent) = 0;
|
|
72
73
|
virtual void stop() = 0;
|
|
73
74
|
virtual void unload() = 0;
|
|
74
75
|
virtual GenerationStats getLastGenerationStats() = 0;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
///
|
|
2
|
+
/// HybridSTTSpec.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 "HybridSTTSpec.hpp"
|
|
9
|
+
|
|
10
|
+
namespace margelo::nitro::mlxreactnative {
|
|
11
|
+
|
|
12
|
+
void HybridSTTSpec::loadHybridMethods() {
|
|
13
|
+
// load base methods/properties
|
|
14
|
+
HybridObject::loadHybridMethods();
|
|
15
|
+
// load custom methods/properties
|
|
16
|
+
registerHybrids(this, [](Prototype& prototype) {
|
|
17
|
+
prototype.registerHybridGetter("isLoaded", &HybridSTTSpec::getIsLoaded);
|
|
18
|
+
prototype.registerHybridGetter("isTranscribing", &HybridSTTSpec::getIsTranscribing);
|
|
19
|
+
prototype.registerHybridGetter("isListening", &HybridSTTSpec::getIsListening);
|
|
20
|
+
prototype.registerHybridGetter("modelId", &HybridSTTSpec::getModelId);
|
|
21
|
+
prototype.registerHybridMethod("load", &HybridSTTSpec::load);
|
|
22
|
+
prototype.registerHybridMethod("transcribe", &HybridSTTSpec::transcribe);
|
|
23
|
+
prototype.registerHybridMethod("transcribeStream", &HybridSTTSpec::transcribeStream);
|
|
24
|
+
prototype.registerHybridMethod("startListening", &HybridSTTSpec::startListening);
|
|
25
|
+
prototype.registerHybridMethod("transcribeBuffer", &HybridSTTSpec::transcribeBuffer);
|
|
26
|
+
prototype.registerHybridMethod("stopListening", &HybridSTTSpec::stopListening);
|
|
27
|
+
prototype.registerHybridMethod("stop", &HybridSTTSpec::stop);
|
|
28
|
+
prototype.registerHybridMethod("unload", &HybridSTTSpec::unload);
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
} // namespace margelo::nitro::mlxreactnative
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
///
|
|
2
|
+
/// HybridSTTSpec.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
|
+
#if __has_include(<NitroModules/HybridObject.hpp>)
|
|
11
|
+
#include <NitroModules/HybridObject.hpp>
|
|
12
|
+
#else
|
|
13
|
+
#error NitroModules cannot be found! Are you sure you installed NitroModules properly?
|
|
14
|
+
#endif
|
|
15
|
+
|
|
16
|
+
// Forward declaration of `STTLoadOptions` to properly resolve imports.
|
|
17
|
+
namespace margelo::nitro::mlxreactnative { struct STTLoadOptions; }
|
|
18
|
+
|
|
19
|
+
#include <string>
|
|
20
|
+
#include <NitroModules/Promise.hpp>
|
|
21
|
+
#include "STTLoadOptions.hpp"
|
|
22
|
+
#include <optional>
|
|
23
|
+
#include <NitroModules/ArrayBuffer.hpp>
|
|
24
|
+
#include <functional>
|
|
25
|
+
|
|
26
|
+
namespace margelo::nitro::mlxreactnative {
|
|
27
|
+
|
|
28
|
+
using namespace margelo::nitro;
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* An abstract base class for `STT`
|
|
32
|
+
* Inherit this class to create instances of `HybridSTTSpec` in C++.
|
|
33
|
+
* You must explicitly call `HybridObject`'s constructor yourself, because it is virtual.
|
|
34
|
+
* @example
|
|
35
|
+
* ```cpp
|
|
36
|
+
* class HybridSTT: public HybridSTTSpec {
|
|
37
|
+
* public:
|
|
38
|
+
* HybridSTT(...): HybridObject(TAG) { ... }
|
|
39
|
+
* // ...
|
|
40
|
+
* };
|
|
41
|
+
* ```
|
|
42
|
+
*/
|
|
43
|
+
class HybridSTTSpec: public virtual HybridObject {
|
|
44
|
+
public:
|
|
45
|
+
// Constructor
|
|
46
|
+
explicit HybridSTTSpec(): HybridObject(TAG) { }
|
|
47
|
+
|
|
48
|
+
// Destructor
|
|
49
|
+
~HybridSTTSpec() override = default;
|
|
50
|
+
|
|
51
|
+
public:
|
|
52
|
+
// Properties
|
|
53
|
+
virtual bool getIsLoaded() = 0;
|
|
54
|
+
virtual bool getIsTranscribing() = 0;
|
|
55
|
+
virtual bool getIsListening() = 0;
|
|
56
|
+
virtual std::string getModelId() = 0;
|
|
57
|
+
|
|
58
|
+
public:
|
|
59
|
+
// Methods
|
|
60
|
+
virtual std::shared_ptr<Promise<void>> load(const std::string& modelId, const std::optional<STTLoadOptions>& options) = 0;
|
|
61
|
+
virtual std::shared_ptr<Promise<std::string>> transcribe(const std::shared_ptr<ArrayBuffer>& audio) = 0;
|
|
62
|
+
virtual std::shared_ptr<Promise<std::string>> transcribeStream(const std::shared_ptr<ArrayBuffer>& audio, const std::function<void(const std::string& /* token */)>& onToken) = 0;
|
|
63
|
+
virtual std::shared_ptr<Promise<void>> startListening() = 0;
|
|
64
|
+
virtual std::shared_ptr<Promise<std::string>> transcribeBuffer() = 0;
|
|
65
|
+
virtual std::shared_ptr<Promise<std::string>> stopListening() = 0;
|
|
66
|
+
virtual void stop() = 0;
|
|
67
|
+
virtual void unload() = 0;
|
|
68
|
+
|
|
69
|
+
protected:
|
|
70
|
+
// Hybrid Setup
|
|
71
|
+
void loadHybridMethods() override;
|
|
72
|
+
|
|
73
|
+
protected:
|
|
74
|
+
// Tag for logging
|
|
75
|
+
static constexpr auto TAG = "STT";
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
} // namespace margelo::nitro::mlxreactnative
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
///
|
|
2
|
+
/// HybridTTSSpec.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 "HybridTTSSpec.hpp"
|
|
9
|
+
|
|
10
|
+
namespace margelo::nitro::mlxreactnative {
|
|
11
|
+
|
|
12
|
+
void HybridTTSSpec::loadHybridMethods() {
|
|
13
|
+
// load base methods/properties
|
|
14
|
+
HybridObject::loadHybridMethods();
|
|
15
|
+
// load custom methods/properties
|
|
16
|
+
registerHybrids(this, [](Prototype& prototype) {
|
|
17
|
+
prototype.registerHybridGetter("isLoaded", &HybridTTSSpec::getIsLoaded);
|
|
18
|
+
prototype.registerHybridGetter("isGenerating", &HybridTTSSpec::getIsGenerating);
|
|
19
|
+
prototype.registerHybridGetter("modelId", &HybridTTSSpec::getModelId);
|
|
20
|
+
prototype.registerHybridGetter("sampleRate", &HybridTTSSpec::getSampleRate);
|
|
21
|
+
prototype.registerHybridMethod("load", &HybridTTSSpec::load);
|
|
22
|
+
prototype.registerHybridMethod("generate", &HybridTTSSpec::generate);
|
|
23
|
+
prototype.registerHybridMethod("stream", &HybridTTSSpec::stream);
|
|
24
|
+
prototype.registerHybridMethod("stop", &HybridTTSSpec::stop);
|
|
25
|
+
prototype.registerHybridMethod("unload", &HybridTTSSpec::unload);
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
} // namespace margelo::nitro::mlxreactnative
|