@gmessier/nitro-speech 0.4.2 → 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.
- package/README.md +19 -7
- package/android/src/main/java/com/margelo/nitro/nitrospeech/recognizer/AudioPermissionRequester.kt +12 -6
- package/android/src/main/java/com/margelo/nitro/nitrospeech/recognizer/HybridRecognizer.kt +57 -39
- package/ios/Audio/AudioLevelTracker.swift +1 -1
- package/ios/Coordinator.swift +1 -0
- package/ios/Engines/AnalyzerEngine.swift +11 -7
- package/ios/Engines/RecognizerEngine.swift +140 -82
- package/ios/Engines/SFSpeechEngine.swift +7 -3
- package/ios/HybridRecognizer.swift +49 -8
- package/ios/Shared/AutoStopper.swift +1 -1
- package/ios/Shared/Permissions.swift +12 -47
- package/ios/Shared/Utils.swift +2 -1
- package/lib/Recognizer/methods.d.ts +10 -10
- package/lib/Recognizer/methods.js +2 -2
- package/lib/Recognizer/types.d.ts +2 -1
- package/lib/index.d.ts +1 -1
- package/lib/specs/Recognizer.nitro.d.ts +2 -1
- package/lib/specs/SpeechRecognitionConfig.d.ts +7 -3
- package/lib/specs/SpeechRecognitionPrewarm.d.ts +10 -0
- package/lib/specs/SpeechRecognitionPrewarm.js +1 -0
- package/nitrogen/generated/android/c++/JHybridRecognizerSpec.cpp +7 -3
- package/nitrogen/generated/android/c++/JHybridRecognizerSpec.hpp +1 -1
- package/nitrogen/generated/android/c++/JIosPreset.hpp +3 -0
- package/nitrogen/generated/android/c++/JSpeechRecognitionPrewarm.hpp +57 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitrospeech/HybridRecognizerSpec.kt +1 -1
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitrospeech/IosPreset.kt +2 -1
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitrospeech/SpeechRecognitionPrewarm.kt +51 -0
- package/nitrogen/generated/ios/NitroSpeech-Swift-Cxx-Bridge.hpp +18 -0
- package/nitrogen/generated/ios/NitroSpeech-Swift-Cxx-Umbrella.hpp +3 -0
- package/nitrogen/generated/ios/c++/HybridRecognizerSpecSwift.hpp +5 -2
- package/nitrogen/generated/ios/swift/HybridRecognizerSpec.swift +1 -1
- package/nitrogen/generated/ios/swift/HybridRecognizerSpec_cxx.swift +2 -2
- package/nitrogen/generated/ios/swift/IosPreset.swift +4 -0
- package/nitrogen/generated/ios/swift/SpeechRecognitionPrewarm.swift +42 -0
- package/nitrogen/generated/shared/c++/HybridRecognizerSpec.hpp +4 -1
- package/nitrogen/generated/shared/c++/IosPreset.hpp +4 -0
- package/nitrogen/generated/shared/c++/SpeechRecognitionPrewarm.hpp +83 -0
- package/package.json +1 -1
- package/src/Recognizer/methods.ts +38 -31
- package/src/Recognizer/types.ts +2 -0
- package/src/index.ts +1 -0
- package/src/specs/Recognizer.nitro.ts +5 -1
- package/src/specs/SpeechRecognitionConfig.ts +7 -3
- package/src/specs/SpeechRecognitionPrewarm.ts +10 -0
|
@@ -1,16 +1,22 @@
|
|
|
1
1
|
import Foundation
|
|
2
2
|
import NitroModules
|
|
3
|
+
import AVFoundation
|
|
3
4
|
|
|
4
5
|
class HybridRecognizer: HybridRecognizerSpec {
|
|
6
|
+
var prewarmOptions: SpeechRecognitionPrewarm?
|
|
5
7
|
var config: SpeechRecognitionConfig?
|
|
8
|
+
var hardwareFormat: AVAudioFormat?
|
|
6
9
|
|
|
7
10
|
var onReadyForSpeech: (() -> Void)?
|
|
8
11
|
var onRecordingStopped: (() -> Void)?
|
|
9
12
|
var onResult: (([String]) -> Void)?
|
|
13
|
+
var onResultFallback: (([String]) -> Void)?
|
|
10
14
|
var onAutoFinishProgress: ((Double) -> Void)?
|
|
15
|
+
var onAutoFinishProgressFallback: ((Double) -> Void)?
|
|
11
16
|
var onError: ((String) -> Void)?
|
|
12
17
|
var onPermissionDenied: (() -> Void)?
|
|
13
18
|
var onVolumeChange: ((VolumeChangeEvent) -> Void)?
|
|
19
|
+
var onVolumeChangeFallback: ((VolumeChangeEvent) -> Void)?
|
|
14
20
|
|
|
15
21
|
private let coordinator = Coordinator()
|
|
16
22
|
private var paramsHash: String?
|
|
@@ -24,12 +30,18 @@ class HybridRecognizer: HybridRecognizerSpec {
|
|
|
24
30
|
private let lg = Lg(prefix: "HybridRecognizer")
|
|
25
31
|
|
|
26
32
|
@discardableResult
|
|
27
|
-
func prewarm(
|
|
33
|
+
func prewarm(
|
|
34
|
+
defaultParams: SpeechRecognitionConfig?,
|
|
35
|
+
options: SpeechRecognitionPrewarm?
|
|
36
|
+
) -> Promise<Void> {
|
|
37
|
+
prewarmOptions = options
|
|
28
38
|
return Promise.async(.userInitiated) { [weak self] in
|
|
39
|
+
// Ignore when standalone prewarm triggered for active session
|
|
40
|
+
guard self?.engine?.isActive != true else { return }
|
|
29
41
|
// Ensure correct engine is selected based on params and ios version
|
|
30
42
|
await self?.ensureEngine(params: defaultParams)
|
|
31
43
|
// try to preload assets and check if speech engine is available on OS level
|
|
32
|
-
await self?.engine?.prewarm(for: .prewarm)
|
|
44
|
+
await self?.engine?.prewarm(for: .prewarm, options)
|
|
33
45
|
}
|
|
34
46
|
}
|
|
35
47
|
|
|
@@ -37,7 +49,7 @@ class HybridRecognizer: HybridRecognizerSpec {
|
|
|
37
49
|
Task {
|
|
38
50
|
// Ensure correct engine is selected based on params and ios version
|
|
39
51
|
await ensureEngine(params: params)
|
|
40
|
-
engine?.start()
|
|
52
|
+
await engine?.start()
|
|
41
53
|
}
|
|
42
54
|
}
|
|
43
55
|
|
|
@@ -108,6 +120,8 @@ class HybridRecognizer: HybridRecognizerSpec {
|
|
|
108
120
|
|
|
109
121
|
protocol RecognizerDelegate: AnyObject {
|
|
110
122
|
var config: SpeechRecognitionConfig? { get }
|
|
123
|
+
var hardwareFormat: AVAudioFormat? { get }
|
|
124
|
+
func setHardwareFormat(format: AVAudioFormat)
|
|
111
125
|
func softlyUpdateConfig(newConfig: MutableSpeechRecognitionConfig?)
|
|
112
126
|
func reselectEngine(forPrewarm: Bool)
|
|
113
127
|
func readyForSpeech()
|
|
@@ -120,6 +134,9 @@ protocol RecognizerDelegate: AnyObject {
|
|
|
120
134
|
}
|
|
121
135
|
|
|
122
136
|
extension HybridRecognizer: RecognizerDelegate {
|
|
137
|
+
func setHardwareFormat(format: AVAudioFormat) {
|
|
138
|
+
hardwareFormat = format
|
|
139
|
+
}
|
|
123
140
|
func softlyUpdateConfig(newConfig: MutableSpeechRecognitionConfig?) {
|
|
124
141
|
if let newConfig {
|
|
125
142
|
config = SpeechRecognitionConfig(
|
|
@@ -154,12 +171,29 @@ extension HybridRecognizer: RecognizerDelegate {
|
|
|
154
171
|
|
|
155
172
|
func result(batches: [String]) {
|
|
156
173
|
self.lg.log("[onResult] \(batches)")
|
|
157
|
-
|
|
174
|
+
if onResult != nil {
|
|
175
|
+
onResultFallback = onResult
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
if (onResultFallback == nil) {
|
|
179
|
+
self.lg.log("onResultFallback -> nil")
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
onResultFallback?(batches)
|
|
158
183
|
}
|
|
159
184
|
|
|
160
185
|
func autoFinishProgress(timeLeftMs: Double) {
|
|
161
186
|
self.lg.log("[onAutoFinishProgress] \(timeLeftMs)ms")
|
|
162
|
-
|
|
187
|
+
|
|
188
|
+
if onAutoFinishProgress != nil {
|
|
189
|
+
onAutoFinishProgressFallback = onAutoFinishProgress
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
if (onAutoFinishProgressFallback == nil) {
|
|
193
|
+
self.lg.log("onAutoFinishProgressFallback -> nil")
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
onAutoFinishProgressFallback?(timeLeftMs)
|
|
163
197
|
}
|
|
164
198
|
|
|
165
199
|
func error(message: String) {
|
|
@@ -173,8 +207,15 @@ extension HybridRecognizer: RecognizerDelegate {
|
|
|
173
207
|
}
|
|
174
208
|
|
|
175
209
|
func volumeChange(event: VolumeChangeEvent) {
|
|
176
|
-
|
|
177
|
-
|
|
210
|
+
if onVolumeChange != nil {
|
|
211
|
+
onVolumeChangeFallback = onVolumeChange
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
if (onVolumeChangeFallback == nil) {
|
|
215
|
+
self.lg.log("onVolumeChangeFallback -> nil")
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
onVolumeChangeFallback?(event)
|
|
178
219
|
}
|
|
179
220
|
|
|
180
221
|
func reselectEngine(forPrewarm: Bool) {
|
|
@@ -184,7 +225,7 @@ extension HybridRecognizer: RecognizerDelegate {
|
|
|
184
225
|
engine = nil
|
|
185
226
|
// Try to prewarm with another candidate
|
|
186
227
|
if forPrewarm {
|
|
187
|
-
self.prewarm(defaultParams: config)
|
|
228
|
+
self.prewarm(defaultParams: config, options: prewarmOptions)
|
|
188
229
|
} else {
|
|
189
230
|
// Try to start with another candidate
|
|
190
231
|
self.startListening(params: config)
|
|
@@ -5,7 +5,7 @@ final class AutoStopper {
|
|
|
5
5
|
private static let defaultProgressIntervalMs = 1000.0
|
|
6
6
|
private static let minProgressIntervalMs = 50.0
|
|
7
7
|
|
|
8
|
-
private let lg = Lg(prefix: "AutoStopper", disable:
|
|
8
|
+
private let lg = Lg(prefix: "AutoStopper", disable: true)
|
|
9
9
|
|
|
10
10
|
private let queue = DispatchQueue(label: "com.margelo.nitrospeech.autostopper")
|
|
11
11
|
|
|
@@ -2,58 +2,23 @@ import Foundation
|
|
|
2
2
|
import Speech
|
|
3
3
|
import AVFoundation
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
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
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
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
|
}
|
package/ios/Shared/Utils.swift
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
export declare const recognizerPrewarm:
|
|
3
|
-
export declare const recognizerStartListening:
|
|
4
|
-
export declare const recognizerStopListening:
|
|
5
|
-
export declare const recognizerResetAutoFinishTime:
|
|
6
|
-
export declare const recognizerAddAutoFinishTime:
|
|
7
|
-
export declare const recognizerUpdateConfig:
|
|
8
|
-
export declare const recognizerGetIsActive:
|
|
9
|
-
export declare const recognizerGetVoiceInputVolume:
|
|
10
|
-
export declare const recognizerGetSupportedLocalesIOS:
|
|
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
|
*
|
|
@@ -22,7 +22,7 @@ interface ParamsAndroid {
|
|
|
22
22
|
*/
|
|
23
23
|
androidDisableBatchHandling?: boolean;
|
|
24
24
|
}
|
|
25
|
-
type IosPreset = 'shortform' | 'general';
|
|
25
|
+
type IosPreset = 'shortform' | 'general' | 'speed';
|
|
26
26
|
interface ParamsIOS {
|
|
27
27
|
/**
|
|
28
28
|
* Add punctuation to speech recognition results
|
|
@@ -33,9 +33,13 @@ interface ParamsIOS {
|
|
|
33
33
|
*/
|
|
34
34
|
iosAddPunctuation?: boolean;
|
|
35
35
|
/**
|
|
36
|
-
* `"shortForm"` -
|
|
36
|
+
* `"shortForm"` - For a short phrase or sentence, also disables punctuation
|
|
37
37
|
*
|
|
38
|
-
* `"
|
|
38
|
+
* `"speed"` - Gives priority to speed over accuracy
|
|
39
|
+
*
|
|
40
|
+
* `"general"` - For longer speeches, more accurate but delayed response
|
|
41
|
+
*
|
|
42
|
+
* @note preset may be overridden by other properties
|
|
39
43
|
*
|
|
40
44
|
* @since iOS 26.0+
|
|
41
45
|
*
|
|
@@ -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;
|
|
@@ -48,6 +48,9 @@ namespace margelo::nitro::nitrospeech {
|
|
|
48
48
|
case IosPreset::GENERAL:
|
|
49
49
|
static const auto fieldGENERAL = clazz->getStaticField<JIosPreset>("GENERAL");
|
|
50
50
|
return clazz->getStaticFieldValue(fieldGENERAL);
|
|
51
|
+
case IosPreset::SPEED:
|
|
52
|
+
static const auto fieldSPEED = clazz->getStaticField<JIosPreset>("SPEED");
|
|
53
|
+
return clazz->getStaticFieldValue(fieldSPEED);
|
|
51
54
|
default:
|
|
52
55
|
std::string stringValue = std::to_string(static_cast<int>(value));
|
|
53
56
|
throw std::invalid_argument("Invalid enum value (" + stringValue + "!");
|
|
@@ -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
|
package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitrospeech/HybridRecognizerSpec.kt
CHANGED
|
@@ -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
|
package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitrospeech/SpeechRecognitionPrewarm.kt
ADDED
|
@@ -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)
|
|
@@ -21,6 +21,8 @@ public extension IosPreset {
|
|
|
21
21
|
self = .shortform
|
|
22
22
|
case "general":
|
|
23
23
|
self = .general
|
|
24
|
+
case "speed":
|
|
25
|
+
self = .speed
|
|
24
26
|
default:
|
|
25
27
|
return nil
|
|
26
28
|
}
|
|
@@ -35,6 +37,8 @@ public extension IosPreset {
|
|
|
35
37
|
return "shortform"
|
|
36
38
|
case .general:
|
|
37
39
|
return "general"
|
|
40
|
+
case .speed:
|
|
41
|
+
return "speed"
|
|
38
42
|
}
|
|
39
43
|
}
|
|
40
44
|
}
|