@gmessier/nitro-speech 0.4.3 → 0.4.4

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 (36) hide show
  1. package/README.md +16 -4
  2. package/android/src/main/java/com/margelo/nitro/nitrospeech/recognizer/AudioPermissionRequester.kt +12 -6
  3. package/android/src/main/java/com/margelo/nitro/nitrospeech/recognizer/HybridRecognizer.kt +57 -39
  4. package/ios/Engines/AnalyzerEngine.swift +11 -7
  5. package/ios/Engines/RecognizerEngine.swift +140 -82
  6. package/ios/Engines/SFSpeechEngine.swift +7 -3
  7. package/ios/HybridRecognizer.swift +18 -5
  8. package/ios/Shared/Permissions.swift +12 -47
  9. package/lib/Recognizer/methods.d.ts +10 -10
  10. package/lib/Recognizer/methods.js +2 -2
  11. package/lib/Recognizer/types.d.ts +2 -1
  12. package/lib/index.d.ts +1 -1
  13. package/lib/specs/Recognizer.nitro.d.ts +2 -1
  14. package/lib/specs/SpeechRecognitionConfig.d.ts +2 -0
  15. package/lib/specs/SpeechRecognitionPrewarm.d.ts +10 -0
  16. package/lib/specs/SpeechRecognitionPrewarm.js +1 -0
  17. package/nitrogen/generated/android/c++/JHybridRecognizerSpec.cpp +7 -3
  18. package/nitrogen/generated/android/c++/JHybridRecognizerSpec.hpp +1 -1
  19. package/nitrogen/generated/android/c++/JSpeechRecognitionPrewarm.hpp +57 -0
  20. package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitrospeech/HybridRecognizerSpec.kt +1 -1
  21. package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitrospeech/SpeechRecognitionPrewarm.kt +51 -0
  22. package/nitrogen/generated/ios/NitroSpeech-Swift-Cxx-Bridge.hpp +18 -0
  23. package/nitrogen/generated/ios/NitroSpeech-Swift-Cxx-Umbrella.hpp +3 -0
  24. package/nitrogen/generated/ios/c++/HybridRecognizerSpecSwift.hpp +5 -2
  25. package/nitrogen/generated/ios/swift/HybridRecognizerSpec.swift +1 -1
  26. package/nitrogen/generated/ios/swift/HybridRecognizerSpec_cxx.swift +2 -2
  27. package/nitrogen/generated/ios/swift/SpeechRecognitionPrewarm.swift +42 -0
  28. package/nitrogen/generated/shared/c++/HybridRecognizerSpec.hpp +4 -1
  29. package/nitrogen/generated/shared/c++/SpeechRecognitionPrewarm.hpp +83 -0
  30. package/package.json +1 -1
  31. package/src/Recognizer/methods.ts +38 -31
  32. package/src/Recognizer/types.ts +2 -0
  33. package/src/index.ts +1 -0
  34. package/src/specs/Recognizer.nitro.ts +5 -1
  35. package/src/specs/SpeechRecognitionConfig.ts +2 -0
  36. package/src/specs/SpeechRecognitionPrewarm.ts +10 -0
@@ -2,58 +2,23 @@ import Foundation
2
2
  import Speech
3
3
  import AVFoundation
4
4
 
5
- final class Permissions {
6
- private let onGranted: () async -> Void
7
- private let onDenied: (() -> Void)?
8
- private let onError: ((String) -> Void)?
9
-
10
- init(
11
- onGranted: @escaping () async -> Void,
12
- onDenied: (() -> Void)?,
13
- onError: ((String) -> Void)?
14
- ) {
15
- self.onGranted = onGranted
16
- self.onDenied = onDenied
17
- self.onError = onError
18
- }
19
-
20
- private func requestMicrophonePermission() async {
21
- // Request permission to record.
22
- if #available(iOS 17.0, *) {
23
- if await AVAudioApplication.requestRecordPermission() {
24
- await self.onGranted()
25
- return
26
- }
27
- self.onDenied?()
28
- return
29
- }
30
- AVAudioSession.sharedInstance().requestRecordPermission { [weak self] granted in
31
- Task { @MainActor in
32
- guard let self else { return }
33
- if granted {
34
- await self.onGranted()
35
- return
36
- }
37
- self.onDenied?()
5
+ enum Permissions {
6
+ static func requestAuthorization() async -> SFSpeechRecognizerAuthorizationStatus {
7
+ return await withCheckedContinuation { continuation in
8
+ SFSpeechRecognizer.requestAuthorization { authStatus in
9
+ continuation.resume(returning: authStatus)
38
10
  }
39
11
  }
40
12
  }
41
13
 
42
- func requestAuthorization() {
43
- SFSpeechRecognizer.requestAuthorization { authStatus in
44
- Task { @MainActor in
45
- switch authStatus {
46
- case .authorized:
47
- await self.requestMicrophonePermission()
48
- case .denied, .restricted:
49
- self.onDenied?()
50
- case .notDetermined:
51
- self.onError?("Speech recognition not determined")
52
- @unknown default:
53
- self.onError?("Unknown authorization status")
54
- }
14
+ static func requestMicrophonePermission() async -> Bool {
15
+ if #available(iOS 17.0, *) {
16
+ return await AVAudioApplication.requestRecordPermission()
17
+ }
18
+ return await withCheckedContinuation { continuation in
19
+ AVAudioSession.sharedInstance().requestRecordPermission { granted in
20
+ continuation.resume(returning: granted)
55
21
  }
56
22
  }
57
23
  }
58
-
59
24
  }
@@ -1,10 +1,10 @@
1
- import type { MutableSpeechRecognitionConfig, SpeechRecognitionConfig } from './types';
2
- export declare const recognizerPrewarm: (params?: SpeechRecognitionConfig) => Promise<void>;
3
- export declare const recognizerStartListening: (params?: SpeechRecognitionConfig) => void;
4
- export declare const recognizerStopListening: () => void;
5
- export declare const recognizerResetAutoFinishTime: () => void;
6
- export declare const recognizerAddAutoFinishTime: (additionalTimeMs?: number) => void;
7
- export declare const recognizerUpdateConfig: (newConfig?: MutableSpeechRecognitionConfig, resetAutoFinishTime?: boolean) => void;
8
- export declare const recognizerGetIsActive: () => boolean;
9
- export declare const recognizerGetVoiceInputVolume: () => import("./types").VolumeChangeEvent;
10
- export declare const recognizerGetSupportedLocalesIOS: () => string[];
1
+ import type { RecognizerMethods } from './types';
2
+ export declare const recognizerPrewarm: RecognizerMethods['prewarm'];
3
+ export declare const recognizerStartListening: RecognizerMethods['startListening'];
4
+ export declare const recognizerStopListening: RecognizerMethods['stopListening'];
5
+ export declare const recognizerResetAutoFinishTime: RecognizerMethods['resetAutoFinishTime'];
6
+ export declare const recognizerAddAutoFinishTime: RecognizerMethods['addAutoFinishTime'];
7
+ export declare const recognizerUpdateConfig: RecognizerMethods['updateConfig'];
8
+ export declare const recognizerGetIsActive: RecognizerMethods['getIsActive'];
9
+ export declare const recognizerGetVoiceInputVolume: RecognizerMethods['getVoiceInputVolume'];
10
+ export declare const recognizerGetSupportedLocalesIOS: RecognizerMethods['getSupportedLocalesIOS'];
@@ -1,7 +1,7 @@
1
1
  import { SpeechRecognizer } from './SpeechRecognizer';
2
- export const recognizerPrewarm = (params) => {
2
+ export const recognizerPrewarm = (params, options) => {
3
3
  'worklet';
4
- return SpeechRecognizer.prewarm(params);
4
+ return SpeechRecognizer.prewarm(params, options);
5
5
  };
6
6
  export const recognizerStartListening = (params) => {
7
7
  'worklet';
@@ -1,6 +1,7 @@
1
1
  import type { Recognizer as RecognizerSpec } from '../specs/Recognizer.nitro';
2
2
  import type { MutableSpeechRecognitionConfig, SpeechRecognitionConfig } from '../specs/SpeechRecognitionConfig';
3
3
  import type { VolumeChangeEvent } from '../specs/VolumeChangeEvent';
4
+ import type { SpeechRecognitionPrewarm } from '../specs/SpeechRecognitionPrewarm';
4
5
  type RecognizerCallbacks = Pick<RecognizerSpec, 'onReadyForSpeech' | 'onRecordingStopped' | 'onResult' | 'onAutoFinishProgress' | 'onError' | 'onPermissionDenied' | 'onVolumeChange'>;
5
6
  type RecognizerMethods = Pick<RecognizerSpec, 'prewarm' | 'startListening' | 'stopListening' | 'resetAutoFinishTime' | 'addAutoFinishTime' | 'updateConfig' | 'getIsActive' | 'getVoiceInputVolume' | 'getSupportedLocalesIOS'>;
6
- export type { RecognizerSpec, SpeechRecognitionConfig, MutableSpeechRecognitionConfig, VolumeChangeEvent, RecognizerCallbacks, RecognizerMethods, };
7
+ export type { RecognizerSpec, SpeechRecognitionConfig, SpeechRecognitionPrewarm, MutableSpeechRecognitionConfig, VolumeChangeEvent, RecognizerCallbacks, RecognizerMethods, };
package/lib/index.d.ts CHANGED
@@ -4,4 +4,4 @@ export { useRecognizerIsActive, speechRecognizerActiveStateHandler, } from './Re
4
4
  export { SpeechRecognizer } from './Recognizer/SpeechRecognizer';
5
5
  export { RecognizerRef } from './Recognizer/RecognizerRef';
6
6
  export { NitroSpeech } from './NitroSpeech';
7
- export { type RecognizerSpec, type SpeechRecognitionConfig, type MutableSpeechRecognitionConfig, type VolumeChangeEvent, type RecognizerCallbacks, type RecognizerMethods, } from './Recognizer/types';
7
+ export { type RecognizerSpec, type SpeechRecognitionConfig, type SpeechRecognitionPrewarm, type MutableSpeechRecognitionConfig, type VolumeChangeEvent, type RecognizerCallbacks, type RecognizerMethods, } from './Recognizer/types';
@@ -1,6 +1,7 @@
1
1
  import type { HybridObject } from 'react-native-nitro-modules';
2
2
  import type { MutableSpeechRecognitionConfig, SpeechRecognitionConfig } from './SpeechRecognitionConfig';
3
3
  import type { VolumeChangeEvent } from './VolumeChangeEvent';
4
+ import type { SpeechRecognitionPrewarm } from './SpeechRecognitionPrewarm';
4
5
  export interface Recognizer extends HybridObject<{
5
6
  ios: 'swift';
6
7
  android: 'kotlin';
@@ -27,7 +28,7 @@ export interface Recognizer extends HybridObject<{
27
28
  * });
28
29
  * ```
29
30
  */
30
- prewarm(defaultParams?: SpeechRecognitionConfig): Promise<void>;
31
+ prewarm(defaultParams?: SpeechRecognitionConfig, options?: SpeechRecognitionPrewarm): Promise<void>;
31
32
  /**
32
33
  * Try to start the speech recognition.
33
34
  *
@@ -39,6 +39,8 @@ interface ParamsIOS {
39
39
  *
40
40
  * `"general"` - For longer speeches, more accurate but delayed response
41
41
  *
42
+ * @note preset may be overridden by other properties
43
+ *
42
44
  * @since iOS 26.0+
43
45
  *
44
46
  * @default "general"
@@ -0,0 +1,10 @@
1
+ export interface SpeechRecognitionPrewarm {
2
+ /**
3
+ * If permission is not granted, will request it.
4
+ *
5
+ * if permission is set, does nothing.
6
+ *
7
+ * @default true
8
+ */
9
+ requestPermission?: boolean;
10
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -15,6 +15,8 @@ namespace margelo::nitro::nitrospeech { struct SpeechRecognitionConfig; }
15
15
  namespace margelo::nitro::nitrospeech { enum class HapticFeedbackStyle; }
16
16
  // Forward declaration of `IosPreset` to properly resolve imports.
17
17
  namespace margelo::nitro::nitrospeech { enum class IosPreset; }
18
+ // Forward declaration of `SpeechRecognitionPrewarm` to properly resolve imports.
19
+ namespace margelo::nitro::nitrospeech { struct SpeechRecognitionPrewarm; }
18
20
  // Forward declaration of `MutableSpeechRecognitionConfig` to properly resolve imports.
19
21
  namespace margelo::nitro::nitrospeech { struct MutableSpeechRecognitionConfig; }
20
22
 
@@ -39,6 +41,8 @@ namespace margelo::nitro::nitrospeech { struct MutableSpeechRecognitionConfig; }
39
41
  #include "JHapticFeedbackStyle.hpp"
40
42
  #include "IosPreset.hpp"
41
43
  #include "JIosPreset.hpp"
44
+ #include "SpeechRecognitionPrewarm.hpp"
45
+ #include "JSpeechRecognitionPrewarm.hpp"
42
46
  #include "MutableSpeechRecognitionConfig.hpp"
43
47
  #include "JMutableSpeechRecognitionConfig.hpp"
44
48
 
@@ -193,9 +197,9 @@ namespace margelo::nitro::nitrospeech {
193
197
  }
194
198
 
195
199
  // Methods
196
- std::shared_ptr<Promise<void>> JHybridRecognizerSpec::prewarm(const std::optional<SpeechRecognitionConfig>& defaultParams) {
197
- static const auto method = _javaPart->javaClassStatic()->getMethod<jni::local_ref<JPromise::javaobject>(jni::alias_ref<JSpeechRecognitionConfig> /* defaultParams */)>("prewarm");
198
- auto __result = method(_javaPart, defaultParams.has_value() ? JSpeechRecognitionConfig::fromCpp(defaultParams.value()) : nullptr);
200
+ std::shared_ptr<Promise<void>> JHybridRecognizerSpec::prewarm(const std::optional<SpeechRecognitionConfig>& defaultParams, const std::optional<SpeechRecognitionPrewarm>& options) {
201
+ static const auto method = _javaPart->javaClassStatic()->getMethod<jni::local_ref<JPromise::javaobject>(jni::alias_ref<JSpeechRecognitionConfig> /* defaultParams */, jni::alias_ref<JSpeechRecognitionPrewarm> /* options */)>("prewarm");
202
+ auto __result = method(_javaPart, defaultParams.has_value() ? JSpeechRecognitionConfig::fromCpp(defaultParams.value()) : nullptr, options.has_value() ? JSpeechRecognitionPrewarm::fromCpp(options.value()) : nullptr);
199
203
  return [&]() {
200
204
  auto __promise = Promise<void>::create();
201
205
  __result->cthis()->addOnResolvedListener([=](const jni::alias_ref<jni::JObject>& /* unit */) {
@@ -67,7 +67,7 @@ namespace margelo::nitro::nitrospeech {
67
67
 
68
68
  public:
69
69
  // Methods
70
- std::shared_ptr<Promise<void>> prewarm(const std::optional<SpeechRecognitionConfig>& defaultParams) override;
70
+ std::shared_ptr<Promise<void>> prewarm(const std::optional<SpeechRecognitionConfig>& defaultParams, const std::optional<SpeechRecognitionPrewarm>& options) override;
71
71
  void startListening(const std::optional<SpeechRecognitionConfig>& params) override;
72
72
  void stopListening() override;
73
73
  void resetAutoFinishTime() override;
@@ -0,0 +1,57 @@
1
+ ///
2
+ /// JSpeechRecognitionPrewarm.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 "SpeechRecognitionPrewarm.hpp"
12
+
13
+ #include <optional>
14
+
15
+ namespace margelo::nitro::nitrospeech {
16
+
17
+ using namespace facebook;
18
+
19
+ /**
20
+ * The C++ JNI bridge between the C++ struct "SpeechRecognitionPrewarm" and the the Kotlin data class "SpeechRecognitionPrewarm".
21
+ */
22
+ struct JSpeechRecognitionPrewarm final: public jni::JavaClass<JSpeechRecognitionPrewarm> {
23
+ public:
24
+ static constexpr auto kJavaDescriptor = "Lcom/margelo/nitro/nitrospeech/SpeechRecognitionPrewarm;";
25
+
26
+ public:
27
+ /**
28
+ * Convert this Java/Kotlin-based struct to the C++ struct SpeechRecognitionPrewarm by copying all values to C++.
29
+ */
30
+ [[maybe_unused]]
31
+ [[nodiscard]]
32
+ SpeechRecognitionPrewarm toCpp() const {
33
+ static const auto clazz = javaClassStatic();
34
+ static const auto fieldRequestPermission = clazz->getField<jni::JBoolean>("requestPermission");
35
+ jni::local_ref<jni::JBoolean> requestPermission = this->getFieldValue(fieldRequestPermission);
36
+ return SpeechRecognitionPrewarm(
37
+ requestPermission != nullptr ? std::make_optional(static_cast<bool>(requestPermission->value())) : std::nullopt
38
+ );
39
+ }
40
+
41
+ public:
42
+ /**
43
+ * Create a Java/Kotlin-based struct by copying all values from the given C++ struct to Java.
44
+ */
45
+ [[maybe_unused]]
46
+ static jni::local_ref<JSpeechRecognitionPrewarm::javaobject> fromCpp(const SpeechRecognitionPrewarm& value) {
47
+ using JSignature = JSpeechRecognitionPrewarm(jni::alias_ref<jni::JBoolean>);
48
+ static const auto clazz = javaClassStatic();
49
+ static const auto create = clazz->getStaticMethod<JSignature>("fromCpp");
50
+ return create(
51
+ clazz,
52
+ value.requestPermission.has_value() ? jni::JBoolean::valueOf(value.requestPermission.value()) : nullptr
53
+ );
54
+ }
55
+ };
56
+
57
+ } // namespace margelo::nitro::nitrospeech
@@ -127,7 +127,7 @@ abstract class HybridRecognizerSpec: HybridObject() {
127
127
  // Methods
128
128
  @DoNotStrip
129
129
  @Keep
130
- abstract fun prewarm(defaultParams: SpeechRecognitionConfig?): Promise<Unit>
130
+ abstract fun prewarm(defaultParams: SpeechRecognitionConfig?, options: SpeechRecognitionPrewarm?): Promise<Unit>
131
131
 
132
132
  @DoNotStrip
133
133
  @Keep
@@ -0,0 +1,51 @@
1
+ ///
2
+ /// SpeechRecognitionPrewarm.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.nitrospeech
9
+
10
+ import androidx.annotation.Keep
11
+ import com.facebook.proguard.annotations.DoNotStrip
12
+ import java.util.Objects
13
+
14
+
15
+ /**
16
+ * Represents the JavaScript object/struct "SpeechRecognitionPrewarm".
17
+ */
18
+ @DoNotStrip
19
+ @Keep
20
+ data class SpeechRecognitionPrewarm(
21
+ @DoNotStrip
22
+ @Keep
23
+ val requestPermission: Boolean?
24
+ ) {
25
+ /* primary constructor */
26
+
27
+ override fun equals(other: Any?): Boolean {
28
+ if (this === other) return true
29
+ if (other !is SpeechRecognitionPrewarm) return false
30
+ return Objects.deepEquals(this.requestPermission, other.requestPermission)
31
+ }
32
+
33
+ override fun hashCode(): Int {
34
+ return arrayOf(
35
+ requestPermission
36
+ ).contentDeepHashCode()
37
+ }
38
+
39
+ companion object {
40
+ /**
41
+ * Constructor called from C++
42
+ */
43
+ @DoNotStrip
44
+ @Keep
45
+ @Suppress("unused")
46
+ @JvmStatic
47
+ private fun fromCpp(requestPermission: Boolean?): SpeechRecognitionPrewarm {
48
+ return SpeechRecognitionPrewarm(requestPermission)
49
+ }
50
+ }
51
+ }
@@ -20,6 +20,8 @@ namespace margelo::nitro::nitrospeech { enum class IosPreset; }
20
20
  namespace margelo::nitro::nitrospeech { struct MutableSpeechRecognitionConfig; }
21
21
  // Forward declaration of `SpeechRecognitionConfig` to properly resolve imports.
22
22
  namespace margelo::nitro::nitrospeech { struct SpeechRecognitionConfig; }
23
+ // Forward declaration of `SpeechRecognitionPrewarm` to properly resolve imports.
24
+ namespace margelo::nitro::nitrospeech { struct SpeechRecognitionPrewarm; }
23
25
  // Forward declaration of `VolumeChangeEvent` to properly resolve imports.
24
26
  namespace margelo::nitro::nitrospeech { struct VolumeChangeEvent; }
25
27
 
@@ -36,6 +38,7 @@ namespace NitroSpeech { class HybridRecognizerSpec_cxx; }
36
38
  #include "IosPreset.hpp"
37
39
  #include "MutableSpeechRecognitionConfig.hpp"
38
40
  #include "SpeechRecognitionConfig.hpp"
41
+ #include "SpeechRecognitionPrewarm.hpp"
39
42
  #include "VolumeChangeEvent.hpp"
40
43
  #include <NitroModules/Promise.hpp>
41
44
  #include <NitroModules/PromiseHolder.hpp>
@@ -249,6 +252,21 @@ namespace margelo::nitro::nitrospeech::bridge::swift {
249
252
  return optional.value();
250
253
  }
251
254
 
255
+ // pragma MARK: std::optional<SpeechRecognitionPrewarm>
256
+ /**
257
+ * Specialized version of `std::optional<SpeechRecognitionPrewarm>`.
258
+ */
259
+ using std__optional_SpeechRecognitionPrewarm_ = std::optional<SpeechRecognitionPrewarm>;
260
+ inline std::optional<SpeechRecognitionPrewarm> create_std__optional_SpeechRecognitionPrewarm_(const SpeechRecognitionPrewarm& value) noexcept {
261
+ return std::optional<SpeechRecognitionPrewarm>(value);
262
+ }
263
+ inline bool has_value_std__optional_SpeechRecognitionPrewarm_(const std::optional<SpeechRecognitionPrewarm>& optional) noexcept {
264
+ return optional.has_value();
265
+ }
266
+ inline SpeechRecognitionPrewarm get_std__optional_SpeechRecognitionPrewarm_(const std::optional<SpeechRecognitionPrewarm>& optional) noexcept {
267
+ return optional.value();
268
+ }
269
+
252
270
  // pragma MARK: std::optional<MutableSpeechRecognitionConfig>
253
271
  /**
254
272
  * Specialized version of `std::optional<MutableSpeechRecognitionConfig>`.
@@ -20,6 +20,8 @@ namespace margelo::nitro::nitrospeech { enum class IosPreset; }
20
20
  namespace margelo::nitro::nitrospeech { struct MutableSpeechRecognitionConfig; }
21
21
  // Forward declaration of `SpeechRecognitionConfig` to properly resolve imports.
22
22
  namespace margelo::nitro::nitrospeech { struct SpeechRecognitionConfig; }
23
+ // Forward declaration of `SpeechRecognitionPrewarm` to properly resolve imports.
24
+ namespace margelo::nitro::nitrospeech { struct SpeechRecognitionPrewarm; }
23
25
  // Forward declaration of `VolumeChangeEvent` to properly resolve imports.
24
26
  namespace margelo::nitro::nitrospeech { struct VolumeChangeEvent; }
25
27
 
@@ -30,6 +32,7 @@ namespace margelo::nitro::nitrospeech { struct VolumeChangeEvent; }
30
32
  #include "IosPreset.hpp"
31
33
  #include "MutableSpeechRecognitionConfig.hpp"
32
34
  #include "SpeechRecognitionConfig.hpp"
35
+ #include "SpeechRecognitionPrewarm.hpp"
33
36
  #include "VolumeChangeEvent.hpp"
34
37
  #include <NitroModules/Promise.hpp>
35
38
  #include <NitroModules/Result.hpp>
@@ -20,6 +20,8 @@ namespace margelo::nitro::nitrospeech { struct SpeechRecognitionConfig; }
20
20
  namespace margelo::nitro::nitrospeech { enum class HapticFeedbackStyle; }
21
21
  // Forward declaration of `IosPreset` to properly resolve imports.
22
22
  namespace margelo::nitro::nitrospeech { enum class IosPreset; }
23
+ // Forward declaration of `SpeechRecognitionPrewarm` to properly resolve imports.
24
+ namespace margelo::nitro::nitrospeech { struct SpeechRecognitionPrewarm; }
23
25
  // Forward declaration of `MutableSpeechRecognitionConfig` to properly resolve imports.
24
26
  namespace margelo::nitro::nitrospeech { struct MutableSpeechRecognitionConfig; }
25
27
 
@@ -32,6 +34,7 @@ namespace margelo::nitro::nitrospeech { struct MutableSpeechRecognitionConfig; }
32
34
  #include "SpeechRecognitionConfig.hpp"
33
35
  #include "HapticFeedbackStyle.hpp"
34
36
  #include "IosPreset.hpp"
37
+ #include "SpeechRecognitionPrewarm.hpp"
35
38
  #include "MutableSpeechRecognitionConfig.hpp"
36
39
 
37
40
  #include "NitroSpeech-Swift-Cxx-Umbrella.hpp"
@@ -132,8 +135,8 @@ namespace margelo::nitro::nitrospeech {
132
135
 
133
136
  public:
134
137
  // Methods
135
- inline std::shared_ptr<Promise<void>> prewarm(const std::optional<SpeechRecognitionConfig>& defaultParams) override {
136
- auto __result = _swiftPart.prewarm(defaultParams);
138
+ inline std::shared_ptr<Promise<void>> prewarm(const std::optional<SpeechRecognitionConfig>& defaultParams, const std::optional<SpeechRecognitionPrewarm>& options) override {
139
+ auto __result = _swiftPart.prewarm(defaultParams, options);
137
140
  if (__result.hasError()) [[unlikely]] {
138
141
  std::rethrow_exception(__result.error());
139
142
  }
@@ -19,7 +19,7 @@ public protocol HybridRecognizerSpec_protocol: HybridObject {
19
19
  var onVolumeChange: ((_ event: VolumeChangeEvent) -> Void)? { get set }
20
20
 
21
21
  // Methods
22
- func prewarm(defaultParams: SpeechRecognitionConfig?) throws -> Promise<Void>
22
+ func prewarm(defaultParams: SpeechRecognitionConfig?, options: SpeechRecognitionPrewarm?) throws -> Promise<Void>
23
23
  func startListening(params: SpeechRecognitionConfig?) throws -> Void
24
24
  func stopListening() throws -> Void
25
25
  func resetAutoFinishTime() throws -> Void
@@ -353,9 +353,9 @@ open class HybridRecognizerSpec_cxx {
353
353
 
354
354
  // Methods
355
355
  @inline(__always)
356
- public final func prewarm(defaultParams: bridge.std__optional_SpeechRecognitionConfig_) -> bridge.Result_std__shared_ptr_Promise_void___ {
356
+ public final func prewarm(defaultParams: bridge.std__optional_SpeechRecognitionConfig_, options: bridge.std__optional_SpeechRecognitionPrewarm_) -> bridge.Result_std__shared_ptr_Promise_void___ {
357
357
  do {
358
- let __result = try self.__implementation.prewarm(defaultParams: defaultParams.value)
358
+ let __result = try self.__implementation.prewarm(defaultParams: defaultParams.value, options: options.value)
359
359
  let __resultCpp = { () -> bridge.std__shared_ptr_Promise_void__ in
360
360
  let __promise = bridge.create_std__shared_ptr_Promise_void__()
361
361
  let __promiseHolder = bridge.wrap_std__shared_ptr_Promise_void__(__promise)
@@ -0,0 +1,42 @@
1
+ ///
2
+ /// SpeechRecognitionPrewarm.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 `SpeechRecognitionPrewarm`, backed by a C++ struct.
12
+ */
13
+ public typealias SpeechRecognitionPrewarm = margelo.nitro.nitrospeech.SpeechRecognitionPrewarm
14
+
15
+ public extension SpeechRecognitionPrewarm {
16
+ private typealias bridge = margelo.nitro.nitrospeech.bridge.swift
17
+
18
+ /**
19
+ * Create a new instance of `SpeechRecognitionPrewarm`.
20
+ */
21
+ init(requestPermission: Bool?) {
22
+ self.init({ () -> bridge.std__optional_bool_ in
23
+ if let __unwrappedValue = requestPermission {
24
+ return bridge.create_std__optional_bool_(__unwrappedValue)
25
+ } else {
26
+ return .init()
27
+ }
28
+ }())
29
+ }
30
+
31
+ @inline(__always)
32
+ var requestPermission: Bool? {
33
+ return { () -> Bool? in
34
+ if bridge.has_value_std__optional_bool_(self.__requestPermission) {
35
+ let __unwrapped = bridge.get_std__optional_bool_(self.__requestPermission)
36
+ return __unwrapped
37
+ } else {
38
+ return nil
39
+ }
40
+ }()
41
+ }
42
+ }
@@ -17,6 +17,8 @@
17
17
  namespace margelo::nitro::nitrospeech { struct VolumeChangeEvent; }
18
18
  // Forward declaration of `SpeechRecognitionConfig` to properly resolve imports.
19
19
  namespace margelo::nitro::nitrospeech { struct SpeechRecognitionConfig; }
20
+ // Forward declaration of `SpeechRecognitionPrewarm` to properly resolve imports.
21
+ namespace margelo::nitro::nitrospeech { struct SpeechRecognitionPrewarm; }
20
22
  // Forward declaration of `MutableSpeechRecognitionConfig` to properly resolve imports.
21
23
  namespace margelo::nitro::nitrospeech { struct MutableSpeechRecognitionConfig; }
22
24
 
@@ -27,6 +29,7 @@ namespace margelo::nitro::nitrospeech { struct MutableSpeechRecognitionConfig; }
27
29
  #include "VolumeChangeEvent.hpp"
28
30
  #include <NitroModules/Promise.hpp>
29
31
  #include "SpeechRecognitionConfig.hpp"
32
+ #include "SpeechRecognitionPrewarm.hpp"
30
33
  #include "MutableSpeechRecognitionConfig.hpp"
31
34
 
32
35
  namespace margelo::nitro::nitrospeech {
@@ -73,7 +76,7 @@ namespace margelo::nitro::nitrospeech {
73
76
 
74
77
  public:
75
78
  // Methods
76
- virtual std::shared_ptr<Promise<void>> prewarm(const std::optional<SpeechRecognitionConfig>& defaultParams) = 0;
79
+ virtual std::shared_ptr<Promise<void>> prewarm(const std::optional<SpeechRecognitionConfig>& defaultParams, const std::optional<SpeechRecognitionPrewarm>& options) = 0;
77
80
  virtual void startListening(const std::optional<SpeechRecognitionConfig>& params) = 0;
78
81
  virtual void stopListening() = 0;
79
82
  virtual void resetAutoFinishTime() = 0;
@@ -0,0 +1,83 @@
1
+ ///
2
+ /// SpeechRecognitionPrewarm.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 <optional>
34
+
35
+ namespace margelo::nitro::nitrospeech {
36
+
37
+ /**
38
+ * A struct which can be represented as a JavaScript object (SpeechRecognitionPrewarm).
39
+ */
40
+ struct SpeechRecognitionPrewarm final {
41
+ public:
42
+ std::optional<bool> requestPermission SWIFT_PRIVATE;
43
+
44
+ public:
45
+ SpeechRecognitionPrewarm() = default;
46
+ explicit SpeechRecognitionPrewarm(std::optional<bool> requestPermission): requestPermission(requestPermission) {}
47
+
48
+ public:
49
+ friend bool operator==(const SpeechRecognitionPrewarm& lhs, const SpeechRecognitionPrewarm& rhs) = default;
50
+ };
51
+
52
+ } // namespace margelo::nitro::nitrospeech
53
+
54
+ namespace margelo::nitro {
55
+
56
+ // C++ SpeechRecognitionPrewarm <> JS SpeechRecognitionPrewarm (object)
57
+ template <>
58
+ struct JSIConverter<margelo::nitro::nitrospeech::SpeechRecognitionPrewarm> final {
59
+ static inline margelo::nitro::nitrospeech::SpeechRecognitionPrewarm fromJSI(jsi::Runtime& runtime, const jsi::Value& arg) {
60
+ jsi::Object obj = arg.asObject(runtime);
61
+ return margelo::nitro::nitrospeech::SpeechRecognitionPrewarm(
62
+ JSIConverter<std::optional<bool>>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "requestPermission")))
63
+ );
64
+ }
65
+ static inline jsi::Value toJSI(jsi::Runtime& runtime, const margelo::nitro::nitrospeech::SpeechRecognitionPrewarm& arg) {
66
+ jsi::Object obj(runtime);
67
+ obj.setProperty(runtime, PropNameIDCache::get(runtime, "requestPermission"), JSIConverter<std::optional<bool>>::toJSI(runtime, arg.requestPermission));
68
+ return obj;
69
+ }
70
+ static inline bool canConvert(jsi::Runtime& runtime, const jsi::Value& value) {
71
+ if (!value.isObject()) {
72
+ return false;
73
+ }
74
+ jsi::Object obj = value.getObject(runtime);
75
+ if (!nitro::isPlainObject(runtime, obj)) {
76
+ return false;
77
+ }
78
+ if (!JSIConverter<std::optional<bool>>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "requestPermission")))) return false;
79
+ return true;
80
+ }
81
+ };
82
+
83
+ } // namespace margelo::nitro
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gmessier/nitro-speech",
3
- "version": "0.4.3",
3
+ "version": "0.4.4",
4
4
  "description": "React Native Real-time Speech Recognition Library powered by Nitro Modules",
5
5
  "main": "./lib/index.js",
6
6
  "module": "./lib/index.js",