@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,16 @@
1
+ export interface VoiceInputChunk {
2
+ partial?: string;
3
+ audio?: ArrayBuffer;
4
+ }
5
+ export interface VoiceInputResult {
6
+ transcription?: string;
7
+ audio?: ArrayBuffer;
8
+ }
9
+ export interface VoiceInputOptions {
10
+ silenceThresholdMs?: number;
11
+ maxDurationMs?: number;
12
+ listeningText?: string;
13
+ preferSpeechToText?: boolean;
14
+ onChunk?: (chunk: VoiceInputChunk) => void;
15
+ language?: string;
16
+ }
@@ -0,0 +1 @@
1
+ export {};
package/nitro.json CHANGED
@@ -9,6 +9,16 @@
9
9
  "androidCxxLibName": "ReactNativeAutoPlay"
10
10
  },
11
11
  "autolinking": {
12
+ "Voice": {
13
+ "android": {
14
+ "implementationClassName": "HybridVoice",
15
+ "language": "kotlin"
16
+ },
17
+ "ios": {
18
+ "implementationClassName": "HybridVoice",
19
+ "language": "swift"
20
+ }
21
+ },
12
22
  "AutoPlay": {
13
23
  "android": {
14
24
  "implementationClassName": "HybridAutoPlay",
@@ -45,6 +45,7 @@ target_sources(
45
45
  ../nitrogen/generated/shared/c++/HybridMessageTemplateSpec.cpp
46
46
  ../nitrogen/generated/shared/c++/HybridSearchTemplateSpec.cpp
47
47
  ../nitrogen/generated/shared/c++/HybridSignInTemplateSpec.cpp
48
+ ../nitrogen/generated/shared/c++/HybridVoiceSpec.cpp
48
49
  # Android-specific Nitrogen C++ sources
49
50
  ../nitrogen/generated/android/c++/JHybridAndroidAutomotiveSpec.cpp
50
51
  ../nitrogen/generated/android/c++/JHybridAndroidAutoTelemetrySpec.cpp
@@ -62,6 +63,7 @@ target_sources(
62
63
  ../nitrogen/generated/android/c++/JHybridSearchTemplateSpec.cpp
63
64
  ../nitrogen/generated/android/c++/JHybridSignInTemplateSpec.cpp
64
65
  ../nitrogen/generated/android/c++/JVariant_QrSignIn_PinSignIn_InputSignIn_GoogleSignIn.cpp
66
+ ../nitrogen/generated/android/c++/JHybridVoiceSpec.cpp
65
67
  )
66
68
 
67
69
  # From node_modules/react-native/ReactAndroid/cmake-utils/folly-flags.cmake
@@ -46,6 +46,8 @@
46
46
  #include "JHybridSearchTemplateSpec.hpp"
47
47
  #include "JHybridSignInTemplateSpec.hpp"
48
48
  #include "JFunc_void_std__optional_std__string__std__optional_GoogleSignInAccount_.hpp"
49
+ #include "JHybridVoiceSpec.hpp"
50
+ #include "JFunc_void_VoiceInputChunk.hpp"
49
51
  #include <NitroModules/DefaultConstructableObject.hpp>
50
52
 
51
53
  namespace margelo::nitro::swe::iternio::reactnativeautoplay {
@@ -56,6 +58,14 @@ int initialize(JavaVM* vm) {
56
58
  });
57
59
  }
58
60
 
61
+ struct JHybridVoiceSpecImpl: public jni::JavaClass<JHybridVoiceSpecImpl, JHybridVoiceSpec::JavaPart> {
62
+ static constexpr auto kJavaDescriptor = "Lcom/margelo/nitro/swe/iternio/reactnativeautoplay/HybridVoice;";
63
+ static std::shared_ptr<JHybridVoiceSpec> create() {
64
+ static const auto constructorFn = javaClassStatic()->getConstructor<JHybridVoiceSpecImpl::javaobject()>();
65
+ jni::local_ref<JHybridVoiceSpec::JavaPart> javaPart = javaClassStatic()->newObject(constructorFn);
66
+ return javaPart->getJHybridVoiceSpec();
67
+ }
68
+ };
59
69
  struct JHybridAutoPlaySpecImpl: public jni::JavaClass<JHybridAutoPlaySpecImpl, JHybridAutoPlaySpec::JavaPart> {
60
70
  static constexpr auto kJavaDescriptor = "Lcom/margelo/nitro/swe/iternio/reactnativeautoplay/HybridAutoPlay;";
61
71
  static std::shared_ptr<JHybridAutoPlaySpec> create() {
@@ -181,8 +191,16 @@ void registerAllNatives() {
181
191
  margelo::nitro::swe::iternio::reactnativeautoplay::JHybridSearchTemplateSpec::CxxPart::registerNatives();
182
192
  margelo::nitro::swe::iternio::reactnativeautoplay::JHybridSignInTemplateSpec::CxxPart::registerNatives();
183
193
  margelo::nitro::swe::iternio::reactnativeautoplay::JFunc_void_std__optional_std__string__std__optional_GoogleSignInAccount__cxx::registerNatives();
194
+ margelo::nitro::swe::iternio::reactnativeautoplay::JHybridVoiceSpec::CxxPart::registerNatives();
195
+ margelo::nitro::swe::iternio::reactnativeautoplay::JFunc_void_VoiceInputChunk_cxx::registerNatives();
184
196
 
185
197
  // Register Nitro Hybrid Objects
198
+ HybridObjectRegistry::registerHybridObjectConstructor(
199
+ "Voice",
200
+ []() -> std::shared_ptr<HybridObject> {
201
+ return JHybridVoiceSpecImpl::create();
202
+ }
203
+ );
186
204
  HybridObjectRegistry::registerHybridObjectConstructor(
187
205
  "AutoPlay",
188
206
  []() -> std::shared_ptr<HybridObject> {
@@ -0,0 +1,81 @@
1
+ ///
2
+ /// JFunc_void_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
+ #include <fbjni/fbjni.h>
11
+ #include <functional>
12
+
13
+ #include "VoiceInputChunk.hpp"
14
+ #include <functional>
15
+ #include <NitroModules/JNICallable.hpp>
16
+ #include "JVoiceInputChunk.hpp"
17
+ #include <string>
18
+ #include <optional>
19
+ #include <NitroModules/ArrayBuffer.hpp>
20
+ #include <NitroModules/JArrayBuffer.hpp>
21
+
22
+ namespace margelo::nitro::swe::iternio::reactnativeautoplay {
23
+
24
+ using namespace facebook;
25
+
26
+ /**
27
+ * Represents the Java/Kotlin callback `(chunk: VoiceInputChunk) -> Unit`.
28
+ * This can be passed around between C++ and Java/Kotlin.
29
+ */
30
+ struct JFunc_void_VoiceInputChunk: public jni::JavaClass<JFunc_void_VoiceInputChunk> {
31
+ public:
32
+ static constexpr auto kJavaDescriptor = "Lcom/margelo/nitro/swe/iternio/reactnativeautoplay/Func_void_VoiceInputChunk;";
33
+
34
+ public:
35
+ /**
36
+ * Invokes the function this `JFunc_void_VoiceInputChunk` instance holds through JNI.
37
+ */
38
+ void invoke(const VoiceInputChunk& chunk) const {
39
+ static const auto method = javaClassStatic()->getMethod<void(jni::alias_ref<JVoiceInputChunk> /* chunk */)>("invoke");
40
+ method(self(), JVoiceInputChunk::fromCpp(chunk));
41
+ }
42
+ };
43
+
44
+ /**
45
+ * An implementation of Func_void_VoiceInputChunk that is backed by a C++ implementation (using `std::function<...>`)
46
+ */
47
+ class JFunc_void_VoiceInputChunk_cxx final: public jni::HybridClass<JFunc_void_VoiceInputChunk_cxx, JFunc_void_VoiceInputChunk> {
48
+ public:
49
+ static jni::local_ref<JFunc_void_VoiceInputChunk::javaobject> fromCpp(const std::function<void(const VoiceInputChunk& /* chunk */)>& func) {
50
+ return JFunc_void_VoiceInputChunk_cxx::newObjectCxxArgs(func);
51
+ }
52
+
53
+ public:
54
+ /**
55
+ * Invokes the C++ `std::function<...>` this `JFunc_void_VoiceInputChunk_cxx` instance holds.
56
+ */
57
+ void invoke_cxx(jni::alias_ref<JVoiceInputChunk> chunk) {
58
+ _func(chunk->toCpp());
59
+ }
60
+
61
+ public:
62
+ [[nodiscard]]
63
+ inline const std::function<void(const VoiceInputChunk& /* chunk */)>& getFunction() const {
64
+ return _func;
65
+ }
66
+
67
+ public:
68
+ static constexpr auto kJavaDescriptor = "Lcom/margelo/nitro/swe/iternio/reactnativeautoplay/Func_void_VoiceInputChunk_cxx;";
69
+ static void registerNatives() {
70
+ registerHybrid({makeNativeMethod("invoke_cxx", JFunc_void_VoiceInputChunk_cxx::invoke_cxx)});
71
+ }
72
+
73
+ private:
74
+ explicit JFunc_void_VoiceInputChunk_cxx(const std::function<void(const VoiceInputChunk& /* chunk */)>& func): _func(func) { }
75
+
76
+ private:
77
+ friend HybridBase;
78
+ std::function<void(const VoiceInputChunk& /* chunk */)> _func;
79
+ };
80
+
81
+ } // namespace margelo::nitro::swe::iternio::reactnativeautoplay
@@ -37,8 +37,6 @@ namespace margelo::nitro::swe::iternio::reactnativeautoplay { enum class NitroBu
37
37
  #include <NitroModules/JNICallable.hpp>
38
38
  #include <NitroModules/Promise.hpp>
39
39
  #include <NitroModules/JPromise.hpp>
40
- #include <NitroModules/ArrayBuffer.hpp>
41
- #include <NitroModules/JArrayBuffer.hpp>
42
40
  #include <NitroModules/JUnit.hpp>
43
41
  #include "EventName.hpp"
44
42
  #include "JEventName.hpp"
@@ -145,47 +143,6 @@ namespace margelo::nitro::swe::iternio::reactnativeautoplay {
145
143
  }
146
144
  }();
147
145
  }
148
- bool JHybridAutoPlaySpec::hasVoiceInputPermission() {
149
- static const auto method = _javaPart->javaClassStatic()->getMethod<jboolean()>("hasVoiceInputPermission");
150
- auto __result = method(_javaPart);
151
- return static_cast<bool>(__result);
152
- }
153
- std::shared_ptr<Promise<bool>> JHybridAutoPlaySpec::requestVoiceInputPermission() {
154
- static const auto method = _javaPart->javaClassStatic()->getMethod<jni::local_ref<JPromise::javaobject>()>("requestVoiceInputPermission");
155
- auto __result = method(_javaPart);
156
- return [&]() {
157
- auto __promise = Promise<bool>::create();
158
- __result->cthis()->addOnResolvedListener([=](const jni::alias_ref<jni::JObject>& __boxedResult) {
159
- auto __result = jni::static_ref_cast<jni::JBoolean>(__boxedResult);
160
- __promise->resolve(static_cast<bool>(__result->value()));
161
- });
162
- __result->cthis()->addOnRejectedListener([=](const jni::alias_ref<jni::JThrowable>& __throwable) {
163
- jni::JniException __jniError(__throwable);
164
- __promise->reject(std::make_exception_ptr(__jniError));
165
- });
166
- return __promise;
167
- }();
168
- }
169
- std::shared_ptr<Promise<std::shared_ptr<ArrayBuffer>>> JHybridAutoPlaySpec::startVoiceInput(std::optional<double> silenceThresholdMs, std::optional<double> maxDurationMs, const std::optional<std::string>& listeningText) {
170
- static const auto method = _javaPart->javaClassStatic()->getMethod<jni::local_ref<JPromise::javaobject>(jni::alias_ref<jni::JDouble> /* silenceThresholdMs */, jni::alias_ref<jni::JDouble> /* maxDurationMs */, jni::alias_ref<jni::JString> /* listeningText */)>("startVoiceInput");
171
- auto __result = method(_javaPart, silenceThresholdMs.has_value() ? jni::JDouble::valueOf(silenceThresholdMs.value()) : nullptr, maxDurationMs.has_value() ? jni::JDouble::valueOf(maxDurationMs.value()) : nullptr, listeningText.has_value() ? jni::make_jstring(listeningText.value()) : nullptr);
172
- return [&]() {
173
- auto __promise = Promise<std::shared_ptr<ArrayBuffer>>::create();
174
- __result->cthis()->addOnResolvedListener([=](const jni::alias_ref<jni::JObject>& __boxedResult) {
175
- auto __result = jni::static_ref_cast<JArrayBuffer::javaobject>(__boxedResult);
176
- __promise->resolve(__result->cthis()->getArrayBuffer());
177
- });
178
- __result->cthis()->addOnRejectedListener([=](const jni::alias_ref<jni::JThrowable>& __throwable) {
179
- jni::JniException __jniError(__throwable);
180
- __promise->reject(std::make_exception_ptr(__jniError));
181
- });
182
- return __promise;
183
- }();
184
- }
185
- void JHybridAutoPlaySpec::stopVoiceInput() {
186
- static const auto method = _javaPart->javaClassStatic()->getMethod<void()>("stopVoiceInput");
187
- method(_javaPart);
188
- }
189
146
  std::shared_ptr<Promise<void>> JHybridAutoPlaySpec::setRootTemplate(const std::string& templateId) {
190
147
  static const auto method = _javaPart->javaClassStatic()->getMethod<jni::local_ref<JPromise::javaobject>(jni::alias_ref<jni::JString> /* templateId */)>("setRootTemplate");
191
148
  auto __result = method(_javaPart, jni::make_jstring(templateId));
@@ -57,10 +57,6 @@ namespace margelo::nitro::swe::iternio::reactnativeautoplay {
57
57
  std::function<void()> addListener(EventName eventType, const std::function<void()>& callback) override;
58
58
  std::function<void()> addListenerRenderState(const std::string& moduleName, const std::function<void(VisibilityState /* payload */)>& callback) override;
59
59
  std::function<void()> addListenerVoiceInput(const std::function<void(const std::optional<Location>& /* coordinates */, const std::optional<std::string>& /* query */)>& callback) override;
60
- bool hasVoiceInputPermission() override;
61
- std::shared_ptr<Promise<bool>> requestVoiceInputPermission() override;
62
- std::shared_ptr<Promise<std::shared_ptr<ArrayBuffer>>> startVoiceInput(std::optional<double> silenceThresholdMs, std::optional<double> maxDurationMs, const std::optional<std::string>& listeningText) override;
63
- void stopVoiceInput() override;
64
60
  std::shared_ptr<Promise<void>> setRootTemplate(const std::string& templateId) override;
65
61
  std::shared_ptr<Promise<void>> pushTemplate(const std::string& templateId) override;
66
62
  std::shared_ptr<Promise<void>> popTemplate(std::optional<bool> animate) override;
@@ -0,0 +1,104 @@
1
+ ///
2
+ /// JHybridVoiceSpec.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 "JHybridVoiceSpec.hpp"
9
+
10
+ // Forward declaration of `VoiceInputResult` to properly resolve imports.
11
+ namespace margelo::nitro::swe::iternio::reactnativeautoplay { struct VoiceInputResult; }
12
+ // Forward declaration of `VoiceInputChunk` to properly resolve imports.
13
+ namespace margelo::nitro::swe::iternio::reactnativeautoplay { struct VoiceInputChunk; }
14
+
15
+ #include <NitroModules/Promise.hpp>
16
+ #include <NitroModules/JPromise.hpp>
17
+ #include "VoiceInputResult.hpp"
18
+ #include "JVoiceInputResult.hpp"
19
+ #include <string>
20
+ #include <optional>
21
+ #include <NitroModules/ArrayBuffer.hpp>
22
+ #include <NitroModules/JArrayBuffer.hpp>
23
+ #include "VoiceInputChunk.hpp"
24
+ #include <functional>
25
+ #include "JFunc_void_VoiceInputChunk.hpp"
26
+ #include <NitroModules/JNICallable.hpp>
27
+ #include "JVoiceInputChunk.hpp"
28
+
29
+ namespace margelo::nitro::swe::iternio::reactnativeautoplay {
30
+
31
+ std::shared_ptr<JHybridVoiceSpec> JHybridVoiceSpec::JavaPart::getJHybridVoiceSpec() {
32
+ auto hybridObject = JHybridObject::JavaPart::getJHybridObject();
33
+ auto castHybridObject = std::dynamic_pointer_cast<JHybridVoiceSpec>(hybridObject);
34
+ if (castHybridObject == nullptr) [[unlikely]] {
35
+ throw std::runtime_error("Failed to downcast JHybridObject to JHybridVoiceSpec!");
36
+ }
37
+ return castHybridObject;
38
+ }
39
+
40
+ jni::local_ref<JHybridVoiceSpec::CxxPart::jhybriddata> JHybridVoiceSpec::CxxPart::initHybrid(jni::alias_ref<jhybridobject> jThis) {
41
+ return makeCxxInstance(jThis);
42
+ }
43
+
44
+ std::shared_ptr<JHybridObject> JHybridVoiceSpec::CxxPart::createHybridObject(const jni::local_ref<JHybridObject::JavaPart>& javaPart) {
45
+ auto castJavaPart = jni::dynamic_ref_cast<JHybridVoiceSpec::JavaPart>(javaPart);
46
+ if (castJavaPart == nullptr) [[unlikely]] {
47
+ throw std::runtime_error("Failed to cast JHybridObject::JavaPart to JHybridVoiceSpec::JavaPart!");
48
+ }
49
+ return std::make_shared<JHybridVoiceSpec>(castJavaPart);
50
+ }
51
+
52
+ void JHybridVoiceSpec::CxxPart::registerNatives() {
53
+ registerHybrid({
54
+ makeNativeMethod("initHybrid", JHybridVoiceSpec::CxxPart::initHybrid),
55
+ });
56
+ }
57
+
58
+ // Properties
59
+
60
+
61
+ // Methods
62
+ bool JHybridVoiceSpec::hasVoiceInputPermission() {
63
+ static const auto method = _javaPart->javaClassStatic()->getMethod<jboolean()>("hasVoiceInputPermission");
64
+ auto __result = method(_javaPart);
65
+ return static_cast<bool>(__result);
66
+ }
67
+ std::shared_ptr<Promise<bool>> JHybridVoiceSpec::requestVoiceInputPermission() {
68
+ static const auto method = _javaPart->javaClassStatic()->getMethod<jni::local_ref<JPromise::javaobject>()>("requestVoiceInputPermission");
69
+ auto __result = method(_javaPart);
70
+ return [&]() {
71
+ auto __promise = Promise<bool>::create();
72
+ __result->cthis()->addOnResolvedListener([=](const jni::alias_ref<jni::JObject>& __boxedResult) {
73
+ auto __result = jni::static_ref_cast<jni::JBoolean>(__boxedResult);
74
+ __promise->resolve(static_cast<bool>(__result->value()));
75
+ });
76
+ __result->cthis()->addOnRejectedListener([=](const jni::alias_ref<jni::JThrowable>& __throwable) {
77
+ jni::JniException __jniError(__throwable);
78
+ __promise->reject(std::make_exception_ptr(__jniError));
79
+ });
80
+ return __promise;
81
+ }();
82
+ }
83
+ std::shared_ptr<Promise<VoiceInputResult>> JHybridVoiceSpec::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) {
84
+ static const auto method = _javaPart->javaClassStatic()->getMethod<jni::local_ref<JPromise::javaobject>(jni::alias_ref<jni::JDouble> /* silenceThresholdMs */, jni::alias_ref<jni::JDouble> /* maxDurationMs */, jni::alias_ref<jni::JString> /* listeningText */, jni::alias_ref<jni::JBoolean> /* preferSpeechToText */, jni::alias_ref<JFunc_void_VoiceInputChunk::javaobject> /* onChunk */, jni::alias_ref<jni::JString> /* language */)>("startVoiceInput_cxx");
85
+ auto __result = method(_javaPart, silenceThresholdMs.has_value() ? jni::JDouble::valueOf(silenceThresholdMs.value()) : nullptr, maxDurationMs.has_value() ? jni::JDouble::valueOf(maxDurationMs.value()) : nullptr, listeningText.has_value() ? jni::make_jstring(listeningText.value()) : nullptr, preferSpeechToText.has_value() ? jni::JBoolean::valueOf(preferSpeechToText.value()) : nullptr, onChunk.has_value() ? JFunc_void_VoiceInputChunk_cxx::fromCpp(onChunk.value()) : nullptr, language.has_value() ? jni::make_jstring(language.value()) : nullptr);
86
+ return [&]() {
87
+ auto __promise = Promise<VoiceInputResult>::create();
88
+ __result->cthis()->addOnResolvedListener([=](const jni::alias_ref<jni::JObject>& __boxedResult) {
89
+ auto __result = jni::static_ref_cast<JVoiceInputResult>(__boxedResult);
90
+ __promise->resolve(__result->toCpp());
91
+ });
92
+ __result->cthis()->addOnRejectedListener([=](const jni::alias_ref<jni::JThrowable>& __throwable) {
93
+ jni::JniException __jniError(__throwable);
94
+ __promise->reject(std::make_exception_ptr(__jniError));
95
+ });
96
+ return __promise;
97
+ }();
98
+ }
99
+ void JHybridVoiceSpec::stopVoiceInput() {
100
+ static const auto method = _javaPart->javaClassStatic()->getMethod<void()>("stopVoiceInput");
101
+ method(_javaPart);
102
+ }
103
+
104
+ } // namespace margelo::nitro::swe::iternio::reactnativeautoplay
@@ -0,0 +1,66 @@
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
+ #include <NitroModules/JHybridObject.hpp>
11
+ #include <fbjni/fbjni.h>
12
+ #include "HybridVoiceSpec.hpp"
13
+
14
+
15
+
16
+
17
+ namespace margelo::nitro::swe::iternio::reactnativeautoplay {
18
+
19
+ using namespace facebook;
20
+
21
+ class JHybridVoiceSpec: public virtual HybridVoiceSpec, public virtual JHybridObject {
22
+ public:
23
+ struct JavaPart: public jni::JavaClass<JavaPart, JHybridObject::JavaPart> {
24
+ static constexpr auto kJavaDescriptor = "Lcom/margelo/nitro/swe/iternio/reactnativeautoplay/HybridVoiceSpec;";
25
+ std::shared_ptr<JHybridVoiceSpec> getJHybridVoiceSpec();
26
+ };
27
+ struct CxxPart: public jni::HybridClass<CxxPart, JHybridObject::CxxPart> {
28
+ static constexpr auto kJavaDescriptor = "Lcom/margelo/nitro/swe/iternio/reactnativeautoplay/HybridVoiceSpec$CxxPart;";
29
+ static jni::local_ref<jhybriddata> initHybrid(jni::alias_ref<jhybridobject> jThis);
30
+ static void registerNatives();
31
+ using HybridBase::HybridBase;
32
+ protected:
33
+ std::shared_ptr<JHybridObject> createHybridObject(const jni::local_ref<JHybridObject::JavaPart>& javaPart) override;
34
+ };
35
+
36
+ public:
37
+ explicit JHybridVoiceSpec(const jni::local_ref<JHybridVoiceSpec::JavaPart>& javaPart):
38
+ HybridObject(HybridVoiceSpec::TAG),
39
+ JHybridObject(javaPart),
40
+ _javaPart(jni::make_global(javaPart)) {}
41
+ ~JHybridVoiceSpec() override {
42
+ // Hermes GC can destroy JS objects on a non-JNI Thread.
43
+ jni::ThreadScope::WithClassLoader([&] { _javaPart.reset(); });
44
+ }
45
+
46
+ public:
47
+ inline const jni::global_ref<JHybridVoiceSpec::JavaPart>& getJavaPart() const noexcept {
48
+ return _javaPart;
49
+ }
50
+
51
+ public:
52
+ // Properties
53
+
54
+
55
+ public:
56
+ // Methods
57
+ bool hasVoiceInputPermission() override;
58
+ std::shared_ptr<Promise<bool>> requestVoiceInputPermission() override;
59
+ 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;
60
+ void stopVoiceInput() override;
61
+
62
+ private:
63
+ jni::global_ref<JHybridVoiceSpec::JavaPart> _javaPart;
64
+ };
65
+
66
+ } // namespace margelo::nitro::swe::iternio::reactnativeautoplay
@@ -0,0 +1,64 @@
1
+ ///
2
+ /// JVoiceInputChunk.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 <fbjni/fbjni.h>
11
+ #include "VoiceInputChunk.hpp"
12
+
13
+ #include <NitroModules/ArrayBuffer.hpp>
14
+ #include <NitroModules/JArrayBuffer.hpp>
15
+ #include <optional>
16
+ #include <string>
17
+
18
+ namespace margelo::nitro::swe::iternio::reactnativeautoplay {
19
+
20
+ using namespace facebook;
21
+
22
+ /**
23
+ * The C++ JNI bridge between the C++ struct "VoiceInputChunk" and the the Kotlin data class "VoiceInputChunk".
24
+ */
25
+ struct JVoiceInputChunk final: public jni::JavaClass<JVoiceInputChunk> {
26
+ public:
27
+ static constexpr auto kJavaDescriptor = "Lcom/margelo/nitro/swe/iternio/reactnativeautoplay/VoiceInputChunk;";
28
+
29
+ public:
30
+ /**
31
+ * Convert this Java/Kotlin-based struct to the C++ struct VoiceInputChunk by copying all values to C++.
32
+ */
33
+ [[maybe_unused]]
34
+ [[nodiscard]]
35
+ VoiceInputChunk toCpp() const {
36
+ static const auto clazz = javaClassStatic();
37
+ static const auto fieldPartial = clazz->getField<jni::JString>("partial");
38
+ jni::local_ref<jni::JString> partial = this->getFieldValue(fieldPartial);
39
+ static const auto fieldAudio = clazz->getField<JArrayBuffer::javaobject>("audio");
40
+ jni::local_ref<JArrayBuffer::javaobject> audio = this->getFieldValue(fieldAudio);
41
+ return VoiceInputChunk(
42
+ partial != nullptr ? std::make_optional(partial->toStdString()) : std::nullopt,
43
+ audio != nullptr ? std::make_optional(audio->cthis()->getArrayBuffer()) : std::nullopt
44
+ );
45
+ }
46
+
47
+ public:
48
+ /**
49
+ * Create a Java/Kotlin-based struct by copying all values from the given C++ struct to Java.
50
+ */
51
+ [[maybe_unused]]
52
+ static jni::local_ref<JVoiceInputChunk::javaobject> fromCpp(const VoiceInputChunk& value) {
53
+ using JSignature = JVoiceInputChunk(jni::alias_ref<jni::JString>, jni::alias_ref<JArrayBuffer::javaobject>);
54
+ static const auto clazz = javaClassStatic();
55
+ static const auto create = clazz->getStaticMethod<JSignature>("fromCpp");
56
+ return create(
57
+ clazz,
58
+ value.partial.has_value() ? jni::make_jstring(value.partial.value()) : nullptr,
59
+ value.audio.has_value() ? JArrayBuffer::wrap(value.audio.value()) : nullptr
60
+ );
61
+ }
62
+ };
63
+
64
+ } // namespace margelo::nitro::swe::iternio::reactnativeautoplay
@@ -0,0 +1,64 @@
1
+ ///
2
+ /// JVoiceInputResult.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 <fbjni/fbjni.h>
11
+ #include "VoiceInputResult.hpp"
12
+
13
+ #include <NitroModules/ArrayBuffer.hpp>
14
+ #include <NitroModules/JArrayBuffer.hpp>
15
+ #include <optional>
16
+ #include <string>
17
+
18
+ namespace margelo::nitro::swe::iternio::reactnativeautoplay {
19
+
20
+ using namespace facebook;
21
+
22
+ /**
23
+ * The C++ JNI bridge between the C++ struct "VoiceInputResult" and the the Kotlin data class "VoiceInputResult".
24
+ */
25
+ struct JVoiceInputResult final: public jni::JavaClass<JVoiceInputResult> {
26
+ public:
27
+ static constexpr auto kJavaDescriptor = "Lcom/margelo/nitro/swe/iternio/reactnativeautoplay/VoiceInputResult;";
28
+
29
+ public:
30
+ /**
31
+ * Convert this Java/Kotlin-based struct to the C++ struct VoiceInputResult by copying all values to C++.
32
+ */
33
+ [[maybe_unused]]
34
+ [[nodiscard]]
35
+ VoiceInputResult toCpp() const {
36
+ static const auto clazz = javaClassStatic();
37
+ static const auto fieldTranscription = clazz->getField<jni::JString>("transcription");
38
+ jni::local_ref<jni::JString> transcription = this->getFieldValue(fieldTranscription);
39
+ static const auto fieldAudio = clazz->getField<JArrayBuffer::javaobject>("audio");
40
+ jni::local_ref<JArrayBuffer::javaobject> audio = this->getFieldValue(fieldAudio);
41
+ return VoiceInputResult(
42
+ transcription != nullptr ? std::make_optional(transcription->toStdString()) : std::nullopt,
43
+ audio != nullptr ? std::make_optional(audio->cthis()->getArrayBuffer()) : std::nullopt
44
+ );
45
+ }
46
+
47
+ public:
48
+ /**
49
+ * Create a Java/Kotlin-based struct by copying all values from the given C++ struct to Java.
50
+ */
51
+ [[maybe_unused]]
52
+ static jni::local_ref<JVoiceInputResult::javaobject> fromCpp(const VoiceInputResult& value) {
53
+ using JSignature = JVoiceInputResult(jni::alias_ref<jni::JString>, jni::alias_ref<JArrayBuffer::javaobject>);
54
+ static const auto clazz = javaClassStatic();
55
+ static const auto create = clazz->getStaticMethod<JSignature>("fromCpp");
56
+ return create(
57
+ clazz,
58
+ value.transcription.has_value() ? jni::make_jstring(value.transcription.value()) : nullptr,
59
+ value.audio.has_value() ? JArrayBuffer::wrap(value.audio.value()) : nullptr
60
+ );
61
+ }
62
+ };
63
+
64
+ } // namespace margelo::nitro::swe::iternio::reactnativeautoplay
@@ -0,0 +1,80 @@
1
+ ///
2
+ /// Func_void_VoiceInputChunk.kt
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
+ package com.margelo.nitro.swe.iternio.reactnativeautoplay
9
+
10
+ import androidx.annotation.Keep
11
+ import com.facebook.jni.HybridData
12
+ import com.facebook.proguard.annotations.DoNotStrip
13
+ import dalvik.annotation.optimization.FastNative
14
+
15
+
16
+ /**
17
+ * Represents the JavaScript callback `(chunk: struct) => void`.
18
+ * This can be either implemented in C++ (in which case it might be a callback coming from JS),
19
+ * or in Kotlin/Java (in which case it is a native callback).
20
+ */
21
+ @DoNotStrip
22
+ @Keep
23
+ @Suppress("ClassName", "RedundantUnitReturnType")
24
+ fun interface Func_void_VoiceInputChunk: (VoiceInputChunk) -> Unit {
25
+ /**
26
+ * Call the given JS callback.
27
+ * @throws Throwable if the JS function itself throws an error, or if the JS function/runtime has already been deleted.
28
+ */
29
+ @DoNotStrip
30
+ @Keep
31
+ override fun invoke(chunk: VoiceInputChunk): Unit
32
+ }
33
+
34
+ /**
35
+ * Represents the JavaScript callback `(chunk: struct) => void`.
36
+ * This is implemented in C++, via a `std::function<...>`.
37
+ * The callback might be coming from JS.
38
+ */
39
+ @DoNotStrip
40
+ @Keep
41
+ @Suppress(
42
+ "KotlinJniMissingFunction", "unused",
43
+ "RedundantSuppression", "RedundantUnitReturnType", "FunctionName",
44
+ "ConvertSecondaryConstructorToPrimary", "ClassName", "LocalVariableName",
45
+ )
46
+ class Func_void_VoiceInputChunk_cxx: Func_void_VoiceInputChunk {
47
+ @DoNotStrip
48
+ @Keep
49
+ private val mHybridData: HybridData
50
+
51
+ @DoNotStrip
52
+ @Keep
53
+ private constructor(hybridData: HybridData) {
54
+ mHybridData = hybridData
55
+ }
56
+
57
+ @DoNotStrip
58
+ @Keep
59
+ override fun invoke(chunk: VoiceInputChunk): Unit
60
+ = invoke_cxx(chunk)
61
+
62
+ @FastNative
63
+ private external fun invoke_cxx(chunk: VoiceInputChunk): Unit
64
+ }
65
+
66
+ /**
67
+ * Represents the JavaScript callback `(chunk: struct) => void`.
68
+ * This is implemented in Java/Kotlin, via a `(VoiceInputChunk) -> Unit`.
69
+ * The callback is always coming from native.
70
+ */
71
+ @DoNotStrip
72
+ @Keep
73
+ @Suppress("ClassName", "RedundantUnitReturnType", "unused")
74
+ class Func_void_VoiceInputChunk_java(private val function: (VoiceInputChunk) -> Unit): Func_void_VoiceInputChunk {
75
+ @DoNotStrip
76
+ @Keep
77
+ override fun invoke(chunk: VoiceInputChunk): Unit {
78
+ return this.function(chunk)
79
+ }
80
+ }
@@ -11,7 +11,6 @@ import androidx.annotation.Keep
11
11
  import com.facebook.jni.HybridData
12
12
  import com.facebook.proguard.annotations.DoNotStrip
13
13
  import com.margelo.nitro.core.Promise
14
- import com.margelo.nitro.core.ArrayBuffer
15
14
  import com.margelo.nitro.core.HybridObject
16
15
 
17
16
  /**
@@ -57,22 +56,6 @@ abstract class HybridAutoPlaySpec: HybridObject() {
57
56
  return Func_void_java(__result)
58
57
  }
59
58
 
60
- @DoNotStrip
61
- @Keep
62
- abstract fun hasVoiceInputPermission(): Boolean
63
-
64
- @DoNotStrip
65
- @Keep
66
- abstract fun requestVoiceInputPermission(): Promise<Boolean>
67
-
68
- @DoNotStrip
69
- @Keep
70
- abstract fun startVoiceInput(silenceThresholdMs: Double?, maxDurationMs: Double?, listeningText: String?): Promise<ArrayBuffer>
71
-
72
- @DoNotStrip
73
- @Keep
74
- abstract fun stopVoiceInput(): Unit
75
-
76
59
  @DoNotStrip
77
60
  @Keep
78
61
  abstract fun setRootTemplate(templateId: String): Promise<Unit>