@iternio/react-native-auto-play 0.4.1 → 0.4.2

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 (60) hide show
  1. package/android/src/main/java/com/margelo/nitro/swe/iternio/reactnativeautoplay/HybridAutoPlay.kt +0 -89
  2. package/android/src/main/java/com/margelo/nitro/swe/iternio/reactnativeautoplay/HybridVoice.kt +95 -0
  3. package/android/src/main/java/com/margelo/nitro/swe/iternio/reactnativeautoplay/VoiceInputManager.kt +276 -20
  4. package/android/src/main/java/com/margelo/nitro/swe/iternio/reactnativeautoplay/utils/ThreadUtil.kt +6 -13
  5. package/ios/hybrid/HybridAutoPlay.swift +2 -47
  6. package/ios/hybrid/HybridVoice.swift +63 -0
  7. package/ios/utils/VoiceInputManager.swift +141 -40
  8. package/lib/hybrid/HybridVoice.d.ts +12 -0
  9. package/lib/hybrid/HybridVoice.js +13 -0
  10. package/lib/index.d.ts +3 -0
  11. package/lib/index.js +2 -0
  12. package/lib/specs/AutoPlay.nitro.d.ts +0 -29
  13. package/lib/specs/Voice.nitro.d.ts +51 -0
  14. package/lib/specs/Voice.nitro.js +1 -0
  15. package/lib/types/Voice.d.ts +15 -0
  16. package/lib/types/Voice.js +1 -0
  17. package/nitro.json +10 -0
  18. package/nitrogen/generated/android/ReactNativeAutoPlay+autolinking.cmake +2 -0
  19. package/nitrogen/generated/android/ReactNativeAutoPlayOnLoad.cpp +18 -0
  20. package/nitrogen/generated/android/c++/JFunc_void_VoiceInputChunk.hpp +81 -0
  21. package/nitrogen/generated/android/c++/JHybridAutoPlaySpec.cpp +0 -43
  22. package/nitrogen/generated/android/c++/JHybridAutoPlaySpec.hpp +0 -4
  23. package/nitrogen/generated/android/c++/JHybridVoiceSpec.cpp +104 -0
  24. package/nitrogen/generated/android/c++/JHybridVoiceSpec.hpp +66 -0
  25. package/nitrogen/generated/android/c++/JVoiceInputChunk.hpp +64 -0
  26. package/nitrogen/generated/android/c++/JVoiceInputResult.hpp +64 -0
  27. package/nitrogen/generated/android/kotlin/com/margelo/nitro/swe/iternio/reactnativeautoplay/Func_void_VoiceInputChunk.kt +80 -0
  28. package/nitrogen/generated/android/kotlin/com/margelo/nitro/swe/iternio/reactnativeautoplay/HybridAutoPlaySpec.kt +0 -17
  29. package/nitrogen/generated/android/kotlin/com/margelo/nitro/swe/iternio/reactnativeautoplay/HybridVoiceSpec.kt +72 -0
  30. package/nitrogen/generated/android/kotlin/com/margelo/nitro/swe/iternio/reactnativeautoplay/VoiceInputChunk.kt +41 -0
  31. package/nitrogen/generated/android/kotlin/com/margelo/nitro/swe/iternio/reactnativeautoplay/VoiceInputResult.kt +41 -0
  32. package/nitrogen/generated/ios/ReactNativeAutoPlay-Swift-Cxx-Bridge.cpp +41 -16
  33. package/nitrogen/generated/ios/ReactNativeAutoPlay-Swift-Cxx-Bridge.hpp +201 -126
  34. package/nitrogen/generated/ios/ReactNativeAutoPlay-Swift-Cxx-Umbrella.hpp +11 -0
  35. package/nitrogen/generated/ios/ReactNativeAutoPlayAutolinking.mm +8 -0
  36. package/nitrogen/generated/ios/ReactNativeAutoPlayAutolinking.swift +12 -0
  37. package/nitrogen/generated/ios/c++/HybridAutoPlaySpecSwift.hpp +0 -34
  38. package/nitrogen/generated/ios/c++/HybridVoiceSpecSwift.cpp +11 -0
  39. package/nitrogen/generated/ios/c++/HybridVoiceSpecSwift.hpp +116 -0
  40. package/nitrogen/generated/ios/swift/Func_void_VoiceInputChunk.swift +46 -0
  41. package/nitrogen/generated/ios/swift/{Func_void_std__shared_ptr_ArrayBuffer_.swift → Func_void_VoiceInputResult.swift} +10 -10
  42. package/nitrogen/generated/ios/swift/Func_void_bool.swift +5 -5
  43. package/nitrogen/generated/ios/swift/HybridAutoPlaySpec.swift +0 -4
  44. package/nitrogen/generated/ios/swift/HybridAutoPlaySpec_cxx.swift +0 -82
  45. package/nitrogen/generated/ios/swift/HybridVoiceSpec.swift +58 -0
  46. package/nitrogen/generated/ios/swift/HybridVoiceSpec_cxx.swift +227 -0
  47. package/nitrogen/generated/ios/swift/VoiceInputChunk.swift +60 -0
  48. package/nitrogen/generated/ios/swift/VoiceInputResult.swift +60 -0
  49. package/nitrogen/generated/shared/c++/HybridAutoPlaySpec.cpp +0 -4
  50. package/nitrogen/generated/shared/c++/HybridAutoPlaySpec.hpp +0 -5
  51. package/nitrogen/generated/shared/c++/HybridVoiceSpec.cpp +24 -0
  52. package/nitrogen/generated/shared/c++/HybridVoiceSpec.hpp +73 -0
  53. package/nitrogen/generated/shared/c++/VoiceInputChunk.hpp +89 -0
  54. package/nitrogen/generated/shared/c++/VoiceInputResult.hpp +89 -0
  55. package/package.json +1 -1
  56. package/src/hybrid/HybridVoice.ts +30 -0
  57. package/src/index.ts +3 -0
  58. package/src/specs/AutoPlay.nitro.ts +0 -37
  59. package/src/specs/Voice.nitro.ts +58 -0
  60. package/src/types/Voice.ts +17 -0
@@ -0,0 +1,227 @@
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______) -> 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
+ }())
202
+ let __resultCpp = { () -> bridge.std__shared_ptr_Promise_VoiceInputResult__ in
203
+ let __promise = bridge.create_std__shared_ptr_Promise_VoiceInputResult__()
204
+ let __promiseHolder = bridge.wrap_std__shared_ptr_Promise_VoiceInputResult__(__promise)
205
+ __result
206
+ .then({ __result in __promiseHolder.resolve(__result) })
207
+ .catch({ __error in __promiseHolder.reject(__error.toCpp()) })
208
+ return __promise
209
+ }()
210
+ return bridge.create_Result_std__shared_ptr_Promise_VoiceInputResult___(__resultCpp)
211
+ } catch (let __error) {
212
+ let __exceptionPtr = __error.toCpp()
213
+ return bridge.create_Result_std__shared_ptr_Promise_VoiceInputResult___(__exceptionPtr)
214
+ }
215
+ }
216
+
217
+ @inline(__always)
218
+ public final func stopVoiceInput() -> bridge.Result_void_ {
219
+ do {
220
+ try self.__implementation.stopVoiceInput()
221
+ return bridge.create_Result_void_()
222
+ } catch (let __error) {
223
+ let __exceptionPtr = __error.toCpp()
224
+ return bridge.create_Result_void_(__exceptionPtr)
225
+ }
226
+ }
227
+ }
@@ -0,0 +1,60 @@
1
+ ///
2
+ /// 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
+ * Represents an instance of `VoiceInputChunk`, backed by a C++ struct.
12
+ */
13
+ public typealias VoiceInputChunk = margelo.nitro.swe.iternio.reactnativeautoplay.VoiceInputChunk
14
+
15
+ public extension VoiceInputChunk {
16
+ private typealias bridge = margelo.nitro.swe.iternio.reactnativeautoplay.bridge.swift
17
+
18
+ /**
19
+ * Create a new instance of `VoiceInputChunk`.
20
+ */
21
+ init(partial: String?, audio: ArrayBuffer?) {
22
+ self.init({ () -> bridge.std__optional_std__string_ in
23
+ if let __unwrappedValue = partial {
24
+ return bridge.create_std__optional_std__string_(std.string(__unwrappedValue))
25
+ } else {
26
+ return .init()
27
+ }
28
+ }(), { () -> bridge.std__optional_std__shared_ptr_ArrayBuffer__ in
29
+ if let __unwrappedValue = audio {
30
+ return bridge.create_std__optional_std__shared_ptr_ArrayBuffer__(__unwrappedValue.getArrayBuffer())
31
+ } else {
32
+ return .init()
33
+ }
34
+ }())
35
+ }
36
+
37
+ @inline(__always)
38
+ var partial: String? {
39
+ return { () -> String? in
40
+ if bridge.has_value_std__optional_std__string_(self.__partial) {
41
+ let __unwrapped = bridge.get_std__optional_std__string_(self.__partial)
42
+ return String(__unwrapped)
43
+ } else {
44
+ return nil
45
+ }
46
+ }()
47
+ }
48
+
49
+ @inline(__always)
50
+ var audio: ArrayBuffer? {
51
+ return { () -> ArrayBuffer? in
52
+ if bridge.has_value_std__optional_std__shared_ptr_ArrayBuffer__(self.__audio) {
53
+ let __unwrapped = bridge.get_std__optional_std__shared_ptr_ArrayBuffer__(self.__audio)
54
+ return ArrayBuffer(__unwrapped)
55
+ } else {
56
+ return nil
57
+ }
58
+ }()
59
+ }
60
+ }
@@ -0,0 +1,60 @@
1
+ ///
2
+ /// VoiceInputResult.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
+ * Represents an instance of `VoiceInputResult`, backed by a C++ struct.
12
+ */
13
+ public typealias VoiceInputResult = margelo.nitro.swe.iternio.reactnativeautoplay.VoiceInputResult
14
+
15
+ public extension VoiceInputResult {
16
+ private typealias bridge = margelo.nitro.swe.iternio.reactnativeautoplay.bridge.swift
17
+
18
+ /**
19
+ * Create a new instance of `VoiceInputResult`.
20
+ */
21
+ init(transcription: String?, audio: ArrayBuffer?) {
22
+ self.init({ () -> bridge.std__optional_std__string_ in
23
+ if let __unwrappedValue = transcription {
24
+ return bridge.create_std__optional_std__string_(std.string(__unwrappedValue))
25
+ } else {
26
+ return .init()
27
+ }
28
+ }(), { () -> bridge.std__optional_std__shared_ptr_ArrayBuffer__ in
29
+ if let __unwrappedValue = audio {
30
+ return bridge.create_std__optional_std__shared_ptr_ArrayBuffer__(__unwrappedValue.getArrayBuffer())
31
+ } else {
32
+ return .init()
33
+ }
34
+ }())
35
+ }
36
+
37
+ @inline(__always)
38
+ var transcription: String? {
39
+ return { () -> String? in
40
+ if bridge.has_value_std__optional_std__string_(self.__transcription) {
41
+ let __unwrapped = bridge.get_std__optional_std__string_(self.__transcription)
42
+ return String(__unwrapped)
43
+ } else {
44
+ return nil
45
+ }
46
+ }()
47
+ }
48
+
49
+ @inline(__always)
50
+ var audio: ArrayBuffer? {
51
+ return { () -> ArrayBuffer? in
52
+ if bridge.has_value_std__optional_std__shared_ptr_ArrayBuffer__(self.__audio) {
53
+ let __unwrapped = bridge.get_std__optional_std__shared_ptr_ArrayBuffer__(self.__audio)
54
+ return ArrayBuffer(__unwrapped)
55
+ } else {
56
+ return nil
57
+ }
58
+ }()
59
+ }
60
+ }
@@ -17,10 +17,6 @@ namespace margelo::nitro::swe::iternio::reactnativeautoplay {
17
17
  prototype.registerHybridMethod("addListener", &HybridAutoPlaySpec::addListener);
18
18
  prototype.registerHybridMethod("addListenerRenderState", &HybridAutoPlaySpec::addListenerRenderState);
19
19
  prototype.registerHybridMethod("addListenerVoiceInput", &HybridAutoPlaySpec::addListenerVoiceInput);
20
- prototype.registerHybridMethod("hasVoiceInputPermission", &HybridAutoPlaySpec::hasVoiceInputPermission);
21
- prototype.registerHybridMethod("requestVoiceInputPermission", &HybridAutoPlaySpec::requestVoiceInputPermission);
22
- prototype.registerHybridMethod("startVoiceInput", &HybridAutoPlaySpec::startVoiceInput);
23
- prototype.registerHybridMethod("stopVoiceInput", &HybridAutoPlaySpec::stopVoiceInput);
24
20
  prototype.registerHybridMethod("setRootTemplate", &HybridAutoPlaySpec::setRootTemplate);
25
21
  prototype.registerHybridMethod("pushTemplate", &HybridAutoPlaySpec::pushTemplate);
26
22
  prototype.registerHybridMethod("popTemplate", &HybridAutoPlaySpec::popTemplate);
@@ -31,7 +31,6 @@ namespace margelo::nitro::swe::iternio::reactnativeautoplay { struct NitroAction
31
31
  #include "Location.hpp"
32
32
  #include <optional>
33
33
  #include <NitroModules/Promise.hpp>
34
- #include <NitroModules/ArrayBuffer.hpp>
35
34
  #include "SafeAreaInsets.hpp"
36
35
  #include "NitroAction.hpp"
37
36
  #include <vector>
@@ -70,10 +69,6 @@ namespace margelo::nitro::swe::iternio::reactnativeautoplay {
70
69
  virtual std::function<void()> addListener(EventName eventType, const std::function<void()>& callback) = 0;
71
70
  virtual std::function<void()> addListenerRenderState(const std::string& moduleName, const std::function<void(VisibilityState /* payload */)>& callback) = 0;
72
71
  virtual std::function<void()> addListenerVoiceInput(const std::function<void(const std::optional<Location>& /* coordinates */, const std::optional<std::string>& /* query */)>& callback) = 0;
73
- virtual bool hasVoiceInputPermission() = 0;
74
- virtual std::shared_ptr<Promise<bool>> requestVoiceInputPermission() = 0;
75
- virtual std::shared_ptr<Promise<std::shared_ptr<ArrayBuffer>>> startVoiceInput(std::optional<double> silenceThresholdMs, std::optional<double> maxDurationMs, const std::optional<std::string>& listeningText) = 0;
76
- virtual void stopVoiceInput() = 0;
77
72
  virtual std::shared_ptr<Promise<void>> setRootTemplate(const std::string& templateId) = 0;
78
73
  virtual std::shared_ptr<Promise<void>> pushTemplate(const std::string& templateId) = 0;
79
74
  virtual std::shared_ptr<Promise<void>> popTemplate(std::optional<bool> animate) = 0;
@@ -0,0 +1,24 @@
1
+ ///
2
+ /// HybridVoiceSpec.cpp
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
+ #include "HybridVoiceSpec.hpp"
9
+
10
+ namespace margelo::nitro::swe::iternio::reactnativeautoplay {
11
+
12
+ void HybridVoiceSpec::loadHybridMethods() {
13
+ // load base methods/properties
14
+ HybridObject::loadHybridMethods();
15
+ // load custom methods/properties
16
+ registerHybrids(this, [](Prototype& prototype) {
17
+ prototype.registerHybridMethod("hasVoiceInputPermission", &HybridVoiceSpec::hasVoiceInputPermission);
18
+ prototype.registerHybridMethod("requestVoiceInputPermission", &HybridVoiceSpec::requestVoiceInputPermission);
19
+ prototype.registerHybridMethod("startVoiceInput", &HybridVoiceSpec::startVoiceInput);
20
+ prototype.registerHybridMethod("stopVoiceInput", &HybridVoiceSpec::stopVoiceInput);
21
+ });
22
+ }
23
+
24
+ } // namespace margelo::nitro::swe::iternio::reactnativeautoplay
@@ -0,0 +1,73 @@
1
+ ///
2
+ /// HybridVoiceSpec.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
+ #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 `VoiceInputResult` to properly resolve imports.
17
+ namespace margelo::nitro::swe::iternio::reactnativeautoplay { struct VoiceInputResult; }
18
+ // Forward declaration of `VoiceInputChunk` to properly resolve imports.
19
+ namespace margelo::nitro::swe::iternio::reactnativeautoplay { struct VoiceInputChunk; }
20
+
21
+ #include <NitroModules/Promise.hpp>
22
+ #include "VoiceInputResult.hpp"
23
+ #include <optional>
24
+ #include <string>
25
+ #include "VoiceInputChunk.hpp"
26
+ #include <functional>
27
+
28
+ namespace margelo::nitro::swe::iternio::reactnativeautoplay {
29
+
30
+ using namespace margelo::nitro;
31
+
32
+ /**
33
+ * An abstract base class for `Voice`
34
+ * Inherit this class to create instances of `HybridVoiceSpec` in C++.
35
+ * You must explicitly call `HybridObject`'s constructor yourself, because it is virtual.
36
+ * @example
37
+ * ```cpp
38
+ * class HybridVoice: public HybridVoiceSpec {
39
+ * public:
40
+ * HybridVoice(...): HybridObject(TAG) { ... }
41
+ * // ...
42
+ * };
43
+ * ```
44
+ */
45
+ class HybridVoiceSpec: public virtual HybridObject {
46
+ public:
47
+ // Constructor
48
+ explicit HybridVoiceSpec(): HybridObject(TAG) { }
49
+
50
+ // Destructor
51
+ ~HybridVoiceSpec() override = default;
52
+
53
+ public:
54
+ // Properties
55
+
56
+
57
+ public:
58
+ // Methods
59
+ virtual bool hasVoiceInputPermission() = 0;
60
+ virtual std::shared_ptr<Promise<bool>> requestVoiceInputPermission() = 0;
61
+ virtual 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) = 0;
62
+ virtual void stopVoiceInput() = 0;
63
+
64
+ protected:
65
+ // Hybrid Setup
66
+ void loadHybridMethods() override;
67
+
68
+ protected:
69
+ // Tag for logging
70
+ static constexpr auto TAG = "Voice";
71
+ };
72
+
73
+ } // namespace margelo::nitro::swe::iternio::reactnativeautoplay
@@ -0,0 +1,89 @@
1
+ ///
2
+ /// VoiceInputChunk.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
+ #if __has_include(<NitroModules/JSIConverter.hpp>)
11
+ #include <NitroModules/JSIConverter.hpp>
12
+ #else
13
+ #error NitroModules cannot be found! Are you sure you installed NitroModules properly?
14
+ #endif
15
+ #if __has_include(<NitroModules/NitroDefines.hpp>)
16
+ #include <NitroModules/NitroDefines.hpp>
17
+ #else
18
+ #error NitroModules cannot be found! Are you sure you installed NitroModules properly?
19
+ #endif
20
+ #if __has_include(<NitroModules/JSIHelpers.hpp>)
21
+ #include <NitroModules/JSIHelpers.hpp>
22
+ #else
23
+ #error NitroModules cannot be found! Are you sure you installed NitroModules properly?
24
+ #endif
25
+ #if __has_include(<NitroModules/PropNameIDCache.hpp>)
26
+ #include <NitroModules/PropNameIDCache.hpp>
27
+ #else
28
+ #error NitroModules cannot be found! Are you sure you installed NitroModules properly?
29
+ #endif
30
+
31
+
32
+
33
+ #include <string>
34
+ #include <optional>
35
+ #include <NitroModules/ArrayBuffer.hpp>
36
+
37
+ namespace margelo::nitro::swe::iternio::reactnativeautoplay {
38
+
39
+ /**
40
+ * A struct which can be represented as a JavaScript object (VoiceInputChunk).
41
+ */
42
+ struct VoiceInputChunk final {
43
+ public:
44
+ std::optional<std::string> partial SWIFT_PRIVATE;
45
+ std::optional<std::shared_ptr<ArrayBuffer>> audio SWIFT_PRIVATE;
46
+
47
+ public:
48
+ VoiceInputChunk() = default;
49
+ explicit VoiceInputChunk(std::optional<std::string> partial, std::optional<std::shared_ptr<ArrayBuffer>> audio): partial(partial), audio(audio) {}
50
+
51
+ public:
52
+ friend bool operator==(const VoiceInputChunk& lhs, const VoiceInputChunk& rhs) = default;
53
+ };
54
+
55
+ } // namespace margelo::nitro::swe::iternio::reactnativeautoplay
56
+
57
+ namespace margelo::nitro {
58
+
59
+ // C++ VoiceInputChunk <> JS VoiceInputChunk (object)
60
+ template <>
61
+ struct JSIConverter<margelo::nitro::swe::iternio::reactnativeautoplay::VoiceInputChunk> final {
62
+ static inline margelo::nitro::swe::iternio::reactnativeautoplay::VoiceInputChunk fromJSI(jsi::Runtime& runtime, const jsi::Value& arg) {
63
+ jsi::Object obj = arg.asObject(runtime);
64
+ return margelo::nitro::swe::iternio::reactnativeautoplay::VoiceInputChunk(
65
+ JSIConverter<std::optional<std::string>>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "partial"))),
66
+ JSIConverter<std::optional<std::shared_ptr<ArrayBuffer>>>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "audio")))
67
+ );
68
+ }
69
+ static inline jsi::Value toJSI(jsi::Runtime& runtime, const margelo::nitro::swe::iternio::reactnativeautoplay::VoiceInputChunk& arg) {
70
+ jsi::Object obj(runtime);
71
+ obj.setProperty(runtime, PropNameIDCache::get(runtime, "partial"), JSIConverter<std::optional<std::string>>::toJSI(runtime, arg.partial));
72
+ obj.setProperty(runtime, PropNameIDCache::get(runtime, "audio"), JSIConverter<std::optional<std::shared_ptr<ArrayBuffer>>>::toJSI(runtime, arg.audio));
73
+ return obj;
74
+ }
75
+ static inline bool canConvert(jsi::Runtime& runtime, const jsi::Value& value) {
76
+ if (!value.isObject()) {
77
+ return false;
78
+ }
79
+ jsi::Object obj = value.getObject(runtime);
80
+ if (!nitro::isPlainObject(runtime, obj)) {
81
+ return false;
82
+ }
83
+ if (!JSIConverter<std::optional<std::string>>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "partial")))) return false;
84
+ if (!JSIConverter<std::optional<std::shared_ptr<ArrayBuffer>>>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "audio")))) return false;
85
+ return true;
86
+ }
87
+ };
88
+
89
+ } // namespace margelo::nitro
@@ -0,0 +1,89 @@
1
+ ///
2
+ /// VoiceInputResult.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
+ #if __has_include(<NitroModules/JSIConverter.hpp>)
11
+ #include <NitroModules/JSIConverter.hpp>
12
+ #else
13
+ #error NitroModules cannot be found! Are you sure you installed NitroModules properly?
14
+ #endif
15
+ #if __has_include(<NitroModules/NitroDefines.hpp>)
16
+ #include <NitroModules/NitroDefines.hpp>
17
+ #else
18
+ #error NitroModules cannot be found! Are you sure you installed NitroModules properly?
19
+ #endif
20
+ #if __has_include(<NitroModules/JSIHelpers.hpp>)
21
+ #include <NitroModules/JSIHelpers.hpp>
22
+ #else
23
+ #error NitroModules cannot be found! Are you sure you installed NitroModules properly?
24
+ #endif
25
+ #if __has_include(<NitroModules/PropNameIDCache.hpp>)
26
+ #include <NitroModules/PropNameIDCache.hpp>
27
+ #else
28
+ #error NitroModules cannot be found! Are you sure you installed NitroModules properly?
29
+ #endif
30
+
31
+
32
+
33
+ #include <string>
34
+ #include <optional>
35
+ #include <NitroModules/ArrayBuffer.hpp>
36
+
37
+ namespace margelo::nitro::swe::iternio::reactnativeautoplay {
38
+
39
+ /**
40
+ * A struct which can be represented as a JavaScript object (VoiceInputResult).
41
+ */
42
+ struct VoiceInputResult final {
43
+ public:
44
+ std::optional<std::string> transcription SWIFT_PRIVATE;
45
+ std::optional<std::shared_ptr<ArrayBuffer>> audio SWIFT_PRIVATE;
46
+
47
+ public:
48
+ VoiceInputResult() = default;
49
+ explicit VoiceInputResult(std::optional<std::string> transcription, std::optional<std::shared_ptr<ArrayBuffer>> audio): transcription(transcription), audio(audio) {}
50
+
51
+ public:
52
+ friend bool operator==(const VoiceInputResult& lhs, const VoiceInputResult& rhs) = default;
53
+ };
54
+
55
+ } // namespace margelo::nitro::swe::iternio::reactnativeautoplay
56
+
57
+ namespace margelo::nitro {
58
+
59
+ // C++ VoiceInputResult <> JS VoiceInputResult (object)
60
+ template <>
61
+ struct JSIConverter<margelo::nitro::swe::iternio::reactnativeautoplay::VoiceInputResult> final {
62
+ static inline margelo::nitro::swe::iternio::reactnativeautoplay::VoiceInputResult fromJSI(jsi::Runtime& runtime, const jsi::Value& arg) {
63
+ jsi::Object obj = arg.asObject(runtime);
64
+ return margelo::nitro::swe::iternio::reactnativeautoplay::VoiceInputResult(
65
+ JSIConverter<std::optional<std::string>>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "transcription"))),
66
+ JSIConverter<std::optional<std::shared_ptr<ArrayBuffer>>>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "audio")))
67
+ );
68
+ }
69
+ static inline jsi::Value toJSI(jsi::Runtime& runtime, const margelo::nitro::swe::iternio::reactnativeautoplay::VoiceInputResult& arg) {
70
+ jsi::Object obj(runtime);
71
+ obj.setProperty(runtime, PropNameIDCache::get(runtime, "transcription"), JSIConverter<std::optional<std::string>>::toJSI(runtime, arg.transcription));
72
+ obj.setProperty(runtime, PropNameIDCache::get(runtime, "audio"), JSIConverter<std::optional<std::shared_ptr<ArrayBuffer>>>::toJSI(runtime, arg.audio));
73
+ return obj;
74
+ }
75
+ static inline bool canConvert(jsi::Runtime& runtime, const jsi::Value& value) {
76
+ if (!value.isObject()) {
77
+ return false;
78
+ }
79
+ jsi::Object obj = value.getObject(runtime);
80
+ if (!nitro::isPlainObject(runtime, obj)) {
81
+ return false;
82
+ }
83
+ if (!JSIConverter<std::optional<std::string>>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "transcription")))) return false;
84
+ if (!JSIConverter<std::optional<std::shared_ptr<ArrayBuffer>>>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "audio")))) return false;
85
+ return true;
86
+ }
87
+ };
88
+
89
+ } // namespace margelo::nitro
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@iternio/react-native-auto-play",
3
- "version": "0.4.1",
3
+ "version": "0.4.2",
4
4
  "description": "Android Auto and Apple CarPlay for react-native",
5
5
  "main": "lib/index",
6
6
  "module": "lib/index",