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
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
///
|
|
2
|
+
/// Func_void_std__shared_ptr_Promise_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: Promise<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_Promise_std__shared_ptr_AnyMap___ {
|
|
16
|
+
public typealias bridge = margelo.nitro.mlxreactnative.bridge.swift
|
|
17
|
+
|
|
18
|
+
private let closure: (_ value: Promise<AnyMap>) -> Void
|
|
19
|
+
|
|
20
|
+
public init(_ closure: @escaping (_ value: Promise<AnyMap>) -> Void) {
|
|
21
|
+
self.closure = closure
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
@inline(__always)
|
|
25
|
+
public func call(value: bridge.std__shared_ptr_Promise_std__shared_ptr_AnyMap___) -> Void {
|
|
26
|
+
self.closure({ () -> Promise<AnyMap> in
|
|
27
|
+
let __promise = Promise<AnyMap>()
|
|
28
|
+
let __resolver = { (__result: AnyMap) in
|
|
29
|
+
__promise.resolve(withResult: __result)
|
|
30
|
+
}
|
|
31
|
+
let __rejecter = { (__error: Error) in
|
|
32
|
+
__promise.reject(withError: __error)
|
|
33
|
+
}
|
|
34
|
+
let __resolverCpp = { () -> bridge.Func_void_std__shared_ptr_AnyMap_ in
|
|
35
|
+
let __closureWrapper = Func_void_std__shared_ptr_AnyMap_(__resolver)
|
|
36
|
+
return bridge.create_Func_void_std__shared_ptr_AnyMap_(__closureWrapper.toUnsafe())
|
|
37
|
+
}()
|
|
38
|
+
let __rejecterCpp = { () -> bridge.Func_void_std__exception_ptr in
|
|
39
|
+
let __closureWrapper = Func_void_std__exception_ptr(__rejecter)
|
|
40
|
+
return bridge.create_Func_void_std__exception_ptr(__closureWrapper.toUnsafe())
|
|
41
|
+
}()
|
|
42
|
+
let __promiseHolder = bridge.wrap_std__shared_ptr_Promise_std__shared_ptr_AnyMap___(value)
|
|
43
|
+
__promiseHolder.addOnResolvedListener(__resolverCpp)
|
|
44
|
+
__promiseHolder.addOnRejectedListener(__rejecterCpp)
|
|
45
|
+
return __promise
|
|
46
|
+
}())
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Casts this instance to a retained unsafe raw pointer.
|
|
51
|
+
* This acquires one additional strong reference on the object!
|
|
52
|
+
*/
|
|
53
|
+
@inline(__always)
|
|
54
|
+
public func toUnsafe() -> UnsafeMutableRawPointer {
|
|
55
|
+
return Unmanaged.passRetained(self).toOpaque()
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* Casts an unsafe pointer to a `Func_void_std__shared_ptr_Promise_std__shared_ptr_AnyMap___`.
|
|
60
|
+
* The pointer has to be a retained opaque `Unmanaged<Func_void_std__shared_ptr_Promise_std__shared_ptr_AnyMap___>`.
|
|
61
|
+
* This removes one strong reference from the object!
|
|
62
|
+
*/
|
|
63
|
+
@inline(__always)
|
|
64
|
+
public static func fromUnsafe(_ pointer: UnsafeMutableRawPointer) -> Func_void_std__shared_ptr_Promise_std__shared_ptr_AnyMap___ {
|
|
65
|
+
return Unmanaged<Func_void_std__shared_ptr_Promise_std__shared_ptr_AnyMap___>.fromOpaque(pointer).takeRetainedValue()
|
|
66
|
+
}
|
|
67
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
///
|
|
2
|
+
/// Func_void_std__string_std__string.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 `(_ toolName: String, _ args: String) -> 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__string_std__string {
|
|
16
|
+
public typealias bridge = margelo.nitro.mlxreactnative.bridge.swift
|
|
17
|
+
|
|
18
|
+
private let closure: (_ toolName: String, _ args: String) -> Void
|
|
19
|
+
|
|
20
|
+
public init(_ closure: @escaping (_ toolName: String, _ args: String) -> Void) {
|
|
21
|
+
self.closure = closure
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
@inline(__always)
|
|
25
|
+
public func call(toolName: std.string, args: std.string) -> Void {
|
|
26
|
+
self.closure(String(toolName), String(args))
|
|
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__string_std__string`.
|
|
40
|
+
* The pointer has to be a retained opaque `Unmanaged<Func_void_std__string_std__string>`.
|
|
41
|
+
* This removes one strong reference from the object!
|
|
42
|
+
*/
|
|
43
|
+
@inline(__always)
|
|
44
|
+
public static func fromUnsafe(_ pointer: UnsafeMutableRawPointer) -> Func_void_std__string_std__string {
|
|
45
|
+
return Unmanaged<Func_void_std__string_std__string>.fromOpaque(pointer).takeRetainedValue()
|
|
46
|
+
}
|
|
47
|
+
}
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
/// Func_void_std__vector_std__string_.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
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
/// GenerationStats.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
|
|
@@ -19,8 +19,8 @@ public extension GenerationStats {
|
|
|
19
19
|
/**
|
|
20
20
|
* Create a new instance of `GenerationStats`.
|
|
21
21
|
*/
|
|
22
|
-
init(tokenCount: Double, tokensPerSecond: Double, timeToFirstToken: Double, totalTime: Double) {
|
|
23
|
-
self.init(tokenCount, tokensPerSecond, timeToFirstToken, totalTime)
|
|
22
|
+
init(tokenCount: Double, tokensPerSecond: Double, timeToFirstToken: Double, totalTime: Double, toolExecutionTime: Double) {
|
|
23
|
+
self.init(tokenCount, tokensPerSecond, timeToFirstToken, totalTime, toolExecutionTime)
|
|
24
24
|
}
|
|
25
25
|
|
|
26
26
|
var tokenCount: Double {
|
|
@@ -66,4 +66,15 @@ public extension GenerationStats {
|
|
|
66
66
|
self.__totalTime = newValue
|
|
67
67
|
}
|
|
68
68
|
}
|
|
69
|
+
|
|
70
|
+
var toolExecutionTime: Double {
|
|
71
|
+
@inline(__always)
|
|
72
|
+
get {
|
|
73
|
+
return self.__toolExecutionTime
|
|
74
|
+
}
|
|
75
|
+
@inline(__always)
|
|
76
|
+
set {
|
|
77
|
+
self.__toolExecutionTime = newValue
|
|
78
|
+
}
|
|
79
|
+
}
|
|
69
80
|
}
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
/// HybridLLMSpec.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
|
|
@@ -20,7 +20,8 @@ public protocol HybridLLMSpec_protocol: HybridObject {
|
|
|
20
20
|
// Methods
|
|
21
21
|
func load(modelId: String, options: LLMLoadOptions?) throws -> Promise<Void>
|
|
22
22
|
func generate(prompt: String) throws -> Promise<String>
|
|
23
|
-
func stream(prompt: String, onToken: @escaping (_ token: String) -> Void) throws -> Promise<String>
|
|
23
|
+
func stream(prompt: String, onToken: @escaping (_ token: String) -> Void, onToolCall: ((_ toolName: String, _ args: String) -> Void)?) throws -> Promise<String>
|
|
24
|
+
func streamWithEvents(prompt: String, onEvent: @escaping (_ eventJson: String) -> Void) throws -> Promise<String>
|
|
24
25
|
func stop() throws -> Void
|
|
25
26
|
func unload() throws -> Void
|
|
26
27
|
func getLastGenerationStats() throws -> GenerationStats
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
/// HybridLLMSpec_cxx.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
|
|
@@ -197,13 +197,49 @@ open class HybridLLMSpec_cxx {
|
|
|
197
197
|
}
|
|
198
198
|
|
|
199
199
|
@inline(__always)
|
|
200
|
-
public final func stream(prompt: std.string, onToken: bridge.Func_void_std__string) -> bridge.Result_std__shared_ptr_Promise_std__string___ {
|
|
200
|
+
public final func stream(prompt: std.string, onToken: bridge.Func_void_std__string, onToolCall: bridge.std__optional_std__function_void_const_std__string_____toolName_____const_std__string_____args______) -> bridge.Result_std__shared_ptr_Promise_std__string___ {
|
|
201
201
|
do {
|
|
202
202
|
let __result = try self.__implementation.stream(prompt: String(prompt), onToken: { () -> (String) -> Void in
|
|
203
203
|
let __wrappedFunction = bridge.wrap_Func_void_std__string(onToken)
|
|
204
204
|
return { (__token: String) -> Void in
|
|
205
205
|
__wrappedFunction.call(std.string(__token))
|
|
206
206
|
}
|
|
207
|
+
}(), onToolCall: { () -> ((_ toolName: String, _ args: String) -> Void)? in
|
|
208
|
+
if bridge.has_value_std__optional_std__function_void_const_std__string_____toolName_____const_std__string_____args______(onToolCall) {
|
|
209
|
+
let __unwrapped = bridge.get_std__optional_std__function_void_const_std__string_____toolName_____const_std__string_____args______(onToolCall)
|
|
210
|
+
return { () -> (String, String) -> Void in
|
|
211
|
+
let __wrappedFunction = bridge.wrap_Func_void_std__string_std__string(__unwrapped)
|
|
212
|
+
return { (__toolName: String, __args: String) -> Void in
|
|
213
|
+
__wrappedFunction.call(std.string(__toolName), std.string(__args))
|
|
214
|
+
}
|
|
215
|
+
}()
|
|
216
|
+
} else {
|
|
217
|
+
return nil
|
|
218
|
+
}
|
|
219
|
+
}())
|
|
220
|
+
let __resultCpp = { () -> bridge.std__shared_ptr_Promise_std__string__ in
|
|
221
|
+
let __promise = bridge.create_std__shared_ptr_Promise_std__string__()
|
|
222
|
+
let __promiseHolder = bridge.wrap_std__shared_ptr_Promise_std__string__(__promise)
|
|
223
|
+
__result
|
|
224
|
+
.then({ __result in __promiseHolder.resolve(std.string(__result)) })
|
|
225
|
+
.catch({ __error in __promiseHolder.reject(__error.toCpp()) })
|
|
226
|
+
return __promise
|
|
227
|
+
}()
|
|
228
|
+
return bridge.create_Result_std__shared_ptr_Promise_std__string___(__resultCpp)
|
|
229
|
+
} catch (let __error) {
|
|
230
|
+
let __exceptionPtr = __error.toCpp()
|
|
231
|
+
return bridge.create_Result_std__shared_ptr_Promise_std__string___(__exceptionPtr)
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
@inline(__always)
|
|
236
|
+
public final func streamWithEvents(prompt: std.string, onEvent: bridge.Func_void_std__string) -> bridge.Result_std__shared_ptr_Promise_std__string___ {
|
|
237
|
+
do {
|
|
238
|
+
let __result = try self.__implementation.streamWithEvents(prompt: String(prompt), onEvent: { () -> (String) -> Void in
|
|
239
|
+
let __wrappedFunction = bridge.wrap_Func_void_std__string(onEvent)
|
|
240
|
+
return { (__eventJson: String) -> Void in
|
|
241
|
+
__wrappedFunction.call(std.string(__eventJson))
|
|
242
|
+
}
|
|
207
243
|
}())
|
|
208
244
|
let __resultCpp = { () -> bridge.std__shared_ptr_Promise_std__string__ in
|
|
209
245
|
let __promise = bridge.create_std__shared_ptr_Promise_std__string__()
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
///
|
|
2
|
+
/// HybridSTTSpec.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
|
+
/// See ``HybridSTTSpec``
|
|
12
|
+
public protocol HybridSTTSpec_protocol: HybridObject {
|
|
13
|
+
// Properties
|
|
14
|
+
var isLoaded: Bool { get }
|
|
15
|
+
var isTranscribing: Bool { get }
|
|
16
|
+
var isListening: Bool { get }
|
|
17
|
+
var modelId: String { get }
|
|
18
|
+
|
|
19
|
+
// Methods
|
|
20
|
+
func load(modelId: String, options: STTLoadOptions?) throws -> Promise<Void>
|
|
21
|
+
func transcribe(audio: ArrayBuffer) throws -> Promise<String>
|
|
22
|
+
func transcribeStream(audio: ArrayBuffer, onToken: @escaping (_ token: String) -> Void) throws -> Promise<String>
|
|
23
|
+
func startListening() throws -> Promise<Void>
|
|
24
|
+
func transcribeBuffer() throws -> Promise<String>
|
|
25
|
+
func stopListening() throws -> Promise<String>
|
|
26
|
+
func stop() throws -> Void
|
|
27
|
+
func unload() throws -> Void
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
public extension HybridSTTSpec_protocol {
|
|
31
|
+
/// Default implementation of ``HybridObject.toString``
|
|
32
|
+
func toString() -> String {
|
|
33
|
+
return "[HybridObject STT]"
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/// See ``HybridSTTSpec``
|
|
38
|
+
open class HybridSTTSpec_base {
|
|
39
|
+
private weak var cxxWrapper: HybridSTTSpec_cxx? = nil
|
|
40
|
+
public init() { }
|
|
41
|
+
public func getCxxWrapper() -> HybridSTTSpec_cxx {
|
|
42
|
+
#if DEBUG
|
|
43
|
+
guard self is HybridSTTSpec else {
|
|
44
|
+
fatalError("`self` is not a `HybridSTTSpec`! Did you accidentally inherit from `HybridSTTSpec_base` instead of `HybridSTTSpec`?")
|
|
45
|
+
}
|
|
46
|
+
#endif
|
|
47
|
+
if let cxxWrapper = self.cxxWrapper {
|
|
48
|
+
return cxxWrapper
|
|
49
|
+
} else {
|
|
50
|
+
let cxxWrapper = HybridSTTSpec_cxx(self as! HybridSTTSpec)
|
|
51
|
+
self.cxxWrapper = cxxWrapper
|
|
52
|
+
return cxxWrapper
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* A Swift base-protocol representing the STT HybridObject.
|
|
59
|
+
* Implement this protocol to create Swift-based instances of STT.
|
|
60
|
+
* ```swift
|
|
61
|
+
* class HybridSTT : HybridSTTSpec {
|
|
62
|
+
* // ...
|
|
63
|
+
* }
|
|
64
|
+
* ```
|
|
65
|
+
*/
|
|
66
|
+
public typealias HybridSTTSpec = HybridSTTSpec_protocol & HybridSTTSpec_base
|
|
@@ -0,0 +1,286 @@
|
|
|
1
|
+
///
|
|
2
|
+
/// HybridSTTSpec_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 HybridSTTSpec 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 HybridSTTSpec_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 `HybridSTTSpec` Swift protocol.
|
|
30
|
+
*/
|
|
31
|
+
private var __implementation: any HybridSTTSpec
|
|
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_HybridSTTSpec_
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Create a new `HybridSTTSpec_cxx` that wraps the given `HybridSTTSpec`.
|
|
40
|
+
* All properties and methods bridge to C++ types.
|
|
41
|
+
*/
|
|
42
|
+
public init(_ implementation: any HybridSTTSpec) {
|
|
43
|
+
self.__implementation = implementation
|
|
44
|
+
self.__cxxPart = .init()
|
|
45
|
+
/* no base class */
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Get the actual `HybridSTTSpec` instance this class wraps.
|
|
50
|
+
*/
|
|
51
|
+
@inline(__always)
|
|
52
|
+
public func getHybridSTTSpec() -> any HybridSTTSpec {
|
|
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 `HybridSTTSpec_cxx`.
|
|
66
|
+
* The pointer has to be a retained opaque `Unmanaged<HybridSTTSpec_cxx>`.
|
|
67
|
+
* This removes one strong reference from the object!
|
|
68
|
+
*/
|
|
69
|
+
public class func fromUnsafe(_ pointer: UnsafeMutableRawPointer) -> HybridSTTSpec_cxx {
|
|
70
|
+
return Unmanaged<HybridSTTSpec_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<HybridSTTSpec>`.
|
|
76
|
+
*/
|
|
77
|
+
public func getCxxPart() -> bridge.std__shared_ptr_HybridSTTSpec_ {
|
|
78
|
+
let cachedCxxPart = self.__cxxPart.lock()
|
|
79
|
+
if Bool(fromCxx: cachedCxxPart) {
|
|
80
|
+
return cachedCxxPart
|
|
81
|
+
} else {
|
|
82
|
+
let newCxxPart = bridge.create_std__shared_ptr_HybridSTTSpec_(self.toUnsafe())
|
|
83
|
+
__cxxPart = bridge.weakify_std__shared_ptr_HybridSTTSpec_(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 isTranscribing: Bool {
|
|
125
|
+
@inline(__always)
|
|
126
|
+
get {
|
|
127
|
+
return self.__implementation.isTranscribing
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
public final var isListening: Bool {
|
|
132
|
+
@inline(__always)
|
|
133
|
+
get {
|
|
134
|
+
return self.__implementation.isListening
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
public final var modelId: std.string {
|
|
139
|
+
@inline(__always)
|
|
140
|
+
get {
|
|
141
|
+
return std.string(self.__implementation.modelId)
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
// Methods
|
|
146
|
+
@inline(__always)
|
|
147
|
+
public final func load(modelId: std.string, options: bridge.std__optional_STTLoadOptions_) -> 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 transcribe(audio: ArrayBuffer) -> bridge.Result_std__shared_ptr_Promise_std__string___ {
|
|
167
|
+
do {
|
|
168
|
+
let __result = try self.__implementation.transcribe(audio: audio)
|
|
169
|
+
let __resultCpp = { () -> bridge.std__shared_ptr_Promise_std__string__ in
|
|
170
|
+
let __promise = bridge.create_std__shared_ptr_Promise_std__string__()
|
|
171
|
+
let __promiseHolder = bridge.wrap_std__shared_ptr_Promise_std__string__(__promise)
|
|
172
|
+
__result
|
|
173
|
+
.then({ __result in __promiseHolder.resolve(std.string(__result)) })
|
|
174
|
+
.catch({ __error in __promiseHolder.reject(__error.toCpp()) })
|
|
175
|
+
return __promise
|
|
176
|
+
}()
|
|
177
|
+
return bridge.create_Result_std__shared_ptr_Promise_std__string___(__resultCpp)
|
|
178
|
+
} catch (let __error) {
|
|
179
|
+
let __exceptionPtr = __error.toCpp()
|
|
180
|
+
return bridge.create_Result_std__shared_ptr_Promise_std__string___(__exceptionPtr)
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
@inline(__always)
|
|
185
|
+
public final func transcribeStream(audio: ArrayBuffer, onToken: bridge.Func_void_std__string) -> bridge.Result_std__shared_ptr_Promise_std__string___ {
|
|
186
|
+
do {
|
|
187
|
+
let __result = try self.__implementation.transcribeStream(audio: audio, onToken: { () -> (String) -> Void in
|
|
188
|
+
let __wrappedFunction = bridge.wrap_Func_void_std__string(onToken)
|
|
189
|
+
return { (__token: String) -> Void in
|
|
190
|
+
__wrappedFunction.call(std.string(__token))
|
|
191
|
+
}
|
|
192
|
+
}())
|
|
193
|
+
let __resultCpp = { () -> bridge.std__shared_ptr_Promise_std__string__ in
|
|
194
|
+
let __promise = bridge.create_std__shared_ptr_Promise_std__string__()
|
|
195
|
+
let __promiseHolder = bridge.wrap_std__shared_ptr_Promise_std__string__(__promise)
|
|
196
|
+
__result
|
|
197
|
+
.then({ __result in __promiseHolder.resolve(std.string(__result)) })
|
|
198
|
+
.catch({ __error in __promiseHolder.reject(__error.toCpp()) })
|
|
199
|
+
return __promise
|
|
200
|
+
}()
|
|
201
|
+
return bridge.create_Result_std__shared_ptr_Promise_std__string___(__resultCpp)
|
|
202
|
+
} catch (let __error) {
|
|
203
|
+
let __exceptionPtr = __error.toCpp()
|
|
204
|
+
return bridge.create_Result_std__shared_ptr_Promise_std__string___(__exceptionPtr)
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
@inline(__always)
|
|
209
|
+
public final func startListening() -> bridge.Result_std__shared_ptr_Promise_void___ {
|
|
210
|
+
do {
|
|
211
|
+
let __result = try self.__implementation.startListening()
|
|
212
|
+
let __resultCpp = { () -> bridge.std__shared_ptr_Promise_void__ in
|
|
213
|
+
let __promise = bridge.create_std__shared_ptr_Promise_void__()
|
|
214
|
+
let __promiseHolder = bridge.wrap_std__shared_ptr_Promise_void__(__promise)
|
|
215
|
+
__result
|
|
216
|
+
.then({ __result in __promiseHolder.resolve() })
|
|
217
|
+
.catch({ __error in __promiseHolder.reject(__error.toCpp()) })
|
|
218
|
+
return __promise
|
|
219
|
+
}()
|
|
220
|
+
return bridge.create_Result_std__shared_ptr_Promise_void___(__resultCpp)
|
|
221
|
+
} catch (let __error) {
|
|
222
|
+
let __exceptionPtr = __error.toCpp()
|
|
223
|
+
return bridge.create_Result_std__shared_ptr_Promise_void___(__exceptionPtr)
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
@inline(__always)
|
|
228
|
+
public final func transcribeBuffer() -> bridge.Result_std__shared_ptr_Promise_std__string___ {
|
|
229
|
+
do {
|
|
230
|
+
let __result = try self.__implementation.transcribeBuffer()
|
|
231
|
+
let __resultCpp = { () -> bridge.std__shared_ptr_Promise_std__string__ in
|
|
232
|
+
let __promise = bridge.create_std__shared_ptr_Promise_std__string__()
|
|
233
|
+
let __promiseHolder = bridge.wrap_std__shared_ptr_Promise_std__string__(__promise)
|
|
234
|
+
__result
|
|
235
|
+
.then({ __result in __promiseHolder.resolve(std.string(__result)) })
|
|
236
|
+
.catch({ __error in __promiseHolder.reject(__error.toCpp()) })
|
|
237
|
+
return __promise
|
|
238
|
+
}()
|
|
239
|
+
return bridge.create_Result_std__shared_ptr_Promise_std__string___(__resultCpp)
|
|
240
|
+
} catch (let __error) {
|
|
241
|
+
let __exceptionPtr = __error.toCpp()
|
|
242
|
+
return bridge.create_Result_std__shared_ptr_Promise_std__string___(__exceptionPtr)
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
@inline(__always)
|
|
247
|
+
public final func stopListening() -> bridge.Result_std__shared_ptr_Promise_std__string___ {
|
|
248
|
+
do {
|
|
249
|
+
let __result = try self.__implementation.stopListening()
|
|
250
|
+
let __resultCpp = { () -> bridge.std__shared_ptr_Promise_std__string__ in
|
|
251
|
+
let __promise = bridge.create_std__shared_ptr_Promise_std__string__()
|
|
252
|
+
let __promiseHolder = bridge.wrap_std__shared_ptr_Promise_std__string__(__promise)
|
|
253
|
+
__result
|
|
254
|
+
.then({ __result in __promiseHolder.resolve(std.string(__result)) })
|
|
255
|
+
.catch({ __error in __promiseHolder.reject(__error.toCpp()) })
|
|
256
|
+
return __promise
|
|
257
|
+
}()
|
|
258
|
+
return bridge.create_Result_std__shared_ptr_Promise_std__string___(__resultCpp)
|
|
259
|
+
} catch (let __error) {
|
|
260
|
+
let __exceptionPtr = __error.toCpp()
|
|
261
|
+
return bridge.create_Result_std__shared_ptr_Promise_std__string___(__exceptionPtr)
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
@inline(__always)
|
|
266
|
+
public final func stop() -> bridge.Result_void_ {
|
|
267
|
+
do {
|
|
268
|
+
try self.__implementation.stop()
|
|
269
|
+
return bridge.create_Result_void_()
|
|
270
|
+
} catch (let __error) {
|
|
271
|
+
let __exceptionPtr = __error.toCpp()
|
|
272
|
+
return bridge.create_Result_void_(__exceptionPtr)
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
@inline(__always)
|
|
277
|
+
public final func unload() -> bridge.Result_void_ {
|
|
278
|
+
do {
|
|
279
|
+
try self.__implementation.unload()
|
|
280
|
+
return bridge.create_Result_void_()
|
|
281
|
+
} catch (let __error) {
|
|
282
|
+
let __exceptionPtr = __error.toCpp()
|
|
283
|
+
return bridge.create_Result_void_(__exceptionPtr)
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
///
|
|
2
|
+
/// HybridTTSSpec.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
|
+
/// See ``HybridTTSSpec``
|
|
12
|
+
public protocol HybridTTSSpec_protocol: HybridObject {
|
|
13
|
+
// Properties
|
|
14
|
+
var isLoaded: Bool { get }
|
|
15
|
+
var isGenerating: Bool { get }
|
|
16
|
+
var modelId: String { get }
|
|
17
|
+
var sampleRate: Double { get }
|
|
18
|
+
|
|
19
|
+
// Methods
|
|
20
|
+
func load(modelId: String, options: TTSLoadOptions?) throws -> Promise<Void>
|
|
21
|
+
func generate(text: String, options: TTSGenerateOptions?) throws -> Promise<ArrayBuffer>
|
|
22
|
+
func stream(text: String, onAudioChunk: @escaping (_ audio: ArrayBuffer) -> Void, options: TTSGenerateOptions?) throws -> Promise<Void>
|
|
23
|
+
func stop() throws -> Void
|
|
24
|
+
func unload() throws -> Void
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
public extension HybridTTSSpec_protocol {
|
|
28
|
+
/// Default implementation of ``HybridObject.toString``
|
|
29
|
+
func toString() -> String {
|
|
30
|
+
return "[HybridObject TTS]"
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/// See ``HybridTTSSpec``
|
|
35
|
+
open class HybridTTSSpec_base {
|
|
36
|
+
private weak var cxxWrapper: HybridTTSSpec_cxx? = nil
|
|
37
|
+
public init() { }
|
|
38
|
+
public func getCxxWrapper() -> HybridTTSSpec_cxx {
|
|
39
|
+
#if DEBUG
|
|
40
|
+
guard self is HybridTTSSpec else {
|
|
41
|
+
fatalError("`self` is not a `HybridTTSSpec`! Did you accidentally inherit from `HybridTTSSpec_base` instead of `HybridTTSSpec`?")
|
|
42
|
+
}
|
|
43
|
+
#endif
|
|
44
|
+
if let cxxWrapper = self.cxxWrapper {
|
|
45
|
+
return cxxWrapper
|
|
46
|
+
} else {
|
|
47
|
+
let cxxWrapper = HybridTTSSpec_cxx(self as! HybridTTSSpec)
|
|
48
|
+
self.cxxWrapper = cxxWrapper
|
|
49
|
+
return cxxWrapper
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* A Swift base-protocol representing the TTS HybridObject.
|
|
56
|
+
* Implement this protocol to create Swift-based instances of TTS.
|
|
57
|
+
* ```swift
|
|
58
|
+
* class HybridTTS : HybridTTSSpec {
|
|
59
|
+
* // ...
|
|
60
|
+
* }
|
|
61
|
+
* ```
|
|
62
|
+
*/
|
|
63
|
+
public typealias HybridTTSSpec = HybridTTSSpec_protocol & HybridTTSSpec_base
|