@iternio/react-native-auto-play 0.4.11 → 0.4.12

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.
Files changed (77) hide show
  1. package/README.md +26 -0
  2. package/android/src/main/java/com/margelo/nitro/swe/iternio/reactnativeautoplay/HybridAutoPlay.kt +0 -89
  3. package/android/src/main/java/com/margelo/nitro/swe/iternio/reactnativeautoplay/HybridVoice.kt +97 -0
  4. package/android/src/main/java/com/margelo/nitro/swe/iternio/reactnativeautoplay/VoiceInputManager.kt +286 -20
  5. package/android/src/main/java/com/margelo/nitro/swe/iternio/reactnativeautoplay/utils/ThreadUtil.kt +6 -13
  6. package/ios/hybrid/HybridAutoPlay.swift +2 -47
  7. package/ios/hybrid/HybridVoice.swift +65 -0
  8. package/ios/utils/VoiceInputManager.swift +144 -40
  9. package/lib/HybridAutoPlay.d.ts +2 -0
  10. package/lib/HybridAutoPlay.js +2 -0
  11. package/lib/components/OnAppearedChildRenderer.d.ts +10 -0
  12. package/lib/components/OnAppearedChildRenderer.js +26 -0
  13. package/lib/hooks/useIsAutoPlayFocused.d.ts +7 -0
  14. package/lib/hooks/useIsAutoPlayFocused.js +20 -0
  15. package/lib/hybrid/HybridVoice.d.ts +52 -0
  16. package/lib/hybrid/HybridVoice.js +52 -0
  17. package/lib/hybrid.d.ts +2 -0
  18. package/lib/hybrid.js +2 -0
  19. package/lib/index.d.ts +3 -1
  20. package/lib/index.js +2 -1
  21. package/lib/specs/AutoPlay.nitro.d.ts +0 -29
  22. package/lib/specs/AutomotivePermissionRequestTemplate.d.ts +11 -0
  23. package/lib/specs/AutomotivePermissionRequestTemplate.js +1 -0
  24. package/lib/specs/AutomotivePermissionRequestTemplate.nitro.d.ts +11 -0
  25. package/lib/specs/AutomotivePermissionRequestTemplate.nitro.js +1 -0
  26. package/lib/specs/Voice.nitro.d.ts +11 -0
  27. package/lib/specs/Voice.nitro.js +1 -0
  28. package/lib/templates/AutomotivePermissionRequestTemplate.d.ts +23 -0
  29. package/lib/templates/AutomotivePermissionRequestTemplate.js +18 -0
  30. package/lib/types/Glyphmap.d.ts +4105 -0
  31. package/lib/types/Glyphmap.js +4105 -0
  32. package/lib/types/Voice.d.ts +16 -0
  33. package/lib/types/Voice.js +1 -0
  34. package/nitro.json +10 -0
  35. package/nitrogen/generated/android/ReactNativeAutoPlay+autolinking.cmake +2 -0
  36. package/nitrogen/generated/android/ReactNativeAutoPlayOnLoad.cpp +18 -0
  37. package/nitrogen/generated/android/c++/JFunc_void_VoiceInputChunk.hpp +81 -0
  38. package/nitrogen/generated/android/c++/JHybridAutoPlaySpec.cpp +0 -43
  39. package/nitrogen/generated/android/c++/JHybridAutoPlaySpec.hpp +0 -4
  40. package/nitrogen/generated/android/c++/JHybridVoiceSpec.cpp +104 -0
  41. package/nitrogen/generated/android/c++/JHybridVoiceSpec.hpp +66 -0
  42. package/nitrogen/generated/android/c++/JVoiceInputChunk.hpp +64 -0
  43. package/nitrogen/generated/android/c++/JVoiceInputResult.hpp +64 -0
  44. package/nitrogen/generated/android/kotlin/com/margelo/nitro/swe/iternio/reactnativeautoplay/Func_void_VoiceInputChunk.kt +80 -0
  45. package/nitrogen/generated/android/kotlin/com/margelo/nitro/swe/iternio/reactnativeautoplay/HybridAutoPlaySpec.kt +0 -17
  46. package/nitrogen/generated/android/kotlin/com/margelo/nitro/swe/iternio/reactnativeautoplay/HybridVoiceSpec.kt +72 -0
  47. package/nitrogen/generated/android/kotlin/com/margelo/nitro/swe/iternio/reactnativeautoplay/VoiceInputChunk.kt +56 -0
  48. package/nitrogen/generated/android/kotlin/com/margelo/nitro/swe/iternio/reactnativeautoplay/VoiceInputResult.kt +56 -0
  49. package/nitrogen/generated/ios/ReactNativeAutoPlay-Swift-Cxx-Bridge.cpp +41 -16
  50. package/nitrogen/generated/ios/ReactNativeAutoPlay-Swift-Cxx-Bridge.hpp +201 -126
  51. package/nitrogen/generated/ios/ReactNativeAutoPlay-Swift-Cxx-Umbrella.hpp +11 -0
  52. package/nitrogen/generated/ios/ReactNativeAutoPlayAutolinking.mm +8 -0
  53. package/nitrogen/generated/ios/ReactNativeAutoPlayAutolinking.swift +12 -0
  54. package/nitrogen/generated/ios/c++/HybridAutoPlaySpecSwift.hpp +0 -34
  55. package/nitrogen/generated/ios/c++/HybridVoiceSpecSwift.cpp +11 -0
  56. package/nitrogen/generated/ios/c++/HybridVoiceSpecSwift.hpp +116 -0
  57. package/nitrogen/generated/ios/swift/Func_void_VoiceInputChunk.swift +46 -0
  58. package/nitrogen/generated/ios/swift/{Func_void_std__shared_ptr_ArrayBuffer_.swift → Func_void_VoiceInputResult.swift} +10 -10
  59. package/nitrogen/generated/ios/swift/Func_void_bool.swift +5 -5
  60. package/nitrogen/generated/ios/swift/HybridAutoPlaySpec.swift +0 -4
  61. package/nitrogen/generated/ios/swift/HybridAutoPlaySpec_cxx.swift +0 -82
  62. package/nitrogen/generated/ios/swift/HybridVoiceSpec.swift +58 -0
  63. package/nitrogen/generated/ios/swift/HybridVoiceSpec_cxx.swift +234 -0
  64. package/nitrogen/generated/ios/swift/VoiceInputChunk.swift +60 -0
  65. package/nitrogen/generated/ios/swift/VoiceInputResult.swift +60 -0
  66. package/nitrogen/generated/shared/c++/HybridAutoPlaySpec.cpp +0 -4
  67. package/nitrogen/generated/shared/c++/HybridAutoPlaySpec.hpp +0 -5
  68. package/nitrogen/generated/shared/c++/HybridVoiceSpec.cpp +24 -0
  69. package/nitrogen/generated/shared/c++/HybridVoiceSpec.hpp +73 -0
  70. package/nitrogen/generated/shared/c++/VoiceInputChunk.hpp +89 -0
  71. package/nitrogen/generated/shared/c++/VoiceInputResult.hpp +89 -0
  72. package/package.json +1 -1
  73. package/src/hybrid/HybridVoice.ts +79 -0
  74. package/src/index.ts +3 -1
  75. package/src/specs/AutoPlay.nitro.ts +0 -37
  76. package/src/specs/Voice.nitro.ts +16 -0
  77. package/src/types/Voice.ts +18 -0
@@ -0,0 +1,116 @@
1
+ ///
2
+ /// HybridVoiceSpecSwift.hpp
3
+ /// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
4
+ /// https://github.com/mrousavy/nitro
5
+ /// Copyright © Marc Rousavy @ Margelo
6
+ ///
7
+
8
+ #pragma once
9
+
10
+ #include "HybridVoiceSpec.hpp"
11
+
12
+ // Forward declaration of `HybridVoiceSpec_cxx` to properly resolve imports.
13
+ namespace ReactNativeAutoPlay { class HybridVoiceSpec_cxx; }
14
+
15
+ // Forward declaration of `VoiceInputResult` to properly resolve imports.
16
+ namespace margelo::nitro::swe::iternio::reactnativeautoplay { struct VoiceInputResult; }
17
+ // Forward declaration of `ArrayBufferHolder` to properly resolve imports.
18
+ namespace NitroModules { class ArrayBufferHolder; }
19
+ // Forward declaration of `VoiceInputChunk` to properly resolve imports.
20
+ namespace margelo::nitro::swe::iternio::reactnativeautoplay { struct VoiceInputChunk; }
21
+
22
+ #include <NitroModules/Promise.hpp>
23
+ #include "VoiceInputResult.hpp"
24
+ #include <string>
25
+ #include <optional>
26
+ #include <NitroModules/ArrayBuffer.hpp>
27
+ #include <NitroModules/ArrayBufferHolder.hpp>
28
+ #include "VoiceInputChunk.hpp"
29
+ #include <functional>
30
+
31
+ #include "ReactNativeAutoPlay-Swift-Cxx-Umbrella.hpp"
32
+
33
+ namespace margelo::nitro::swe::iternio::reactnativeautoplay {
34
+
35
+ /**
36
+ * The C++ part of HybridVoiceSpec_cxx.swift.
37
+ *
38
+ * HybridVoiceSpecSwift (C++) accesses HybridVoiceSpec_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, HybridVoiceSpec_cxx can directly inherit from the C++ class HybridVoiceSpec
43
+ * to simplify the whole structure and memory management.
44
+ */
45
+ class HybridVoiceSpecSwift: public virtual HybridVoiceSpec {
46
+ public:
47
+ // Constructor from a Swift instance
48
+ explicit HybridVoiceSpecSwift(const ReactNativeAutoPlay::HybridVoiceSpec_cxx& swiftPart):
49
+ HybridObject(HybridVoiceSpec::TAG),
50
+ _swiftPart(swiftPart) { }
51
+
52
+ public:
53
+ // Get the Swift part
54
+ inline ReactNativeAutoPlay::HybridVoiceSpec_cxx& getSwiftPart() noexcept {
55
+ return _swiftPart;
56
+ }
57
+
58
+ public:
59
+ inline size_t getExternalMemorySize() noexcept override {
60
+ return _swiftPart.getMemorySize();
61
+ }
62
+ bool equals(const std::shared_ptr<HybridObject>& other) override {
63
+ if (auto otherCast = std::dynamic_pointer_cast<HybridVoiceSpecSwift>(other)) {
64
+ return _swiftPart.equals(otherCast->_swiftPart);
65
+ }
66
+ return false;
67
+ }
68
+ void dispose() noexcept override {
69
+ _swiftPart.dispose();
70
+ }
71
+ std::string toString() override {
72
+ return _swiftPart.toString();
73
+ }
74
+
75
+ public:
76
+ // Properties
77
+
78
+
79
+ public:
80
+ // Methods
81
+ inline bool hasVoiceInputPermission() override {
82
+ auto __result = _swiftPart.hasVoiceInputPermission();
83
+ if (__result.hasError()) [[unlikely]] {
84
+ std::rethrow_exception(__result.error());
85
+ }
86
+ auto __value = std::move(__result.value());
87
+ return __value;
88
+ }
89
+ inline std::shared_ptr<Promise<bool>> requestVoiceInputPermission() override {
90
+ auto __result = _swiftPart.requestVoiceInputPermission();
91
+ if (__result.hasError()) [[unlikely]] {
92
+ std::rethrow_exception(__result.error());
93
+ }
94
+ auto __value = std::move(__result.value());
95
+ return __value;
96
+ }
97
+ inline std::shared_ptr<Promise<VoiceInputResult>> startVoiceInput(std::optional<double> silenceThresholdMs, std::optional<double> maxDurationMs, const std::optional<std::string>& listeningText, std::optional<bool> preferSpeechToText, const std::optional<std::function<void(const VoiceInputChunk& /* chunk */)>>& onChunk, const std::optional<std::string>& language) override {
98
+ auto __result = _swiftPart.startVoiceInput(silenceThresholdMs, maxDurationMs, listeningText, preferSpeechToText, onChunk, language);
99
+ if (__result.hasError()) [[unlikely]] {
100
+ std::rethrow_exception(__result.error());
101
+ }
102
+ auto __value = std::move(__result.value());
103
+ return __value;
104
+ }
105
+ inline void stopVoiceInput() override {
106
+ auto __result = _swiftPart.stopVoiceInput();
107
+ if (__result.hasError()) [[unlikely]] {
108
+ std::rethrow_exception(__result.error());
109
+ }
110
+ }
111
+
112
+ private:
113
+ ReactNativeAutoPlay::HybridVoiceSpec_cxx _swiftPart;
114
+ };
115
+
116
+ } // namespace margelo::nitro::swe::iternio::reactnativeautoplay
@@ -0,0 +1,46 @@
1
+ ///
2
+ /// Func_void_VoiceInputChunk.swift
3
+ /// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
4
+ /// https://github.com/mrousavy/nitro
5
+ /// Copyright © Marc Rousavy @ Margelo
6
+ ///
7
+
8
+ import NitroModules
9
+
10
+ /**
11
+ * Wraps a Swift `(_ chunk: VoiceInputChunk) -> Void` as a class.
12
+ * This class can be used from C++, e.g. to wrap the Swift closure as a `std::function`.
13
+ */
14
+ public final class Func_void_VoiceInputChunk {
15
+ public typealias bridge = margelo.nitro.swe.iternio.reactnativeautoplay.bridge.swift
16
+
17
+ private let closure: (_ chunk: VoiceInputChunk) -> Void
18
+
19
+ public init(_ closure: @escaping (_ chunk: VoiceInputChunk) -> Void) {
20
+ self.closure = closure
21
+ }
22
+
23
+ @inline(__always)
24
+ public func call(chunk: VoiceInputChunk) -> Void {
25
+ self.closure(chunk)
26
+ }
27
+
28
+ /**
29
+ * Casts this instance to a retained unsafe raw pointer.
30
+ * This acquires one additional strong reference on the object!
31
+ */
32
+ @inline(__always)
33
+ public func toUnsafe() -> UnsafeMutableRawPointer {
34
+ return Unmanaged.passRetained(self).toOpaque()
35
+ }
36
+
37
+ /**
38
+ * Casts an unsafe pointer to a `Func_void_VoiceInputChunk`.
39
+ * The pointer has to be a retained opaque `Unmanaged<Func_void_VoiceInputChunk>`.
40
+ * This removes one strong reference from the object!
41
+ */
42
+ @inline(__always)
43
+ public static func fromUnsafe(_ pointer: UnsafeMutableRawPointer) -> Func_void_VoiceInputChunk {
44
+ return Unmanaged<Func_void_VoiceInputChunk>.fromOpaque(pointer).takeRetainedValue()
45
+ }
46
+ }
@@ -1,5 +1,5 @@
1
1
  ///
2
- /// Func_void_std__shared_ptr_ArrayBuffer_.swift
2
+ /// Func_void_VoiceInputResult.swift
3
3
  /// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
4
4
  /// https://github.com/mrousavy/nitro
5
5
  /// Copyright © Marc Rousavy @ Margelo
@@ -8,20 +8,20 @@
8
8
  import NitroModules
9
9
 
10
10
  /**
11
- * Wraps a Swift `(_ value: ArrayBuffer) -> Void` as a class.
11
+ * Wraps a Swift `(_ value: VoiceInputResult) -> Void` as a class.
12
12
  * This class can be used from C++, e.g. to wrap the Swift closure as a `std::function`.
13
13
  */
14
- public final class Func_void_std__shared_ptr_ArrayBuffer_ {
14
+ public final class Func_void_VoiceInputResult {
15
15
  public typealias bridge = margelo.nitro.swe.iternio.reactnativeautoplay.bridge.swift
16
16
 
17
- private let closure: (_ value: ArrayBuffer) -> Void
17
+ private let closure: (_ value: VoiceInputResult) -> Void
18
18
 
19
- public init(_ closure: @escaping (_ value: ArrayBuffer) -> Void) {
19
+ public init(_ closure: @escaping (_ value: VoiceInputResult) -> Void) {
20
20
  self.closure = closure
21
21
  }
22
22
 
23
23
  @inline(__always)
24
- public func call(value: ArrayBuffer) -> Void {
24
+ public func call(value: VoiceInputResult) -> Void {
25
25
  self.closure(value)
26
26
  }
27
27
 
@@ -35,12 +35,12 @@ public final class Func_void_std__shared_ptr_ArrayBuffer_ {
35
35
  }
36
36
 
37
37
  /**
38
- * Casts an unsafe pointer to a `Func_void_std__shared_ptr_ArrayBuffer_`.
39
- * The pointer has to be a retained opaque `Unmanaged<Func_void_std__shared_ptr_ArrayBuffer_>`.
38
+ * Casts an unsafe pointer to a `Func_void_VoiceInputResult`.
39
+ * The pointer has to be a retained opaque `Unmanaged<Func_void_VoiceInputResult>`.
40
40
  * This removes one strong reference from the object!
41
41
  */
42
42
  @inline(__always)
43
- public static func fromUnsafe(_ pointer: UnsafeMutableRawPointer) -> Func_void_std__shared_ptr_ArrayBuffer_ {
44
- return Unmanaged<Func_void_std__shared_ptr_ArrayBuffer_>.fromOpaque(pointer).takeRetainedValue()
43
+ public static func fromUnsafe(_ pointer: UnsafeMutableRawPointer) -> Func_void_VoiceInputResult {
44
+ return Unmanaged<Func_void_VoiceInputResult>.fromOpaque(pointer).takeRetainedValue()
45
45
  }
46
46
  }
@@ -8,21 +8,21 @@
8
8
  import NitroModules
9
9
 
10
10
  /**
11
- * Wraps a Swift `(_ isPanningInterfaceVisible: Bool) -> Void` as a class.
11
+ * Wraps a Swift `(_ value: Bool) -> Void` as a class.
12
12
  * This class can be used from C++, e.g. to wrap the Swift closure as a `std::function`.
13
13
  */
14
14
  public final class Func_void_bool {
15
15
  public typealias bridge = margelo.nitro.swe.iternio.reactnativeautoplay.bridge.swift
16
16
 
17
- private let closure: (_ isPanningInterfaceVisible: Bool) -> Void
17
+ private let closure: (_ value: Bool) -> Void
18
18
 
19
- public init(_ closure: @escaping (_ isPanningInterfaceVisible: Bool) -> Void) {
19
+ public init(_ closure: @escaping (_ value: Bool) -> Void) {
20
20
  self.closure = closure
21
21
  }
22
22
 
23
23
  @inline(__always)
24
- public func call(isPanningInterfaceVisible: Bool) -> Void {
25
- self.closure(isPanningInterfaceVisible)
24
+ public func call(value: Bool) -> Void {
25
+ self.closure(value)
26
26
  }
27
27
 
28
28
  /**
@@ -16,10 +16,6 @@ public protocol HybridAutoPlaySpec_protocol: HybridObject {
16
16
  func addListener(eventType: EventName, callback: @escaping () -> Void) throws -> () -> Void
17
17
  func addListenerRenderState(moduleName: String, callback: @escaping (_ payload: VisibilityState) -> Void) throws -> () -> Void
18
18
  func addListenerVoiceInput(callback: @escaping (_ coordinates: Location?, _ query: String?) -> Void) throws -> () -> Void
19
- func hasVoiceInputPermission() throws -> Bool
20
- func requestVoiceInputPermission() throws -> Promise<Bool>
21
- func startVoiceInput(silenceThresholdMs: Double?, maxDurationMs: Double?, listeningText: String?) throws -> Promise<ArrayBuffer>
22
- func stopVoiceInput() throws -> Void
23
19
  func setRootTemplate(templateId: String) throws -> Promise<Void>
24
20
  func pushTemplate(templateId: String) throws -> Promise<Void>
25
21
  func popTemplate(animate: Bool?) throws -> Promise<Void>
@@ -196,88 +196,6 @@ open class HybridAutoPlaySpec_cxx {
196
196
  }
197
197
  }
198
198
 
199
- @inline(__always)
200
- public final func hasVoiceInputPermission() -> bridge.Result_bool_ {
201
- do {
202
- let __result = try self.__implementation.hasVoiceInputPermission()
203
- let __resultCpp = __result
204
- return bridge.create_Result_bool_(__resultCpp)
205
- } catch (let __error) {
206
- let __exceptionPtr = __error.toCpp()
207
- return bridge.create_Result_bool_(__exceptionPtr)
208
- }
209
- }
210
-
211
- @inline(__always)
212
- public final func requestVoiceInputPermission() -> bridge.Result_std__shared_ptr_Promise_bool___ {
213
- do {
214
- let __result = try self.__implementation.requestVoiceInputPermission()
215
- let __resultCpp = { () -> bridge.std__shared_ptr_Promise_bool__ in
216
- let __promise = bridge.create_std__shared_ptr_Promise_bool__()
217
- let __promiseHolder = bridge.wrap_std__shared_ptr_Promise_bool__(__promise)
218
- __result
219
- .then({ __result in __promiseHolder.resolve(__result) })
220
- .catch({ __error in __promiseHolder.reject(__error.toCpp()) })
221
- return __promise
222
- }()
223
- return bridge.create_Result_std__shared_ptr_Promise_bool___(__resultCpp)
224
- } catch (let __error) {
225
- let __exceptionPtr = __error.toCpp()
226
- return bridge.create_Result_std__shared_ptr_Promise_bool___(__exceptionPtr)
227
- }
228
- }
229
-
230
- @inline(__always)
231
- public final func startVoiceInput(silenceThresholdMs: bridge.std__optional_double_, maxDurationMs: bridge.std__optional_double_, listeningText: bridge.std__optional_std__string_) -> bridge.Result_std__shared_ptr_Promise_std__shared_ptr_ArrayBuffer____ {
232
- do {
233
- let __result = try self.__implementation.startVoiceInput(silenceThresholdMs: { () -> Double? in
234
- if bridge.has_value_std__optional_double_(silenceThresholdMs) {
235
- let __unwrapped = bridge.get_std__optional_double_(silenceThresholdMs)
236
- return __unwrapped
237
- } else {
238
- return nil
239
- }
240
- }(), maxDurationMs: { () -> Double? in
241
- if bridge.has_value_std__optional_double_(maxDurationMs) {
242
- let __unwrapped = bridge.get_std__optional_double_(maxDurationMs)
243
- return __unwrapped
244
- } else {
245
- return nil
246
- }
247
- }(), listeningText: { () -> String? in
248
- if bridge.has_value_std__optional_std__string_(listeningText) {
249
- let __unwrapped = bridge.get_std__optional_std__string_(listeningText)
250
- return String(__unwrapped)
251
- } else {
252
- return nil
253
- }
254
- }())
255
- let __resultCpp = { () -> bridge.std__shared_ptr_Promise_std__shared_ptr_ArrayBuffer___ in
256
- let __promise = bridge.create_std__shared_ptr_Promise_std__shared_ptr_ArrayBuffer___()
257
- let __promiseHolder = bridge.wrap_std__shared_ptr_Promise_std__shared_ptr_ArrayBuffer___(__promise)
258
- __result
259
- .then({ __result in __promiseHolder.resolve(__result.getArrayBuffer()) })
260
- .catch({ __error in __promiseHolder.reject(__error.toCpp()) })
261
- return __promise
262
- }()
263
- return bridge.create_Result_std__shared_ptr_Promise_std__shared_ptr_ArrayBuffer____(__resultCpp)
264
- } catch (let __error) {
265
- let __exceptionPtr = __error.toCpp()
266
- return bridge.create_Result_std__shared_ptr_Promise_std__shared_ptr_ArrayBuffer____(__exceptionPtr)
267
- }
268
- }
269
-
270
- @inline(__always)
271
- public final func stopVoiceInput() -> bridge.Result_void_ {
272
- do {
273
- try self.__implementation.stopVoiceInput()
274
- return bridge.create_Result_void_()
275
- } catch (let __error) {
276
- let __exceptionPtr = __error.toCpp()
277
- return bridge.create_Result_void_(__exceptionPtr)
278
- }
279
- }
280
-
281
199
  @inline(__always)
282
200
  public final func setRootTemplate(templateId: std.string) -> bridge.Result_std__shared_ptr_Promise_void___ {
283
201
  do {
@@ -0,0 +1,58 @@
1
+ ///
2
+ /// HybridVoiceSpec.swift
3
+ /// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
4
+ /// https://github.com/mrousavy/nitro
5
+ /// Copyright © Marc Rousavy @ Margelo
6
+ ///
7
+
8
+ import NitroModules
9
+
10
+ /// See ``HybridVoiceSpec``
11
+ public protocol HybridVoiceSpec_protocol: HybridObject {
12
+ // Properties
13
+
14
+
15
+ // Methods
16
+ func hasVoiceInputPermission() throws -> Bool
17
+ func requestVoiceInputPermission() throws -> Promise<Bool>
18
+ func startVoiceInput(silenceThresholdMs: Double?, maxDurationMs: Double?, listeningText: String?, preferSpeechToText: Bool?, onChunk: ((_ chunk: VoiceInputChunk) -> Void)?, language: String?) throws -> Promise<VoiceInputResult>
19
+ func stopVoiceInput() throws -> Void
20
+ }
21
+
22
+ public extension HybridVoiceSpec_protocol {
23
+ /// Default implementation of ``HybridObject.toString``
24
+ func toString() -> String {
25
+ return "[HybridObject Voice]"
26
+ }
27
+ }
28
+
29
+ /// See ``HybridVoiceSpec``
30
+ open class HybridVoiceSpec_base {
31
+ private weak var cxxWrapper: HybridVoiceSpec_cxx? = nil
32
+ public init() { }
33
+ public func getCxxWrapper() -> HybridVoiceSpec_cxx {
34
+ #if DEBUG
35
+ guard self is any HybridVoiceSpec else {
36
+ fatalError("`self` is not a `HybridVoiceSpec`! Did you accidentally inherit from `HybridVoiceSpec_base` instead of `HybridVoiceSpec`?")
37
+ }
38
+ #endif
39
+ if let cxxWrapper = self.cxxWrapper {
40
+ return cxxWrapper
41
+ } else {
42
+ let cxxWrapper = HybridVoiceSpec_cxx(self as! any HybridVoiceSpec)
43
+ self.cxxWrapper = cxxWrapper
44
+ return cxxWrapper
45
+ }
46
+ }
47
+ }
48
+
49
+ /**
50
+ * A Swift base-protocol representing the Voice HybridObject.
51
+ * Implement this protocol to create Swift-based instances of Voice.
52
+ * ```swift
53
+ * class HybridVoice : HybridVoiceSpec {
54
+ * // ...
55
+ * }
56
+ * ```
57
+ */
58
+ public typealias HybridVoiceSpec = HybridVoiceSpec_protocol & HybridVoiceSpec_base
@@ -0,0 +1,234 @@
1
+ ///
2
+ /// HybridVoiceSpec_cxx.swift
3
+ /// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
4
+ /// https://github.com/mrousavy/nitro
5
+ /// Copyright © Marc Rousavy @ Margelo
6
+ ///
7
+
8
+ import NitroModules
9
+
10
+ /**
11
+ * A class implementation that bridges HybridVoiceSpec over to C++.
12
+ * In C++, we cannot use Swift protocols - so we need to wrap it in a class to make it strongly defined.
13
+ *
14
+ * Also, some Swift types need to be bridged with special handling:
15
+ * - Enums need to be wrapped in Structs, otherwise they cannot be accessed bi-directionally (Swift bug: https://github.com/swiftlang/swift/issues/75330)
16
+ * - Other HybridObjects need to be wrapped/unwrapped from the Swift TCxx wrapper
17
+ * - Throwing methods need to be wrapped with a Result<T, Error> type, as exceptions cannot be propagated to C++
18
+ */
19
+ open class HybridVoiceSpec_cxx {
20
+ /**
21
+ * The Swift <> C++ bridge's namespace (`margelo::nitro::swe::iternio::reactnativeautoplay::bridge::swift`)
22
+ * from `ReactNativeAutoPlay-Swift-Cxx-Bridge.hpp`.
23
+ * This contains specialized C++ templates, and C++ helper functions that can be accessed from Swift.
24
+ */
25
+ public typealias bridge = margelo.nitro.swe.iternio.reactnativeautoplay.bridge.swift
26
+
27
+ /**
28
+ * Holds an instance of the `HybridVoiceSpec` Swift protocol.
29
+ */
30
+ private var __implementation: any HybridVoiceSpec
31
+
32
+ /**
33
+ * Holds a weak pointer to the C++ class that wraps the Swift class.
34
+ */
35
+ private var __cxxPart: bridge.std__weak_ptr_HybridVoiceSpec_
36
+
37
+ /**
38
+ * Create a new `HybridVoiceSpec_cxx` that wraps the given `HybridVoiceSpec`.
39
+ * All properties and methods bridge to C++ types.
40
+ */
41
+ public init(_ implementation: any HybridVoiceSpec) {
42
+ self.__implementation = implementation
43
+ self.__cxxPart = .init()
44
+ /* no base class */
45
+ }
46
+
47
+ /**
48
+ * Get the actual `HybridVoiceSpec` instance this class wraps.
49
+ */
50
+ @inline(__always)
51
+ public func getHybridVoiceSpec() -> any HybridVoiceSpec {
52
+ return __implementation
53
+ }
54
+
55
+ /**
56
+ * Casts this instance to a retained unsafe raw pointer.
57
+ * This acquires one additional strong reference on the object!
58
+ */
59
+ public func toUnsafe() -> UnsafeMutableRawPointer {
60
+ return Unmanaged.passRetained(self).toOpaque()
61
+ }
62
+
63
+ /**
64
+ * Casts an unsafe pointer to a `HybridVoiceSpec_cxx`.
65
+ * The pointer has to be a retained opaque `Unmanaged<HybridVoiceSpec_cxx>`.
66
+ * This removes one strong reference from the object!
67
+ */
68
+ public class func fromUnsafe(_ pointer: UnsafeMutableRawPointer) -> HybridVoiceSpec_cxx {
69
+ return Unmanaged<HybridVoiceSpec_cxx>.fromOpaque(pointer).takeRetainedValue()
70
+ }
71
+
72
+ /**
73
+ * Gets (or creates) the C++ part of this Hybrid Object.
74
+ * The C++ part is a `std::shared_ptr<HybridVoiceSpec>`.
75
+ */
76
+ public func getCxxPart() -> bridge.std__shared_ptr_HybridVoiceSpec_ {
77
+ let cachedCxxPart = self.__cxxPart.lock()
78
+ if Bool(fromCxx: cachedCxxPart) {
79
+ return cachedCxxPart
80
+ } else {
81
+ let newCxxPart = bridge.create_std__shared_ptr_HybridVoiceSpec_(self.toUnsafe())
82
+ __cxxPart = bridge.weakify_std__shared_ptr_HybridVoiceSpec_(newCxxPart)
83
+ return newCxxPart
84
+ }
85
+ }
86
+
87
+
88
+
89
+ /**
90
+ * Get the memory size of the Swift class (plus size of any other allocations)
91
+ * so the JS VM can properly track it and garbage-collect the JS object if needed.
92
+ */
93
+ @inline(__always)
94
+ public var memorySize: Int {
95
+ return MemoryHelper.getSizeOf(self.__implementation) + self.__implementation.memorySize
96
+ }
97
+
98
+ /**
99
+ * Compares this object with the given [other] object for reference equality.
100
+ */
101
+ @inline(__always)
102
+ public func equals(other: HybridVoiceSpec_cxx) -> Bool {
103
+ return self.__implementation === other.__implementation
104
+ }
105
+
106
+ /**
107
+ * Call dispose() on the Swift class.
108
+ * This _may_ be called manually from JS.
109
+ */
110
+ @inline(__always)
111
+ public func dispose() {
112
+ self.__implementation.dispose()
113
+ }
114
+
115
+ /**
116
+ * Call toString() on the Swift class.
117
+ */
118
+ @inline(__always)
119
+ public func toString() -> String {
120
+ return self.__implementation.toString()
121
+ }
122
+
123
+ // Properties
124
+
125
+
126
+ // Methods
127
+ @inline(__always)
128
+ public final func hasVoiceInputPermission() -> bridge.Result_bool_ {
129
+ do {
130
+ let __result = try self.__implementation.hasVoiceInputPermission()
131
+ let __resultCpp = __result
132
+ return bridge.create_Result_bool_(__resultCpp)
133
+ } catch (let __error) {
134
+ let __exceptionPtr = __error.toCpp()
135
+ return bridge.create_Result_bool_(__exceptionPtr)
136
+ }
137
+ }
138
+
139
+ @inline(__always)
140
+ public final func requestVoiceInputPermission() -> bridge.Result_std__shared_ptr_Promise_bool___ {
141
+ do {
142
+ let __result = try self.__implementation.requestVoiceInputPermission()
143
+ let __resultCpp = { () -> bridge.std__shared_ptr_Promise_bool__ in
144
+ let __promise = bridge.create_std__shared_ptr_Promise_bool__()
145
+ let __promiseHolder = bridge.wrap_std__shared_ptr_Promise_bool__(__promise)
146
+ __result
147
+ .then({ __result in __promiseHolder.resolve(__result) })
148
+ .catch({ __error in __promiseHolder.reject(__error.toCpp()) })
149
+ return __promise
150
+ }()
151
+ return bridge.create_Result_std__shared_ptr_Promise_bool___(__resultCpp)
152
+ } catch (let __error) {
153
+ let __exceptionPtr = __error.toCpp()
154
+ return bridge.create_Result_std__shared_ptr_Promise_bool___(__exceptionPtr)
155
+ }
156
+ }
157
+
158
+ @inline(__always)
159
+ public final func startVoiceInput(silenceThresholdMs: bridge.std__optional_double_, maxDurationMs: bridge.std__optional_double_, listeningText: bridge.std__optional_std__string_, preferSpeechToText: bridge.std__optional_bool_, onChunk: bridge.std__optional_std__function_void_const_VoiceInputChunk_____chunk______, language: bridge.std__optional_std__string_) -> bridge.Result_std__shared_ptr_Promise_VoiceInputResult___ {
160
+ do {
161
+ let __result = try self.__implementation.startVoiceInput(silenceThresholdMs: { () -> Double? in
162
+ if bridge.has_value_std__optional_double_(silenceThresholdMs) {
163
+ let __unwrapped = bridge.get_std__optional_double_(silenceThresholdMs)
164
+ return __unwrapped
165
+ } else {
166
+ return nil
167
+ }
168
+ }(), maxDurationMs: { () -> Double? in
169
+ if bridge.has_value_std__optional_double_(maxDurationMs) {
170
+ let __unwrapped = bridge.get_std__optional_double_(maxDurationMs)
171
+ return __unwrapped
172
+ } else {
173
+ return nil
174
+ }
175
+ }(), listeningText: { () -> String? in
176
+ if bridge.has_value_std__optional_std__string_(listeningText) {
177
+ let __unwrapped = bridge.get_std__optional_std__string_(listeningText)
178
+ return String(__unwrapped)
179
+ } else {
180
+ return nil
181
+ }
182
+ }(), preferSpeechToText: { () -> Bool? in
183
+ if bridge.has_value_std__optional_bool_(preferSpeechToText) {
184
+ let __unwrapped = bridge.get_std__optional_bool_(preferSpeechToText)
185
+ return __unwrapped
186
+ } else {
187
+ return nil
188
+ }
189
+ }(), onChunk: { () -> ((_ chunk: VoiceInputChunk) -> Void)? in
190
+ if bridge.has_value_std__optional_std__function_void_const_VoiceInputChunk_____chunk______(onChunk) {
191
+ let __unwrapped = bridge.get_std__optional_std__function_void_const_VoiceInputChunk_____chunk______(onChunk)
192
+ return { () -> (VoiceInputChunk) -> Void in
193
+ let __wrappedFunction = bridge.wrap_Func_void_VoiceInputChunk(__unwrapped)
194
+ return { (__chunk: VoiceInputChunk) -> Void in
195
+ __wrappedFunction.call(__chunk)
196
+ }
197
+ }()
198
+ } else {
199
+ return nil
200
+ }
201
+ }(), language: { () -> String? in
202
+ if bridge.has_value_std__optional_std__string_(language) {
203
+ let __unwrapped = bridge.get_std__optional_std__string_(language)
204
+ return String(__unwrapped)
205
+ } else {
206
+ return nil
207
+ }
208
+ }())
209
+ let __resultCpp = { () -> bridge.std__shared_ptr_Promise_VoiceInputResult__ in
210
+ let __promise = bridge.create_std__shared_ptr_Promise_VoiceInputResult__()
211
+ let __promiseHolder = bridge.wrap_std__shared_ptr_Promise_VoiceInputResult__(__promise)
212
+ __result
213
+ .then({ __result in __promiseHolder.resolve(__result) })
214
+ .catch({ __error in __promiseHolder.reject(__error.toCpp()) })
215
+ return __promise
216
+ }()
217
+ return bridge.create_Result_std__shared_ptr_Promise_VoiceInputResult___(__resultCpp)
218
+ } catch (let __error) {
219
+ let __exceptionPtr = __error.toCpp()
220
+ return bridge.create_Result_std__shared_ptr_Promise_VoiceInputResult___(__exceptionPtr)
221
+ }
222
+ }
223
+
224
+ @inline(__always)
225
+ public final func stopVoiceInput() -> bridge.Result_void_ {
226
+ do {
227
+ try self.__implementation.stopVoiceInput()
228
+ return bridge.create_Result_void_()
229
+ } catch (let __error) {
230
+ let __exceptionPtr = __error.toCpp()
231
+ return bridge.create_Result_void_(__exceptionPtr)
232
+ }
233
+ }
234
+ }