@gmessier/nitro-speech 0.3.3 → 0.4.0
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/LICENSE +21 -0
- package/README.md +165 -148
- package/android/build.gradle +0 -1
- package/android/src/main/cpp/cpp-adapter.cpp +5 -1
- package/android/src/main/java/com/margelo/nitro/nitrospeech/HybridNitroSpeech.kt +2 -0
- package/android/src/main/java/com/margelo/nitro/nitrospeech/recognizer/AutoStopper.kt +80 -16
- package/android/src/main/java/com/margelo/nitro/nitrospeech/recognizer/HybridRecognizer.kt +93 -20
- package/android/src/main/java/com/margelo/nitro/nitrospeech/recognizer/RecognitionListenerSession.kt +27 -15
- package/ios/{BufferUtil.swift → Audio/AudioBufferConverter.swift} +3 -34
- package/ios/Audio/AudioLevelTracker.swift +66 -0
- package/ios/Coordinator.swift +105 -0
- package/ios/Engines/AnalyzerEngine.swift +241 -0
- package/ios/Engines/DictationRuntime.swift +67 -0
- package/ios/Engines/RecognizerEngine.swift +312 -0
- package/ios/Engines/SFSpeechEngine.swift +119 -0
- package/ios/Engines/SpeechRuntime.swift +58 -0
- package/ios/Engines/TranscriberRuntimeProtocol.swift +21 -0
- package/ios/HybridNitroSpeech.swift +1 -10
- package/ios/HybridRecognizer.swift +135 -192
- package/ios/LocaleManager.swift +73 -0
- package/ios/{AppStateObserver.swift → Shared/AppStateObserver.swift} +1 -2
- package/ios/Shared/AutoStopper.swift +147 -0
- package/ios/Shared/HapticImpact.swift +24 -0
- package/ios/Shared/Log.swift +41 -0
- package/ios/Shared/Permissions.swift +59 -0
- package/ios/Shared/Utils.swift +58 -0
- package/lib/NitroSpeech.d.ts +2 -0
- package/lib/NitroSpeech.js +2 -0
- package/lib/Recognizer/RecognizerRef.d.ts +5 -0
- package/lib/Recognizer/RecognizerRef.js +13 -0
- package/lib/Recognizer/SpeechRecognizer.d.ts +8 -0
- package/lib/Recognizer/SpeechRecognizer.js +9 -0
- package/lib/Recognizer/methods.d.ts +8 -0
- package/lib/Recognizer/methods.js +29 -0
- package/lib/Recognizer/types.d.ts +6 -0
- package/lib/Recognizer/types.js +1 -0
- package/lib/Recognizer/useRecognizer.d.ts +16 -0
- package/lib/Recognizer/useRecognizer.js +71 -0
- package/lib/Recognizer/useVoiceInputVolume.d.ts +25 -0
- package/lib/Recognizer/useVoiceInputVolume.js +52 -0
- package/lib/index.d.ts +6 -0
- package/lib/index.js +6 -0
- package/lib/specs/NitroSpeech.nitro.d.ts +8 -0
- package/lib/specs/NitroSpeech.nitro.js +1 -0
- package/lib/specs/Recognizer.nitro.d.ts +95 -0
- package/lib/specs/Recognizer.nitro.js +1 -0
- package/lib/specs/SpeechRecognitionConfig.d.ts +162 -0
- package/lib/specs/SpeechRecognitionConfig.js +1 -0
- package/lib/specs/VolumeChangeEvent.d.ts +31 -0
- package/lib/specs/VolumeChangeEvent.js +1 -0
- package/nitro.json +0 -4
- package/nitrogen/generated/android/NitroSpeech+autolinking.cmake +2 -2
- package/nitrogen/generated/android/NitroSpeechOnLoad.cpp +4 -2
- package/nitrogen/generated/android/c++/JFunc_void_VolumeChangeEvent.hpp +78 -0
- package/nitrogen/generated/android/c++/JFunc_void_std__vector_std__string_.hpp +14 -14
- package/nitrogen/generated/android/c++/JHybridRecognizerSpec.cpp +68 -19
- package/nitrogen/generated/android/c++/JHybridRecognizerSpec.hpp +7 -4
- package/nitrogen/generated/android/c++/JIosPreset.hpp +58 -0
- package/nitrogen/generated/android/c++/JMutableSpeechRecognitionConfig.hpp +79 -0
- package/nitrogen/generated/android/c++/{JSpeechToTextParams.hpp → JSpeechRecognitionConfig.hpp} +48 -30
- package/nitrogen/generated/android/c++/JVolumeChangeEvent.hpp +65 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitrospeech/Func_void_VolumeChangeEvent.kt +80 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitrospeech/HybridRecognizerSpec.kt +18 -5
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitrospeech/IosPreset.kt +23 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitrospeech/MutableSpeechRecognitionConfig.kt +76 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitrospeech/SpeechRecognitionConfig.kt +121 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitrospeech/VolumeChangeEvent.kt +61 -0
- package/nitrogen/generated/ios/NitroSpeech-Swift-Cxx-Bridge.cpp +46 -30
- package/nitrogen/generated/ios/NitroSpeech-Swift-Cxx-Bridge.hpp +203 -70
- package/nitrogen/generated/ios/NitroSpeech-Swift-Cxx-Umbrella.hpp +13 -3
- package/nitrogen/generated/ios/c++/HybridRecognizerSpecSwift.hpp +41 -9
- package/nitrogen/generated/ios/swift/Func_void_VolumeChangeEvent.swift +46 -0
- package/nitrogen/generated/ios/swift/Func_void_std__exception_ptr.swift +46 -0
- package/nitrogen/generated/ios/swift/HybridRecognizerSpec.swift +6 -3
- package/nitrogen/generated/ios/swift/HybridRecognizerSpec_cxx.swift +66 -18
- package/nitrogen/generated/ios/swift/IosPreset.swift +40 -0
- package/nitrogen/generated/ios/swift/MutableSpeechRecognitionConfig.swift +118 -0
- package/nitrogen/generated/ios/swift/{SpeechToTextParams.swift → SpeechRecognitionConfig.swift} +108 -43
- package/nitrogen/generated/ios/swift/VolumeChangeEvent.swift +52 -0
- package/nitrogen/generated/shared/c++/HybridRecognizerSpec.cpp +4 -1
- package/nitrogen/generated/shared/c++/HybridRecognizerSpec.hpp +17 -7
- package/nitrogen/generated/shared/c++/IosPreset.hpp +76 -0
- package/nitrogen/generated/shared/c++/MutableSpeechRecognitionConfig.hpp +105 -0
- package/nitrogen/generated/shared/c++/{SpeechToTextParams.hpp → SpeechRecognitionConfig.hpp} +39 -20
- package/nitrogen/generated/shared/c++/VolumeChangeEvent.hpp +91 -0
- package/package.json +15 -16
- package/src/NitroSpeech.ts +5 -0
- package/src/Recognizer/RecognizerRef.ts +23 -0
- package/src/Recognizer/SpeechRecognizer.ts +10 -0
- package/src/Recognizer/methods.ts +40 -0
- package/src/Recognizer/types.ts +33 -0
- package/src/Recognizer/useRecognizer.ts +85 -0
- package/src/Recognizer/useVoiceInputVolume.ts +65 -0
- package/src/index.ts +6 -182
- package/src/specs/NitroSpeech.nitro.ts +2 -163
- package/src/specs/Recognizer.nitro.ts +110 -0
- package/src/specs/SpeechRecognitionConfig.ts +167 -0
- package/src/specs/VolumeChangeEvent.ts +31 -0
- package/android/proguard-rules.pro +0 -1
- package/ios/AnylyzerTranscriber.swift +0 -331
- package/ios/AutoStopper.swift +0 -69
- package/ios/HapticImpact.swift +0 -32
- package/ios/LegacySpeechRecognizer.swift +0 -161
- package/lib/commonjs/index.js +0 -145
- package/lib/commonjs/index.js.map +0 -1
- package/lib/commonjs/package.json +0 -1
- package/lib/commonjs/specs/NitroSpeech.nitro.js +0 -6
- package/lib/commonjs/specs/NitroSpeech.nitro.js.map +0 -1
- package/lib/module/index.js +0 -138
- package/lib/module/index.js.map +0 -1
- package/lib/module/package.json +0 -1
- package/lib/module/specs/NitroSpeech.nitro.js +0 -4
- package/lib/module/specs/NitroSpeech.nitro.js.map +0 -1
- package/lib/tsconfig.tsbuildinfo +0 -1
- package/lib/typescript/index.d.ts +0 -50
- package/lib/typescript/index.d.ts.map +0 -1
- package/lib/typescript/specs/NitroSpeech.nitro.d.ts +0 -162
- package/lib/typescript/specs/NitroSpeech.nitro.d.ts.map +0 -1
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitrospeech/SpeechToTextParams.kt +0 -68
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import type { HybridObject } from 'react-native-nitro-modules';
|
|
2
|
+
import type { MutableSpeechRecognitionConfig, SpeechRecognitionConfig } from './SpeechRecognitionConfig';
|
|
3
|
+
import type { VolumeChangeEvent } from './VolumeChangeEvent';
|
|
4
|
+
export interface Recognizer extends HybridObject<{
|
|
5
|
+
ios: 'swift';
|
|
6
|
+
android: 'kotlin';
|
|
7
|
+
}> {
|
|
8
|
+
/**
|
|
9
|
+
* Prepare the speech recognition engine and the model for the given parameters.
|
|
10
|
+
*
|
|
11
|
+
* Omit the {@linkcode Promise} result if want to run synchronously.
|
|
12
|
+
* {@linkcode startListening} will start and resolve it automatically.
|
|
13
|
+
* Only `await` if run beforehand and want to react on the success
|
|
14
|
+
*/
|
|
15
|
+
prewarm(defaultParams?: SpeechRecognitionConfig): Promise<void>;
|
|
16
|
+
/**
|
|
17
|
+
* Try to start the speech recognition.
|
|
18
|
+
*
|
|
19
|
+
* Not guaranteed to start the speech recognition.
|
|
20
|
+
*
|
|
21
|
+
* On success - {@linkcode onReadyForSpeech} is called
|
|
22
|
+
*
|
|
23
|
+
* On failure - {@linkcode onError} is called
|
|
24
|
+
*/
|
|
25
|
+
startListening(params?: SpeechRecognitionConfig): void;
|
|
26
|
+
/**
|
|
27
|
+
* Stops the speech recognition. if not started, does nothing.
|
|
28
|
+
*
|
|
29
|
+
* Not a sync operation for android, delay about 250ms to polish the result.
|
|
30
|
+
*
|
|
31
|
+
* Use {@linkcode onRecordingStopped} to handle the stop event.
|
|
32
|
+
*/
|
|
33
|
+
stopListening(): void;
|
|
34
|
+
/**
|
|
35
|
+
* Reset the auto finish timer to current {@linkcode SpeechRecognitionConfig.autoFinishRecognitionMs}.
|
|
36
|
+
*/
|
|
37
|
+
resetAutoFinishTime(): void;
|
|
38
|
+
/**
|
|
39
|
+
* Add time to the auto finish timer once without changing the timer threshold.
|
|
40
|
+
*
|
|
41
|
+
* @param additionalTimeMs - time in ms to add to the current auto finish timer. If not set, will reset the timer to the original {@linkcode SpeechRecognitionConfig.autoFinishRecognitionMs}.
|
|
42
|
+
*/
|
|
43
|
+
addAutoFinishTime(additionalTimeMs?: number): void;
|
|
44
|
+
/**
|
|
45
|
+
* Applies changes only within the active recognition session.
|
|
46
|
+
*
|
|
47
|
+
* @param newConfig - new dynamic params for the speech recognition.
|
|
48
|
+
* @param resetAutoFinishTime - if true, will reset auto finish time to actual {@linkcode SpeechRecognitionConfig.autoFinishRecognitionMs}.
|
|
49
|
+
*/
|
|
50
|
+
updateConfig(newConfig?: MutableSpeechRecognitionConfig, resetAutoFinishTime?: boolean): void;
|
|
51
|
+
/**
|
|
52
|
+
* Returns true if the speech recognition is active.
|
|
53
|
+
*/
|
|
54
|
+
getIsActive(): boolean;
|
|
55
|
+
/**
|
|
56
|
+
* Returns a list of supported locales.
|
|
57
|
+
*
|
|
58
|
+
* @platform iOS only
|
|
59
|
+
*/
|
|
60
|
+
getSupportedLocalesIOS(): string[];
|
|
61
|
+
/**
|
|
62
|
+
* The speech recognition session has started.
|
|
63
|
+
*/
|
|
64
|
+
onReadyForSpeech?: () => void;
|
|
65
|
+
/**
|
|
66
|
+
* The speech recognition session has stopped.
|
|
67
|
+
*/
|
|
68
|
+
onRecordingStopped?: () => void;
|
|
69
|
+
/**
|
|
70
|
+
* Called each time either a new batch has been added or the last batch has been updated.
|
|
71
|
+
*/
|
|
72
|
+
onResult?: (resultBatches: string[]) => void;
|
|
73
|
+
/**
|
|
74
|
+
* Called every {@linkcode SpeechRecognitionConfig.autoFinishProgressIntervalMs} or 1000ms
|
|
75
|
+
*
|
|
76
|
+
* Time left in milliseconds until the timer stops.
|
|
77
|
+
*
|
|
78
|
+
* @note not implemented for Android yet.
|
|
79
|
+
*/
|
|
80
|
+
onAutoFinishProgress?: (timeLeftMs: number) => void;
|
|
81
|
+
/**
|
|
82
|
+
* Error of the speech recognition.
|
|
83
|
+
*/
|
|
84
|
+
onError?: (message: string) => void;
|
|
85
|
+
/**
|
|
86
|
+
* The permission to use the microphone or recognize speech has been denied.
|
|
87
|
+
*/
|
|
88
|
+
onPermissionDenied?: () => void;
|
|
89
|
+
/**
|
|
90
|
+
* Called with high and arbitrary frequency (many times per second) while audio recording is active.
|
|
91
|
+
*
|
|
92
|
+
* @warning overriding it will disable the built-in `useVoiceInputVolume` hook.
|
|
93
|
+
*/
|
|
94
|
+
onVolumeChange?: (event: VolumeChangeEvent) => void;
|
|
95
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
interface ParamsAndroid {
|
|
2
|
+
/**
|
|
3
|
+
* Prefer quality over latency (may break autofinish, depends on device)
|
|
4
|
+
*
|
|
5
|
+
* @since Android 13+
|
|
6
|
+
*
|
|
7
|
+
* @default false
|
|
8
|
+
*/
|
|
9
|
+
androidFormattingPreferQuality?: boolean;
|
|
10
|
+
/**
|
|
11
|
+
* Language model based on web search terms. (may not work on some devices)
|
|
12
|
+
*
|
|
13
|
+
* Free form model by default
|
|
14
|
+
*
|
|
15
|
+
* @default false
|
|
16
|
+
*/
|
|
17
|
+
androidUseWebSearchModel?: boolean;
|
|
18
|
+
/**
|
|
19
|
+
* Without batch handling the result will contain empty or same content batches.
|
|
20
|
+
*
|
|
21
|
+
* @default false
|
|
22
|
+
*/
|
|
23
|
+
androidDisableBatchHandling?: boolean;
|
|
24
|
+
}
|
|
25
|
+
type IosPreset = 'shortform' | 'general';
|
|
26
|
+
interface ParamsIOS {
|
|
27
|
+
/**
|
|
28
|
+
* Add punctuation to speech recognition results
|
|
29
|
+
*
|
|
30
|
+
* @since iOS 16.0+
|
|
31
|
+
*
|
|
32
|
+
* @default true
|
|
33
|
+
*/
|
|
34
|
+
iosAddPunctuation?: boolean;
|
|
35
|
+
/**
|
|
36
|
+
* `"shortForm"` - for a short phrase or sentence, also disables punctuation
|
|
37
|
+
*
|
|
38
|
+
* `"general"` - for longer speeches, more accurate but delayed response
|
|
39
|
+
*
|
|
40
|
+
* @since iOS 26.0+
|
|
41
|
+
*
|
|
42
|
+
* @default "general"
|
|
43
|
+
*/
|
|
44
|
+
iosPreset?: IosPreset;
|
|
45
|
+
/**
|
|
46
|
+
* A processing hint indicating that the audio is from a speaker with a heavy accent, lisp, or other confounding factor.
|
|
47
|
+
*
|
|
48
|
+
* @since iOS 26.0+
|
|
49
|
+
*
|
|
50
|
+
* @default false
|
|
51
|
+
*/
|
|
52
|
+
iosAtypicalSpeech?: boolean;
|
|
53
|
+
}
|
|
54
|
+
type HapticFeedbackStyle = 'light' | 'medium' | 'heavy' | 'none';
|
|
55
|
+
export interface MutableSpeechRecognitionConfig {
|
|
56
|
+
/**
|
|
57
|
+
* Silence timer duration with no voice detected
|
|
58
|
+
*
|
|
59
|
+
* for Android - undefined behavior for > 300_000ms (5 minutes)
|
|
60
|
+
*
|
|
61
|
+
* @default 8000
|
|
62
|
+
*/
|
|
63
|
+
autoFinishRecognitionMs?: number;
|
|
64
|
+
/**
|
|
65
|
+
* The interval at which `onAutoFinishProgress` will be triggered.
|
|
66
|
+
*
|
|
67
|
+
* min: 50ms,
|
|
68
|
+
*
|
|
69
|
+
* max: {@link autoFinishRecognitionMs}
|
|
70
|
+
*
|
|
71
|
+
* @default 1000
|
|
72
|
+
*/
|
|
73
|
+
autoFinishProgressIntervalMs?: number;
|
|
74
|
+
/**
|
|
75
|
+
* The voice detector sensitivity to reset the auto finish timer.
|
|
76
|
+
*
|
|
77
|
+
* Adjust for your expected environment.
|
|
78
|
+
*
|
|
79
|
+
* `0.00` - `1.00`
|
|
80
|
+
*
|
|
81
|
+
* `0.10` - Quiet room level
|
|
82
|
+
*
|
|
83
|
+
* `0.40` - Default, street, medium restaurant background, office level
|
|
84
|
+
*
|
|
85
|
+
* `0.60` - Loud restaurants, noisy office, party, highly crowded places level
|
|
86
|
+
*
|
|
87
|
+
* `1` - Use to disable volume-based reset of the auto finish timer
|
|
88
|
+
*
|
|
89
|
+
* @default 0.40
|
|
90
|
+
*/
|
|
91
|
+
resetAutoFinishVoiceSensitivity?: number;
|
|
92
|
+
/**
|
|
93
|
+
* Lots of repeating words in a row can be annoying
|
|
94
|
+
*
|
|
95
|
+
* @default false
|
|
96
|
+
*/
|
|
97
|
+
disableRepeatingFilter?: boolean;
|
|
98
|
+
/**
|
|
99
|
+
* Haptic feedback level when microphone starts recording.
|
|
100
|
+
*
|
|
101
|
+
* Use `"none"` to disable.
|
|
102
|
+
*
|
|
103
|
+
* @default "medium"
|
|
104
|
+
*/
|
|
105
|
+
startHapticFeedbackStyle?: HapticFeedbackStyle;
|
|
106
|
+
/**
|
|
107
|
+
* Haptic feedback level when microphone stops recording.
|
|
108
|
+
*
|
|
109
|
+
* Use `"none"` to disable.
|
|
110
|
+
*
|
|
111
|
+
* @default "medium"
|
|
112
|
+
*/
|
|
113
|
+
stopHapticFeedbackStyle?: HapticFeedbackStyle;
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* @note Configuration for android and ios may behave differently
|
|
117
|
+
* for the same properties, test both platforms
|
|
118
|
+
*
|
|
119
|
+
* Use `Plarform.select()` to match expectations
|
|
120
|
+
*/
|
|
121
|
+
export interface SpeechRecognitionConfig extends MutableSpeechRecognitionConfig, ParamsAndroid, ParamsIOS {
|
|
122
|
+
/**
|
|
123
|
+
* @default "en-US"
|
|
124
|
+
*
|
|
125
|
+
* @example
|
|
126
|
+
* "fr-FR"
|
|
127
|
+
* "pt-PT"
|
|
128
|
+
* "pt-BR"
|
|
129
|
+
*
|
|
130
|
+
*/
|
|
131
|
+
locale?: string;
|
|
132
|
+
/**
|
|
133
|
+
* An array of strings that should be recognized, even if they are not in the system vocabulary.
|
|
134
|
+
*
|
|
135
|
+
* Use this property to specify short custom phrases that are unique to your app.
|
|
136
|
+
*
|
|
137
|
+
* You might include phrases with the names of characters, products, or places that are specific to your app.
|
|
138
|
+
*
|
|
139
|
+
* You might also include domain-specific terminology or unusual or made-up words.
|
|
140
|
+
*
|
|
141
|
+
* Assigning custom phrases to this property improves the likelihood of those phrases being recognized.
|
|
142
|
+
*
|
|
143
|
+
* Keep phrases relatively brief, limiting them to one or two words whenever possible.
|
|
144
|
+
* Lengthy phrases are less likely to be recognized.
|
|
145
|
+
* In addition, try to limit each phrase to something the user can say without pausing.
|
|
146
|
+
*
|
|
147
|
+
* Limit the total number of phrases to no more than 100.
|
|
148
|
+
*
|
|
149
|
+
* @default []
|
|
150
|
+
*/
|
|
151
|
+
contextualStrings?: string[];
|
|
152
|
+
/**
|
|
153
|
+
* Mask offensive words with asterisks.
|
|
154
|
+
*
|
|
155
|
+
* @since Android 13+
|
|
156
|
+
* @since iOS 26+ (iOS <26: always `false`)
|
|
157
|
+
*
|
|
158
|
+
* @default false
|
|
159
|
+
*/
|
|
160
|
+
maskOffensiveWords?: boolean;
|
|
161
|
+
}
|
|
162
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Contains data about each audio buffer volume.
|
|
3
|
+
*
|
|
4
|
+
* Emits with high frequency.
|
|
5
|
+
*/
|
|
6
|
+
export interface VolumeChangeEvent {
|
|
7
|
+
/**
|
|
8
|
+
* Smoothed voice input volume
|
|
9
|
+
*
|
|
10
|
+
* Normalized to a range of 0 to 1.
|
|
11
|
+
*
|
|
12
|
+
* Best choice for UI animations.
|
|
13
|
+
*/
|
|
14
|
+
smoothedVolume: number;
|
|
15
|
+
/**
|
|
16
|
+
* Raw voice input volume
|
|
17
|
+
*
|
|
18
|
+
* Normalized to a range of 0 to 1.
|
|
19
|
+
*
|
|
20
|
+
* Appropriate for internal logic, quick reactions, not UI.
|
|
21
|
+
*/
|
|
22
|
+
rawVolume: number;
|
|
23
|
+
/**
|
|
24
|
+
* Audio buffer volume in decibels.
|
|
25
|
+
*
|
|
26
|
+
* May vary on different devices and audio engines.
|
|
27
|
+
*
|
|
28
|
+
* db 0 is still a sound, undefined is no sound.
|
|
29
|
+
*/
|
|
30
|
+
db?: number;
|
|
31
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/nitro.json
CHANGED
|
@@ -1,15 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"$schema": "https://nitro.margelo.com/nitro.schema.json",
|
|
3
3
|
"cxxNamespace": ["nitrospeech"],
|
|
4
|
-
|
|
5
|
-
|
|
6
4
|
"ios": {
|
|
7
5
|
"iosModuleName": "NitroSpeech"
|
|
8
6
|
},
|
|
9
7
|
"android": {
|
|
10
8
|
"androidNamespace": ["nitrospeech"],
|
|
11
|
-
|
|
12
|
-
|
|
13
9
|
"androidCxxLibName": "NitroSpeech"
|
|
14
10
|
},
|
|
15
11
|
"autolinking": {
|
|
@@ -33,11 +33,11 @@ target_sources(
|
|
|
33
33
|
# Autolinking Setup
|
|
34
34
|
../nitrogen/generated/android/NitroSpeechOnLoad.cpp
|
|
35
35
|
# Shared Nitrogen C++ sources
|
|
36
|
-
../nitrogen/generated/shared/c++/HybridRecognizerSpec.cpp
|
|
37
36
|
../nitrogen/generated/shared/c++/HybridNitroSpeechSpec.cpp
|
|
37
|
+
../nitrogen/generated/shared/c++/HybridRecognizerSpec.cpp
|
|
38
38
|
# Android-specific Nitrogen C++ sources
|
|
39
|
-
../nitrogen/generated/android/c++/JHybridRecognizerSpec.cpp
|
|
40
39
|
../nitrogen/generated/android/c++/JHybridNitroSpeechSpec.cpp
|
|
40
|
+
../nitrogen/generated/android/c++/JHybridRecognizerSpec.cpp
|
|
41
41
|
)
|
|
42
42
|
|
|
43
43
|
# From node_modules/react-native/ReactAndroid/cmake-utils/folly-flags.cmake
|
|
@@ -15,12 +15,13 @@
|
|
|
15
15
|
#include <fbjni/fbjni.h>
|
|
16
16
|
#include <NitroModules/HybridObjectRegistry.hpp>
|
|
17
17
|
|
|
18
|
+
#include "JHybridNitroSpeechSpec.hpp"
|
|
18
19
|
#include "JHybridRecognizerSpec.hpp"
|
|
19
20
|
#include "JFunc_void.hpp"
|
|
20
21
|
#include "JFunc_void_std__vector_std__string_.hpp"
|
|
21
22
|
#include "JFunc_void_double.hpp"
|
|
22
23
|
#include "JFunc_void_std__string.hpp"
|
|
23
|
-
#include "
|
|
24
|
+
#include "JFunc_void_VolumeChangeEvent.hpp"
|
|
24
25
|
#include <NitroModules/DefaultConstructableObject.hpp>
|
|
25
26
|
|
|
26
27
|
namespace margelo::nitro::nitrospeech {
|
|
@@ -45,12 +46,13 @@ void registerAllNatives() {
|
|
|
45
46
|
using namespace margelo::nitro::nitrospeech;
|
|
46
47
|
|
|
47
48
|
// Register native JNI methods
|
|
49
|
+
margelo::nitro::nitrospeech::JHybridNitroSpeechSpec::CxxPart::registerNatives();
|
|
48
50
|
margelo::nitro::nitrospeech::JHybridRecognizerSpec::CxxPart::registerNatives();
|
|
49
51
|
margelo::nitro::nitrospeech::JFunc_void_cxx::registerNatives();
|
|
50
52
|
margelo::nitro::nitrospeech::JFunc_void_std__vector_std__string__cxx::registerNatives();
|
|
51
53
|
margelo::nitro::nitrospeech::JFunc_void_double_cxx::registerNatives();
|
|
52
54
|
margelo::nitro::nitrospeech::JFunc_void_std__string_cxx::registerNatives();
|
|
53
|
-
margelo::nitro::nitrospeech::
|
|
55
|
+
margelo::nitro::nitrospeech::JFunc_void_VolumeChangeEvent_cxx::registerNatives();
|
|
54
56
|
|
|
55
57
|
// Register Nitro Hybrid Objects
|
|
56
58
|
HybridObjectRegistry::registerHybridObjectConstructor(
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
///
|
|
2
|
+
/// JFunc_void_VolumeChangeEvent.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 "VolumeChangeEvent.hpp"
|
|
14
|
+
#include <functional>
|
|
15
|
+
#include <NitroModules/JNICallable.hpp>
|
|
16
|
+
#include "JVolumeChangeEvent.hpp"
|
|
17
|
+
#include <optional>
|
|
18
|
+
|
|
19
|
+
namespace margelo::nitro::nitrospeech {
|
|
20
|
+
|
|
21
|
+
using namespace facebook;
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Represents the Java/Kotlin callback `(event: VolumeChangeEvent) -> Unit`.
|
|
25
|
+
* This can be passed around between C++ and Java/Kotlin.
|
|
26
|
+
*/
|
|
27
|
+
struct JFunc_void_VolumeChangeEvent: public jni::JavaClass<JFunc_void_VolumeChangeEvent> {
|
|
28
|
+
public:
|
|
29
|
+
static constexpr auto kJavaDescriptor = "Lcom/margelo/nitro/nitrospeech/Func_void_VolumeChangeEvent;";
|
|
30
|
+
|
|
31
|
+
public:
|
|
32
|
+
/**
|
|
33
|
+
* Invokes the function this `JFunc_void_VolumeChangeEvent` instance holds through JNI.
|
|
34
|
+
*/
|
|
35
|
+
void invoke(const VolumeChangeEvent& event) const {
|
|
36
|
+
static const auto method = javaClassStatic()->getMethod<void(jni::alias_ref<JVolumeChangeEvent> /* event */)>("invoke");
|
|
37
|
+
method(self(), JVolumeChangeEvent::fromCpp(event));
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* An implementation of Func_void_VolumeChangeEvent that is backed by a C++ implementation (using `std::function<...>`)
|
|
43
|
+
*/
|
|
44
|
+
class JFunc_void_VolumeChangeEvent_cxx final: public jni::HybridClass<JFunc_void_VolumeChangeEvent_cxx, JFunc_void_VolumeChangeEvent> {
|
|
45
|
+
public:
|
|
46
|
+
static jni::local_ref<JFunc_void_VolumeChangeEvent::javaobject> fromCpp(const std::function<void(const VolumeChangeEvent& /* event */)>& func) {
|
|
47
|
+
return JFunc_void_VolumeChangeEvent_cxx::newObjectCxxArgs(func);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
public:
|
|
51
|
+
/**
|
|
52
|
+
* Invokes the C++ `std::function<...>` this `JFunc_void_VolumeChangeEvent_cxx` instance holds.
|
|
53
|
+
*/
|
|
54
|
+
void invoke_cxx(jni::alias_ref<JVolumeChangeEvent> event) {
|
|
55
|
+
_func(event->toCpp());
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
public:
|
|
59
|
+
[[nodiscard]]
|
|
60
|
+
inline const std::function<void(const VolumeChangeEvent& /* event */)>& getFunction() const {
|
|
61
|
+
return _func;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
public:
|
|
65
|
+
static constexpr auto kJavaDescriptor = "Lcom/margelo/nitro/nitrospeech/Func_void_VolumeChangeEvent_cxx;";
|
|
66
|
+
static void registerNatives() {
|
|
67
|
+
registerHybrid({makeNativeMethod("invoke_cxx", JFunc_void_VolumeChangeEvent_cxx::invoke_cxx)});
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
private:
|
|
71
|
+
explicit JFunc_void_VolumeChangeEvent_cxx(const std::function<void(const VolumeChangeEvent& /* event */)>& func): _func(func) { }
|
|
72
|
+
|
|
73
|
+
private:
|
|
74
|
+
friend HybridBase;
|
|
75
|
+
std::function<void(const VolumeChangeEvent& /* event */)> _func;
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
} // namespace margelo::nitro::nitrospeech
|
|
@@ -33,16 +33,16 @@ namespace margelo::nitro::nitrospeech {
|
|
|
33
33
|
*/
|
|
34
34
|
void invoke(const std::vector<std::string>& resultBatches) const {
|
|
35
35
|
static const auto method = javaClassStatic()->getMethod<void(jni::alias_ref<jni::JArrayClass<jni::JString>> /* resultBatches */)>("invoke");
|
|
36
|
-
method(self(), [&]() {
|
|
37
|
-
size_t __size =
|
|
36
|
+
method(self(), [&](auto&& __input) {
|
|
37
|
+
size_t __size = __input.size();
|
|
38
38
|
jni::local_ref<jni::JArrayClass<jni::JString>> __array = jni::JArrayClass<jni::JString>::newArray(__size);
|
|
39
39
|
for (size_t __i = 0; __i < __size; __i++) {
|
|
40
|
-
const auto& __element =
|
|
40
|
+
const auto& __element = __input[__i];
|
|
41
41
|
auto __elementJni = jni::make_jstring(__element);
|
|
42
42
|
__array->setElement(__i, *__elementJni);
|
|
43
43
|
}
|
|
44
44
|
return __array;
|
|
45
|
-
}());
|
|
45
|
+
}(resultBatches));
|
|
46
46
|
}
|
|
47
47
|
};
|
|
48
48
|
|
|
@@ -60,16 +60,16 @@ namespace margelo::nitro::nitrospeech {
|
|
|
60
60
|
* Invokes the C++ `std::function<...>` this `JFunc_void_std__vector_std__string__cxx` instance holds.
|
|
61
61
|
*/
|
|
62
62
|
void invoke_cxx(jni::alias_ref<jni::JArrayClass<jni::JString>> resultBatches) {
|
|
63
|
-
_func([&]() {
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
63
|
+
_func([&](auto&& __input) {
|
|
64
|
+
size_t __size = __input->size();
|
|
65
|
+
std::vector<std::string> __vector;
|
|
66
|
+
__vector.reserve(__size);
|
|
67
|
+
for (size_t __i = 0; __i < __size; __i++) {
|
|
68
|
+
auto __element = __input->getElement(__i);
|
|
69
|
+
__vector.push_back(__element->toStdString());
|
|
70
|
+
}
|
|
71
|
+
return __vector;
|
|
72
|
+
}(resultBatches));
|
|
73
73
|
}
|
|
74
74
|
|
|
75
75
|
public:
|
|
@@ -7,10 +7,16 @@
|
|
|
7
7
|
|
|
8
8
|
#include "JHybridRecognizerSpec.hpp"
|
|
9
9
|
|
|
10
|
-
// Forward declaration of `
|
|
11
|
-
namespace margelo::nitro::nitrospeech { struct
|
|
10
|
+
// Forward declaration of `VolumeChangeEvent` to properly resolve imports.
|
|
11
|
+
namespace margelo::nitro::nitrospeech { struct VolumeChangeEvent; }
|
|
12
|
+
// Forward declaration of `SpeechRecognitionConfig` to properly resolve imports.
|
|
13
|
+
namespace margelo::nitro::nitrospeech { struct SpeechRecognitionConfig; }
|
|
12
14
|
// Forward declaration of `HapticFeedbackStyle` to properly resolve imports.
|
|
13
15
|
namespace margelo::nitro::nitrospeech { enum class HapticFeedbackStyle; }
|
|
16
|
+
// Forward declaration of `IosPreset` to properly resolve imports.
|
|
17
|
+
namespace margelo::nitro::nitrospeech { enum class IosPreset; }
|
|
18
|
+
// Forward declaration of `MutableSpeechRecognitionConfig` to properly resolve imports.
|
|
19
|
+
namespace margelo::nitro::nitrospeech { struct MutableSpeechRecognitionConfig; }
|
|
14
20
|
|
|
15
21
|
#include <functional>
|
|
16
22
|
#include <optional>
|
|
@@ -21,10 +27,20 @@ namespace margelo::nitro::nitrospeech { enum class HapticFeedbackStyle; }
|
|
|
21
27
|
#include "JFunc_void_std__vector_std__string_.hpp"
|
|
22
28
|
#include "JFunc_void_double.hpp"
|
|
23
29
|
#include "JFunc_void_std__string.hpp"
|
|
24
|
-
#include "
|
|
25
|
-
#include "
|
|
30
|
+
#include "VolumeChangeEvent.hpp"
|
|
31
|
+
#include "JFunc_void_VolumeChangeEvent.hpp"
|
|
32
|
+
#include "JVolumeChangeEvent.hpp"
|
|
33
|
+
#include <NitroModules/Promise.hpp>
|
|
34
|
+
#include <NitroModules/JPromise.hpp>
|
|
35
|
+
#include <NitroModules/JUnit.hpp>
|
|
36
|
+
#include "SpeechRecognitionConfig.hpp"
|
|
37
|
+
#include "JSpeechRecognitionConfig.hpp"
|
|
26
38
|
#include "HapticFeedbackStyle.hpp"
|
|
27
39
|
#include "JHapticFeedbackStyle.hpp"
|
|
40
|
+
#include "IosPreset.hpp"
|
|
41
|
+
#include "JIosPreset.hpp"
|
|
42
|
+
#include "MutableSpeechRecognitionConfig.hpp"
|
|
43
|
+
#include "JMutableSpeechRecognitionConfig.hpp"
|
|
28
44
|
|
|
29
45
|
namespace margelo::nitro::nitrospeech {
|
|
30
46
|
|
|
@@ -158,45 +174,78 @@ namespace margelo::nitro::nitrospeech {
|
|
|
158
174
|
static const auto method = _javaPart->javaClassStatic()->getMethod<void(jni::alias_ref<JFunc_void::javaobject> /* onPermissionDenied */)>("setOnPermissionDenied_cxx");
|
|
159
175
|
method(_javaPart, onPermissionDenied.has_value() ? JFunc_void_cxx::fromCpp(onPermissionDenied.value()) : nullptr);
|
|
160
176
|
}
|
|
161
|
-
std::optional<std::function<void(
|
|
162
|
-
static const auto method = _javaPart->javaClassStatic()->getMethod<jni::local_ref<
|
|
177
|
+
std::optional<std::function<void(const VolumeChangeEvent& /* event */)>> JHybridRecognizerSpec::getOnVolumeChange() {
|
|
178
|
+
static const auto method = _javaPart->javaClassStatic()->getMethod<jni::local_ref<JFunc_void_VolumeChangeEvent::javaobject>()>("getOnVolumeChange_cxx");
|
|
163
179
|
auto __result = method(_javaPart);
|
|
164
|
-
return __result != nullptr ? std::make_optional([&]() -> std::function<void(
|
|
165
|
-
if (__result->isInstanceOf(
|
|
166
|
-
auto downcast = jni::static_ref_cast<
|
|
180
|
+
return __result != nullptr ? std::make_optional([&]() -> std::function<void(const VolumeChangeEvent& /* event */)> {
|
|
181
|
+
if (__result->isInstanceOf(JFunc_void_VolumeChangeEvent_cxx::javaClassStatic())) [[likely]] {
|
|
182
|
+
auto downcast = jni::static_ref_cast<JFunc_void_VolumeChangeEvent_cxx::javaobject>(__result);
|
|
167
183
|
return downcast->cthis()->getFunction();
|
|
168
184
|
} else {
|
|
169
185
|
auto __resultRef = jni::make_global(__result);
|
|
170
|
-
return JNICallable<
|
|
186
|
+
return JNICallable<JFunc_void_VolumeChangeEvent, void(VolumeChangeEvent)>(std::move(__resultRef));
|
|
171
187
|
}
|
|
172
188
|
}()) : std::nullopt;
|
|
173
189
|
}
|
|
174
|
-
void JHybridRecognizerSpec::setOnVolumeChange(const std::optional<std::function<void(
|
|
175
|
-
static const auto method = _javaPart->javaClassStatic()->getMethod<void(jni::alias_ref<
|
|
176
|
-
method(_javaPart, onVolumeChange.has_value() ?
|
|
190
|
+
void JHybridRecognizerSpec::setOnVolumeChange(const std::optional<std::function<void(const VolumeChangeEvent& /* event */)>>& onVolumeChange) {
|
|
191
|
+
static const auto method = _javaPart->javaClassStatic()->getMethod<void(jni::alias_ref<JFunc_void_VolumeChangeEvent::javaobject> /* onVolumeChange */)>("setOnVolumeChange_cxx");
|
|
192
|
+
method(_javaPart, onVolumeChange.has_value() ? JFunc_void_VolumeChangeEvent_cxx::fromCpp(onVolumeChange.value()) : nullptr);
|
|
177
193
|
}
|
|
178
194
|
|
|
179
195
|
// Methods
|
|
180
|
-
void JHybridRecognizerSpec::
|
|
181
|
-
static const auto method = _javaPart->javaClassStatic()->getMethod<
|
|
182
|
-
method(_javaPart,
|
|
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);
|
|
199
|
+
return [&]() {
|
|
200
|
+
auto __promise = Promise<void>::create();
|
|
201
|
+
__result->cthis()->addOnResolvedListener([=](const jni::alias_ref<jni::JObject>& /* unit */) {
|
|
202
|
+
__promise->resolve();
|
|
203
|
+
});
|
|
204
|
+
__result->cthis()->addOnRejectedListener([=](const jni::alias_ref<jni::JThrowable>& __throwable) {
|
|
205
|
+
jni::JniException __jniError(__throwable);
|
|
206
|
+
__promise->reject(std::make_exception_ptr(__jniError));
|
|
207
|
+
});
|
|
208
|
+
return __promise;
|
|
209
|
+
}();
|
|
210
|
+
}
|
|
211
|
+
void JHybridRecognizerSpec::startListening(const std::optional<SpeechRecognitionConfig>& params) {
|
|
212
|
+
static const auto method = _javaPart->javaClassStatic()->getMethod<void(jni::alias_ref<JSpeechRecognitionConfig> /* params */)>("startListening");
|
|
213
|
+
method(_javaPart, params.has_value() ? JSpeechRecognitionConfig::fromCpp(params.value()) : nullptr);
|
|
183
214
|
}
|
|
184
215
|
void JHybridRecognizerSpec::stopListening() {
|
|
185
216
|
static const auto method = _javaPart->javaClassStatic()->getMethod<void()>("stopListening");
|
|
186
217
|
method(_javaPart);
|
|
187
218
|
}
|
|
219
|
+
void JHybridRecognizerSpec::resetAutoFinishTime() {
|
|
220
|
+
static const auto method = _javaPart->javaClassStatic()->getMethod<void()>("resetAutoFinishTime");
|
|
221
|
+
method(_javaPart);
|
|
222
|
+
}
|
|
188
223
|
void JHybridRecognizerSpec::addAutoFinishTime(std::optional<double> additionalTimeMs) {
|
|
189
224
|
static const auto method = _javaPart->javaClassStatic()->getMethod<void(jni::alias_ref<jni::JDouble> /* additionalTimeMs */)>("addAutoFinishTime");
|
|
190
225
|
method(_javaPart, additionalTimeMs.has_value() ? jni::JDouble::valueOf(additionalTimeMs.value()) : nullptr);
|
|
191
226
|
}
|
|
192
|
-
void JHybridRecognizerSpec::
|
|
193
|
-
static const auto method = _javaPart->javaClassStatic()->getMethod<void(
|
|
194
|
-
method(_javaPart,
|
|
227
|
+
void JHybridRecognizerSpec::updateConfig(const std::optional<MutableSpeechRecognitionConfig>& newConfig, std::optional<bool> resetAutoFinishTime) {
|
|
228
|
+
static const auto method = _javaPart->javaClassStatic()->getMethod<void(jni::alias_ref<JMutableSpeechRecognitionConfig> /* newConfig */, jni::alias_ref<jni::JBoolean> /* resetAutoFinishTime */)>("updateConfig");
|
|
229
|
+
method(_javaPart, newConfig.has_value() ? JMutableSpeechRecognitionConfig::fromCpp(newConfig.value()) : nullptr, resetAutoFinishTime.has_value() ? jni::JBoolean::valueOf(resetAutoFinishTime.value()) : nullptr);
|
|
195
230
|
}
|
|
196
231
|
bool JHybridRecognizerSpec::getIsActive() {
|
|
197
232
|
static const auto method = _javaPart->javaClassStatic()->getMethod<jboolean()>("getIsActive");
|
|
198
233
|
auto __result = method(_javaPart);
|
|
199
234
|
return static_cast<bool>(__result);
|
|
200
235
|
}
|
|
236
|
+
std::vector<std::string> JHybridRecognizerSpec::getSupportedLocalesIOS() {
|
|
237
|
+
static const auto method = _javaPart->javaClassStatic()->getMethod<jni::local_ref<jni::JArrayClass<jni::JString>>()>("getSupportedLocalesIOS");
|
|
238
|
+
auto __result = method(_javaPart);
|
|
239
|
+
return [&](auto&& __input) {
|
|
240
|
+
size_t __size = __input->size();
|
|
241
|
+
std::vector<std::string> __vector;
|
|
242
|
+
__vector.reserve(__size);
|
|
243
|
+
for (size_t __i = 0; __i < __size; __i++) {
|
|
244
|
+
auto __element = __input->getElement(__i);
|
|
245
|
+
__vector.push_back(__element->toStdString());
|
|
246
|
+
}
|
|
247
|
+
return __vector;
|
|
248
|
+
}(__result);
|
|
249
|
+
}
|
|
201
250
|
|
|
202
251
|
} // namespace margelo::nitro::nitrospeech
|
|
@@ -62,16 +62,19 @@ namespace margelo::nitro::nitrospeech {
|
|
|
62
62
|
void setOnError(const std::optional<std::function<void(const std::string& /* message */)>>& onError) override;
|
|
63
63
|
std::optional<std::function<void()>> getOnPermissionDenied() override;
|
|
64
64
|
void setOnPermissionDenied(const std::optional<std::function<void()>>& onPermissionDenied) override;
|
|
65
|
-
std::optional<std::function<void(
|
|
66
|
-
void setOnVolumeChange(const std::optional<std::function<void(
|
|
65
|
+
std::optional<std::function<void(const VolumeChangeEvent& /* event */)>> getOnVolumeChange() override;
|
|
66
|
+
void setOnVolumeChange(const std::optional<std::function<void(const VolumeChangeEvent& /* event */)>>& onVolumeChange) override;
|
|
67
67
|
|
|
68
68
|
public:
|
|
69
69
|
// Methods
|
|
70
|
-
void
|
|
70
|
+
std::shared_ptr<Promise<void>> prewarm(const std::optional<SpeechRecognitionConfig>& defaultParams) override;
|
|
71
|
+
void startListening(const std::optional<SpeechRecognitionConfig>& params) override;
|
|
71
72
|
void stopListening() override;
|
|
73
|
+
void resetAutoFinishTime() override;
|
|
72
74
|
void addAutoFinishTime(std::optional<double> additionalTimeMs) override;
|
|
73
|
-
void
|
|
75
|
+
void updateConfig(const std::optional<MutableSpeechRecognitionConfig>& newConfig, std::optional<bool> resetAutoFinishTime) override;
|
|
74
76
|
bool getIsActive() override;
|
|
77
|
+
std::vector<std::string> getSupportedLocalesIOS() override;
|
|
75
78
|
|
|
76
79
|
private:
|
|
77
80
|
jni::global_ref<JHybridRecognizerSpec::JavaPart> _javaPart;
|