@contentgrowth/llm-service 0.9.4 → 0.9.5
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.
|
@@ -203,6 +203,12 @@ var useSpeechRecognition = (onResult, onEnd, language = "en-US") => {
|
|
|
203
203
|
const recognitionRef = (0, import_react2.useRef)(null);
|
|
204
204
|
const isSimulatingRef = (0, import_react2.useRef)(false);
|
|
205
205
|
const simulationTimeoutRef = (0, import_react2.useRef)(null);
|
|
206
|
+
const onResultRef = (0, import_react2.useRef)(onResult);
|
|
207
|
+
const onEndRef = (0, import_react2.useRef)(onEnd);
|
|
208
|
+
(0, import_react2.useEffect)(() => {
|
|
209
|
+
onResultRef.current = onResult;
|
|
210
|
+
onEndRef.current = onEnd;
|
|
211
|
+
}, [onResult, onEnd]);
|
|
206
212
|
(0, import_react2.useEffect)(() => {
|
|
207
213
|
if (typeof window !== "undefined") {
|
|
208
214
|
const SpeechRecognition = window.SpeechRecognition || window.webkitSpeechRecognition;
|
|
@@ -221,7 +227,7 @@ var useSpeechRecognition = (onResult, onEnd, language = "en-US") => {
|
|
|
221
227
|
return;
|
|
222
228
|
}
|
|
223
229
|
setIsListening(false);
|
|
224
|
-
if (
|
|
230
|
+
if (onEndRef.current) onEndRef.current();
|
|
225
231
|
};
|
|
226
232
|
recognition.onresult = (event) => {
|
|
227
233
|
let interimTranscript = "";
|
|
@@ -230,10 +236,10 @@ var useSpeechRecognition = (onResult, onEnd, language = "en-US") => {
|
|
|
230
236
|
const result = event.results[i];
|
|
231
237
|
if (result.isFinal) {
|
|
232
238
|
finalTranscript += result[0].transcript;
|
|
233
|
-
if (
|
|
239
|
+
if (onResultRef.current) onResultRef.current(finalTranscript, true);
|
|
234
240
|
} else {
|
|
235
241
|
interimTranscript += result[0].transcript;
|
|
236
|
-
if (
|
|
242
|
+
if (onResultRef.current) onResultRef.current(interimTranscript, false);
|
|
237
243
|
}
|
|
238
244
|
}
|
|
239
245
|
setTranscript((prev) => prev + finalTranscript);
|
|
@@ -248,10 +254,10 @@ var useSpeechRecognition = (onResult, onEnd, language = "en-US") => {
|
|
|
248
254
|
simulationTimeoutRef.current = setTimeout(() => {
|
|
249
255
|
const mockText = "This is a simulated voice input for testing.";
|
|
250
256
|
setTranscript((prev) => prev + (prev ? " " : "") + mockText);
|
|
251
|
-
if (
|
|
257
|
+
if (onResultRef.current) onResultRef.current(mockText, true);
|
|
252
258
|
isSimulatingRef.current = false;
|
|
253
259
|
setIsListening(false);
|
|
254
|
-
if (
|
|
260
|
+
if (onEndRef.current) onEndRef.current();
|
|
255
261
|
simulationTimeoutRef.current = null;
|
|
256
262
|
}, 3e3);
|
|
257
263
|
return;
|
|
@@ -268,9 +274,11 @@ var useSpeechRecognition = (onResult, onEnd, language = "en-US") => {
|
|
|
268
274
|
clearTimeout(simulationTimeoutRef.current);
|
|
269
275
|
simulationTimeoutRef.current = null;
|
|
270
276
|
}
|
|
271
|
-
recognitionRef.current
|
|
277
|
+
if (recognitionRef.current) {
|
|
278
|
+
recognitionRef.current.stop();
|
|
279
|
+
}
|
|
272
280
|
};
|
|
273
|
-
}, [
|
|
281
|
+
}, [language]);
|
|
274
282
|
const start = (0, import_react2.useCallback)(() => {
|
|
275
283
|
if (recognitionRef.current && !isListening) {
|
|
276
284
|
try {
|
|
@@ -290,10 +298,10 @@ var useSpeechRecognition = (onResult, onEnd, language = "en-US") => {
|
|
|
290
298
|
}
|
|
291
299
|
const mockText = "This is a simulated voice input for testing.";
|
|
292
300
|
setTranscript((prev) => prev + (prev ? " " : "") + mockText);
|
|
293
|
-
if (
|
|
301
|
+
if (onResultRef.current) onResultRef.current(mockText, true);
|
|
294
302
|
isSimulatingRef.current = false;
|
|
295
303
|
setIsListening(false);
|
|
296
|
-
if (
|
|
304
|
+
if (onEndRef.current) onEndRef.current();
|
|
297
305
|
return;
|
|
298
306
|
}
|
|
299
307
|
if (recognitionRef.current && isListening) {
|