@bytexbyte/nxtlinq-ai-agent-sdk 1.6.16 → 1.6.17
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/dist/components/context/ChatBotContext.d.ts.map +1 -1
- package/dist/components/context/ChatBotContext.js +217 -9
- package/dist/components/types/ChatBotTypes.d.ts +4 -1
- package/dist/components/types/ChatBotTypes.d.ts.map +1 -1
- package/dist/components/ui/BerifyMeModal.d.ts +5 -0
- package/dist/components/ui/BerifyMeModal.d.ts.map +1 -1
- package/dist/components/ui/BerifyMeModal.js +7 -5
- package/dist/components/ui/MessageInput.d.ts.map +1 -1
- package/dist/components/ui/MessageInput.js +64 -42
- package/dist/core/lib/useSpeechToTextFromMic/helper.d.ts +3 -3
- package/dist/core/lib/useSpeechToTextFromMic/helper.d.ts.map +1 -1
- package/dist/core/lib/useSpeechToTextFromMic/helper.js +14 -12
- package/dist/core/lib/useSpeechToTextFromMic/index.d.ts +1 -1
- package/dist/core/lib/useSpeechToTextFromMic/index.d.ts.map +1 -1
- package/dist/core/lib/useSpeechToTextFromMic/index.js +28 -21
- package/package.json +1 -1
- package/umd/nxtlinq-ai-agent.umd.js +142 -134
|
@@ -1,16 +1,15 @@
|
|
|
1
|
-
import { useEffect, useRef, useState } from 'react';
|
|
1
|
+
import { useCallback, useEffect, useRef, useState } from 'react';
|
|
2
2
|
import { startSpeechToTextFromMic, stopRecognition } from './helper';
|
|
3
3
|
export function useSpeechToTextFromMic({ apiKey, apiSecret, autoClearTranscript = true, }) {
|
|
4
|
-
const [
|
|
4
|
+
const [isMicEnabled, setIsMicEnabled] = useState(false);
|
|
5
5
|
const [transcriptArray, setTranscriptArray] = useState([]);
|
|
6
6
|
const [partialTranscript, setPartialTranscript] = useState('');
|
|
7
7
|
const [recognizer, setRecognizer] = useState();
|
|
8
8
|
const wakelock = useRef();
|
|
9
9
|
const historyRef = useRef([]);
|
|
10
10
|
const indexRef = useRef(0);
|
|
11
|
-
const
|
|
12
|
-
|
|
13
|
-
if (!canWakeLock())
|
|
11
|
+
const lockWakeState = useCallback(async () => {
|
|
12
|
+
if (typeof navigator === 'undefined' || !('wakeLock' in navigator))
|
|
14
13
|
return;
|
|
15
14
|
try {
|
|
16
15
|
wakelock.current = await navigator.wakeLock.request('screen');
|
|
@@ -21,26 +20,34 @@ export function useSpeechToTextFromMic({ apiKey, apiSecret, autoClearTranscript
|
|
|
21
20
|
catch (err) {
|
|
22
21
|
console.error('Wake lock error:', err);
|
|
23
22
|
}
|
|
24
|
-
}
|
|
25
|
-
const
|
|
23
|
+
}, []);
|
|
24
|
+
const clear = useCallback(() => {
|
|
25
|
+
historyRef.current = [];
|
|
26
|
+
indexRef.current = 0;
|
|
27
|
+
setTranscriptArray([]);
|
|
28
|
+
setPartialTranscript('');
|
|
29
|
+
}, [setPartialTranscript, setTranscriptArray]);
|
|
30
|
+
const start = useCallback(async () => {
|
|
26
31
|
clear();
|
|
27
32
|
await lockWakeState();
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
+
try {
|
|
34
|
+
const recognizerInstance = await startSpeechToTextFromMic(setTranscriptArray, { apiKey, apiSecret }, historyRef, indexRef, setPartialTranscript);
|
|
35
|
+
setRecognizer(recognizerInstance);
|
|
36
|
+
setIsMicEnabled(true);
|
|
37
|
+
}
|
|
38
|
+
catch (error) {
|
|
39
|
+
wakelock.current?.release();
|
|
40
|
+
setIsMicEnabled(false);
|
|
41
|
+
console.error('Failed to start speech recognition:', error);
|
|
42
|
+
throw error;
|
|
43
|
+
}
|
|
44
|
+
}, [apiKey, apiSecret, clear, lockWakeState, setPartialTranscript, setTranscriptArray]);
|
|
45
|
+
const stop = useCallback(() => {
|
|
33
46
|
wakelock.current?.release();
|
|
34
47
|
stopRecognition(recognizer);
|
|
35
|
-
|
|
48
|
+
setIsMicEnabled(false);
|
|
36
49
|
setRecognizer(undefined);
|
|
37
|
-
};
|
|
38
|
-
const clear = () => {
|
|
39
|
-
historyRef.current = [];
|
|
40
|
-
indexRef.current = 0;
|
|
41
|
-
setTranscriptArray([]);
|
|
42
|
-
setPartialTranscript('');
|
|
43
|
-
};
|
|
50
|
+
}, [recognizer, setRecognizer]);
|
|
44
51
|
useEffect(() => {
|
|
45
52
|
if (autoClearTranscript && transcriptArray.length > 0) {
|
|
46
53
|
const timer = setTimeout(() => {
|
|
@@ -54,7 +61,7 @@ export function useSpeechToTextFromMic({ apiKey, apiSecret, autoClearTranscript
|
|
|
54
61
|
start,
|
|
55
62
|
stop,
|
|
56
63
|
clear,
|
|
57
|
-
|
|
64
|
+
isMicEnabled,
|
|
58
65
|
transcript,
|
|
59
66
|
partialTranscript,
|
|
60
67
|
};
|
package/package.json
CHANGED