@gmessier/nitro-speech 0.1.0 → 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +116 -27
- package/android/src/main/AndroidManifest.xml +1 -0
- package/android/src/main/java/com/margelo/nitro/nitrospeech/recognizer/HapticImpact.kt +66 -0
- package/android/src/main/java/com/margelo/nitro/nitrospeech/recognizer/HybridRecognizer.kt +11 -0
- package/ios/HapticImpact.swift +23 -0
- package/ios/HybridRecognizer.swift +28 -10
- package/lib/commonjs/index.js +44 -22
- package/lib/commonjs/index.js.map +1 -1
- package/lib/module/index.js +42 -21
- package/lib/module/index.js.map +1 -1
- package/lib/tsconfig.tsbuildinfo +1 -1
- package/lib/typescript/index.d.ts +23 -3
- package/lib/typescript/index.d.ts.map +1 -1
- package/lib/typescript/specs/NitroSpeech.nitro.d.ts +13 -0
- package/lib/typescript/specs/NitroSpeech.nitro.d.ts.map +1 -1
- package/nitrogen/generated/android/c++/JHapticFeedbackStyle.hpp +62 -0
- package/nitrogen/generated/android/c++/JHybridRecognizerSpec.cpp +4 -0
- package/nitrogen/generated/android/c++/JSpeechToTextParams.hpp +11 -1
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitrospeech/HapticFeedbackStyle.kt +22 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitrospeech/SpeechToTextParams.kt +8 -2
- 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 +3 -0
- package/nitrogen/generated/ios/swift/HapticFeedbackStyle.swift +44 -0
- package/nitrogen/generated/ios/swift/SpeechToTextParams.swift +47 -1
- package/nitrogen/generated/shared/c++/HapticFeedbackStyle.hpp +80 -0
- package/nitrogen/generated/shared/c++/SpeechToTextParams.hpp +12 -2
- package/package.json +4 -4
- package/src/index.ts +43 -21
- package/src/specs/NitroSpeech.nitro.ts +14 -0
package/src/index.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
/* eslint-disable react-hooks/exhaustive-deps */
|
|
1
2
|
import React from 'react'
|
|
2
3
|
import { NitroModules } from 'react-native-nitro-modules'
|
|
3
4
|
import type {
|
|
@@ -10,9 +11,9 @@ const NitroSpeech =
|
|
|
10
11
|
NitroModules.createHybridObject<NitroSpeechSpec>('NitroSpeech')
|
|
11
12
|
|
|
12
13
|
/**
|
|
13
|
-
* Unsafe access to the
|
|
14
|
+
* Unsafe access to the Recognizer Session.
|
|
14
15
|
*/
|
|
15
|
-
export const
|
|
16
|
+
export const RecognizerSession = NitroSpeech.recognizer
|
|
16
17
|
|
|
17
18
|
type RecognizerCallbacks = Pick<
|
|
18
19
|
RecognizerSpec,
|
|
@@ -33,64 +34,75 @@ type RecognizerHandlers = Pick<
|
|
|
33
34
|
>
|
|
34
35
|
|
|
35
36
|
const recognizerStartListening = (params: SpeechToTextParams) => {
|
|
36
|
-
|
|
37
|
+
RecognizerSession.startListening(params)
|
|
37
38
|
}
|
|
38
39
|
|
|
39
40
|
const recognizerStopListening = () => {
|
|
40
|
-
|
|
41
|
+
RecognizerSession.stopListening()
|
|
41
42
|
}
|
|
42
43
|
|
|
43
44
|
const recognizerAddAutoFinishTime = (additionalTimeMs?: number) => {
|
|
44
|
-
|
|
45
|
+
RecognizerSession.addAutoFinishTime(additionalTimeMs)
|
|
45
46
|
}
|
|
46
47
|
|
|
47
48
|
const recognizerUpdateAutoFinishTime = (
|
|
48
49
|
newTimeMs: number,
|
|
49
50
|
withRefresh?: boolean
|
|
50
51
|
) => {
|
|
51
|
-
|
|
52
|
+
RecognizerSession.updateAutoFinishTime(newTimeMs, withRefresh)
|
|
52
53
|
}
|
|
53
54
|
|
|
54
55
|
/**
|
|
55
56
|
* Safe, lifecycle-aware hook to use the recognizer.
|
|
57
|
+
*
|
|
58
|
+
* @param callbacks - The callbacks to use for the recognizer.
|
|
59
|
+
* @param destroyDeps - The additional dependencies to use for the cleanup effect.
|
|
60
|
+
*
|
|
61
|
+
* Example: To cleanup when the screen is unfocused.
|
|
62
|
+
*
|
|
63
|
+
* ```typescript
|
|
64
|
+
* const isFocused = useIsFocused()
|
|
65
|
+
* useRecognizer({ ... }, [isFocused])
|
|
66
|
+
* ```
|
|
56
67
|
*/
|
|
57
68
|
export const useRecognizer = (
|
|
58
|
-
callbacks: RecognizerCallbacks
|
|
69
|
+
callbacks: RecognizerCallbacks,
|
|
70
|
+
destroyDeps: React.DependencyList = []
|
|
59
71
|
): RecognizerHandlers => {
|
|
60
72
|
React.useEffect(() => {
|
|
61
|
-
|
|
73
|
+
RecognizerSession.onReadyForSpeech = () => {
|
|
62
74
|
callbacks.onReadyForSpeech?.()
|
|
63
75
|
}
|
|
64
|
-
|
|
76
|
+
RecognizerSession.onRecordingStopped = () => {
|
|
65
77
|
callbacks.onRecordingStopped?.()
|
|
66
78
|
}
|
|
67
|
-
|
|
79
|
+
RecognizerSession.onResult = (resultBatches: string[]) => {
|
|
68
80
|
callbacks.onResult?.(resultBatches)
|
|
69
81
|
}
|
|
70
|
-
|
|
82
|
+
RecognizerSession.onAutoFinishProgress = (timeLeftMs: number) => {
|
|
71
83
|
callbacks.onAutoFinishProgress?.(timeLeftMs)
|
|
72
84
|
}
|
|
73
|
-
|
|
85
|
+
RecognizerSession.onError = (message: string) => {
|
|
74
86
|
callbacks.onError?.(message)
|
|
75
87
|
}
|
|
76
|
-
|
|
88
|
+
RecognizerSession.onPermissionDenied = () => {
|
|
77
89
|
callbacks.onPermissionDenied?.()
|
|
78
90
|
}
|
|
79
91
|
return () => {
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
92
|
+
RecognizerSession.onReadyForSpeech = undefined
|
|
93
|
+
RecognizerSession.onRecordingStopped = undefined
|
|
94
|
+
RecognizerSession.onResult = undefined
|
|
95
|
+
RecognizerSession.onAutoFinishProgress = undefined
|
|
96
|
+
RecognizerSession.onError = undefined
|
|
97
|
+
RecognizerSession.onPermissionDenied = undefined
|
|
86
98
|
}
|
|
87
99
|
}, [callbacks])
|
|
88
100
|
|
|
89
101
|
React.useEffect(() => {
|
|
90
102
|
return () => {
|
|
91
|
-
|
|
103
|
+
RecognizerSession.stopListening()
|
|
92
104
|
}
|
|
93
|
-
}, [])
|
|
105
|
+
}, [...destroyDeps])
|
|
94
106
|
|
|
95
107
|
return {
|
|
96
108
|
startListening: recognizerStartListening,
|
|
@@ -100,4 +112,14 @@ export const useRecognizer = (
|
|
|
100
112
|
}
|
|
101
113
|
}
|
|
102
114
|
|
|
115
|
+
/**
|
|
116
|
+
* Safe reference to the Recognizer methods.
|
|
117
|
+
*/
|
|
118
|
+
export const RecognizerRef = {
|
|
119
|
+
startListening: recognizerStartListening,
|
|
120
|
+
stopListening: recognizerStopListening,
|
|
121
|
+
addAutoFinishTime: recognizerAddAutoFinishTime,
|
|
122
|
+
updateAutoFinishTime: recognizerUpdateAutoFinishTime,
|
|
123
|
+
}
|
|
124
|
+
|
|
103
125
|
export type { RecognizerCallbacks, RecognizerHandlers, SpeechToTextParams }
|
|
@@ -44,6 +44,8 @@ interface ParamsIOS {
|
|
|
44
44
|
iosAddPunctuation?: boolean
|
|
45
45
|
}
|
|
46
46
|
|
|
47
|
+
type HapticFeedbackStyle = 'light' | 'medium' | 'heavy'
|
|
48
|
+
|
|
47
49
|
export interface SpeechToTextParams extends ParamsAndroid, ParamsIOS {
|
|
48
50
|
/**
|
|
49
51
|
* Default - "en-US"
|
|
@@ -65,6 +67,18 @@ export interface SpeechToTextParams extends ParamsAndroid, ParamsIOS {
|
|
|
65
67
|
* An array of strings that should be recognized, even if they are not in the system vocabulary.
|
|
66
68
|
*/
|
|
67
69
|
contextualStrings?: string[]
|
|
70
|
+
/**
|
|
71
|
+
* Default - null
|
|
72
|
+
*
|
|
73
|
+
* Haptic feedback style when microphone starts recording.
|
|
74
|
+
*/
|
|
75
|
+
startHapticFeedbackStyle?: HapticFeedbackStyle
|
|
76
|
+
/**
|
|
77
|
+
* Default - null
|
|
78
|
+
*
|
|
79
|
+
* Haptic feedback style when microphone stops recording.
|
|
80
|
+
*/
|
|
81
|
+
stopHapticFeedbackStyle?: HapticFeedbackStyle
|
|
68
82
|
}
|
|
69
83
|
|
|
70
84
|
export interface Recognizer extends HybridObject<{
|