@dreamtree-org/twreact-ui 1.1.30 → 1.1.32
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.
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SpeechToText.d.ts","sourceRoot":"","sources":["../../../src/components/core/SpeechToText.jsx"],"names":[],"mappings":";AAcA,
|
|
1
|
+
{"version":3,"file":"SpeechToText.d.ts","sourceRoot":"","sources":["../../../src/components/core/SpeechToText.jsx"],"names":[],"mappings":";AAcA,sFAwOE;kBA/OK,OAAO"}
|
package/dist/index.esm.js
CHANGED
|
@@ -16205,7 +16205,7 @@ var SpeechToText = /*#__PURE__*/forwardRef(function (_ref, ref) {
|
|
|
16205
16205
|
setError = _useState6[1];
|
|
16206
16206
|
useEffect(function () {
|
|
16207
16207
|
return function () {
|
|
16208
|
-
isMountedRef.current =
|
|
16208
|
+
// isMountedRef.current = true;
|
|
16209
16209
|
if (recognitionRef.current) {
|
|
16210
16210
|
try {
|
|
16211
16211
|
recognitionRef.current.stop();
|
|
@@ -16214,7 +16214,9 @@ var SpeechToText = /*#__PURE__*/forwardRef(function (_ref, ref) {
|
|
|
16214
16214
|
};
|
|
16215
16215
|
}, []);
|
|
16216
16216
|
useEffect(function () {
|
|
16217
|
-
var
|
|
16217
|
+
var isNotSupported = typeof window === "undefined";
|
|
16218
|
+
var hasSpeechRecognition = "SpeechRecognition" in window || "webkitSpeechRecognition" in window;
|
|
16219
|
+
var supported = !isNotSupported && hasSpeechRecognition;
|
|
16218
16220
|
setIsSupported(supported);
|
|
16219
16221
|
}, []);
|
|
16220
16222
|
useEffect(function () {
|
|
@@ -16239,6 +16241,7 @@ var SpeechToText = /*#__PURE__*/forwardRef(function (_ref, ref) {
|
|
|
16239
16241
|
recognition.interimResults = interimResults;
|
|
16240
16242
|
recognition.lang = lang;
|
|
16241
16243
|
recognition.onstart = function () {
|
|
16244
|
+
console.log("recognition.onstart");
|
|
16242
16245
|
if (!isMountedRef.current) return;
|
|
16243
16246
|
setIsListening(true);
|
|
16244
16247
|
setError(null);
|
|
@@ -16247,22 +16250,19 @@ var SpeechToText = /*#__PURE__*/forwardRef(function (_ref, ref) {
|
|
|
16247
16250
|
recognition.onresult = function (event) {
|
|
16248
16251
|
if (!isMountedRef.current) return;
|
|
16249
16252
|
var interim = "";
|
|
16253
|
+
var finalChunk = "";
|
|
16250
16254
|
for (var i = event.resultIndex; i < event.results.length; i++) {
|
|
16251
16255
|
var _res$;
|
|
16252
16256
|
var res = event.results[i];
|
|
16253
16257
|
var text = ((_res$ = res[0]) === null || _res$ === void 0 ? void 0 : _res$.transcript) || "";
|
|
16254
16258
|
if (res.isFinal) {
|
|
16255
|
-
|
|
16259
|
+
finalChunk += text + " ";
|
|
16256
16260
|
} else {
|
|
16257
16261
|
interim += text;
|
|
16258
16262
|
}
|
|
16259
16263
|
}
|
|
16260
16264
|
if (interim) onSpeaking(interim.trim());
|
|
16261
|
-
|
|
16262
|
-
if (finalTranscript && finalTranscript !== lastEmittedFinalRef.current) {
|
|
16263
|
-
lastEmittedFinalRef.current = finalTranscript;
|
|
16264
|
-
onSpeechComplete(finalTranscript);
|
|
16265
|
-
}
|
|
16265
|
+
if (finalChunk) onSpeechComplete(finalChunk.trim());
|
|
16266
16266
|
};
|
|
16267
16267
|
recognition.onerror = function (event) {
|
|
16268
16268
|
var err = new Error((event === null || event === void 0 ? void 0 : event.error) || "Speech recognition error");
|
package/dist/index.js
CHANGED
|
@@ -16225,7 +16225,7 @@ var SpeechToText = /*#__PURE__*/React.forwardRef(function (_ref, ref) {
|
|
|
16225
16225
|
setError = _useState6[1];
|
|
16226
16226
|
React.useEffect(function () {
|
|
16227
16227
|
return function () {
|
|
16228
|
-
isMountedRef.current =
|
|
16228
|
+
// isMountedRef.current = true;
|
|
16229
16229
|
if (recognitionRef.current) {
|
|
16230
16230
|
try {
|
|
16231
16231
|
recognitionRef.current.stop();
|
|
@@ -16234,7 +16234,9 @@ var SpeechToText = /*#__PURE__*/React.forwardRef(function (_ref, ref) {
|
|
|
16234
16234
|
};
|
|
16235
16235
|
}, []);
|
|
16236
16236
|
React.useEffect(function () {
|
|
16237
|
-
var
|
|
16237
|
+
var isNotSupported = typeof window === "undefined";
|
|
16238
|
+
var hasSpeechRecognition = "SpeechRecognition" in window || "webkitSpeechRecognition" in window;
|
|
16239
|
+
var supported = !isNotSupported && hasSpeechRecognition;
|
|
16238
16240
|
setIsSupported(supported);
|
|
16239
16241
|
}, []);
|
|
16240
16242
|
React.useEffect(function () {
|
|
@@ -16259,6 +16261,7 @@ var SpeechToText = /*#__PURE__*/React.forwardRef(function (_ref, ref) {
|
|
|
16259
16261
|
recognition.interimResults = interimResults;
|
|
16260
16262
|
recognition.lang = lang;
|
|
16261
16263
|
recognition.onstart = function () {
|
|
16264
|
+
console.log("recognition.onstart");
|
|
16262
16265
|
if (!isMountedRef.current) return;
|
|
16263
16266
|
setIsListening(true);
|
|
16264
16267
|
setError(null);
|
|
@@ -16267,22 +16270,19 @@ var SpeechToText = /*#__PURE__*/React.forwardRef(function (_ref, ref) {
|
|
|
16267
16270
|
recognition.onresult = function (event) {
|
|
16268
16271
|
if (!isMountedRef.current) return;
|
|
16269
16272
|
var interim = "";
|
|
16273
|
+
var finalChunk = "";
|
|
16270
16274
|
for (var i = event.resultIndex; i < event.results.length; i++) {
|
|
16271
16275
|
var _res$;
|
|
16272
16276
|
var res = event.results[i];
|
|
16273
16277
|
var text = ((_res$ = res[0]) === null || _res$ === void 0 ? void 0 : _res$.transcript) || "";
|
|
16274
16278
|
if (res.isFinal) {
|
|
16275
|
-
|
|
16279
|
+
finalChunk += text + " ";
|
|
16276
16280
|
} else {
|
|
16277
16281
|
interim += text;
|
|
16278
16282
|
}
|
|
16279
16283
|
}
|
|
16280
16284
|
if (interim) onSpeaking(interim.trim());
|
|
16281
|
-
|
|
16282
|
-
if (finalTranscript && finalTranscript !== lastEmittedFinalRef.current) {
|
|
16283
|
-
lastEmittedFinalRef.current = finalTranscript;
|
|
16284
|
-
onSpeechComplete(finalTranscript);
|
|
16285
|
-
}
|
|
16285
|
+
if (finalChunk) onSpeechComplete(finalChunk.trim());
|
|
16286
16286
|
};
|
|
16287
16287
|
recognition.onerror = function (event) {
|
|
16288
16288
|
var err = new Error((event === null || event === void 0 ? void 0 : event.error) || "Speech recognition error");
|