@dreamtree-org/twreact-ui 1.1.31 → 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,sFAoPE;kBA3PK,OAAO"}
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
@@ -16188,7 +16188,7 @@ var SpeechToText = /*#__PURE__*/forwardRef(function (_ref, ref) {
16188
16188
  _ref$resetOnStart = _ref.resetOnStart,
16189
16189
  resetOnStart = _ref$resetOnStart === void 0 ? false : _ref$resetOnStart;
16190
16190
  var recognitionRef = useRef(null);
16191
- var isMountedRef = useRef(false);
16191
+ var isMountedRef = useRef(true);
16192
16192
  var finalTranscriptRef = useRef("");
16193
16193
  var lastEmittedFinalRef = useRef("");
16194
16194
  var _useState = useState(false),
@@ -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 = true;
16208
+ // isMountedRef.current = true;
16209
16209
  if (recognitionRef.current) {
16210
16210
  try {
16211
16211
  recognitionRef.current.stop();
@@ -16248,29 +16248,21 @@ var SpeechToText = /*#__PURE__*/forwardRef(function (_ref, ref) {
16248
16248
  onStart();
16249
16249
  };
16250
16250
  recognition.onresult = function (event) {
16251
- console.log("event", {
16252
- event: event,
16253
- isMountedRef: isMountedRef
16254
- });
16255
16251
  if (!isMountedRef.current) return;
16256
- console.log("recognition.onresult");
16257
16252
  var interim = "";
16253
+ var finalChunk = "";
16258
16254
  for (var i = event.resultIndex; i < event.results.length; i++) {
16259
16255
  var _res$;
16260
16256
  var res = event.results[i];
16261
16257
  var text = ((_res$ = res[0]) === null || _res$ === void 0 ? void 0 : _res$.transcript) || "";
16262
16258
  if (res.isFinal) {
16263
- finalTranscriptRef.current = (finalTranscriptRef.current + " " + text).trim();
16259
+ finalChunk += text + " ";
16264
16260
  } else {
16265
16261
  interim += text;
16266
16262
  }
16267
16263
  }
16268
16264
  if (interim) onSpeaking(interim.trim());
16269
- var finalTranscript = buildFinalTranscript();
16270
- if (finalTranscript && finalTranscript !== lastEmittedFinalRef.current) {
16271
- lastEmittedFinalRef.current = finalTranscript;
16272
- onSpeechComplete(finalTranscript);
16273
- }
16265
+ if (finalChunk) onSpeechComplete(finalChunk.trim());
16274
16266
  };
16275
16267
  recognition.onerror = function (event) {
16276
16268
  var err = new Error((event === null || event === void 0 ? void 0 : event.error) || "Speech recognition error");
package/dist/index.js CHANGED
@@ -16208,7 +16208,7 @@ var SpeechToText = /*#__PURE__*/React.forwardRef(function (_ref, ref) {
16208
16208
  _ref$resetOnStart = _ref.resetOnStart,
16209
16209
  resetOnStart = _ref$resetOnStart === void 0 ? false : _ref$resetOnStart;
16210
16210
  var recognitionRef = React.useRef(null);
16211
- var isMountedRef = React.useRef(false);
16211
+ var isMountedRef = React.useRef(true);
16212
16212
  var finalTranscriptRef = React.useRef("");
16213
16213
  var lastEmittedFinalRef = React.useRef("");
16214
16214
  var _useState = React.useState(false),
@@ -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 = true;
16228
+ // isMountedRef.current = true;
16229
16229
  if (recognitionRef.current) {
16230
16230
  try {
16231
16231
  recognitionRef.current.stop();
@@ -16268,29 +16268,21 @@ var SpeechToText = /*#__PURE__*/React.forwardRef(function (_ref, ref) {
16268
16268
  onStart();
16269
16269
  };
16270
16270
  recognition.onresult = function (event) {
16271
- console.log("event", {
16272
- event: event,
16273
- isMountedRef: isMountedRef
16274
- });
16275
16271
  if (!isMountedRef.current) return;
16276
- console.log("recognition.onresult");
16277
16272
  var interim = "";
16273
+ var finalChunk = "";
16278
16274
  for (var i = event.resultIndex; i < event.results.length; i++) {
16279
16275
  var _res$;
16280
16276
  var res = event.results[i];
16281
16277
  var text = ((_res$ = res[0]) === null || _res$ === void 0 ? void 0 : _res$.transcript) || "";
16282
16278
  if (res.isFinal) {
16283
- finalTranscriptRef.current = (finalTranscriptRef.current + " " + text).trim();
16279
+ finalChunk += text + " ";
16284
16280
  } else {
16285
16281
  interim += text;
16286
16282
  }
16287
16283
  }
16288
16284
  if (interim) onSpeaking(interim.trim());
16289
- var finalTranscript = buildFinalTranscript();
16290
- if (finalTranscript && finalTranscript !== lastEmittedFinalRef.current) {
16291
- lastEmittedFinalRef.current = finalTranscript;
16292
- onSpeechComplete(finalTranscript);
16293
- }
16285
+ if (finalChunk) onSpeechComplete(finalChunk.trim());
16294
16286
  };
16295
16287
  recognition.onerror = function (event) {
16296
16288
  var err = new Error((event === null || event === void 0 ? void 0 : event.error) || "Speech recognition error");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dreamtree-org/twreact-ui",
3
- "version": "1.1.31",
3
+ "version": "1.1.32",
4
4
  "description": "A comprehensive React + Tailwind components library for building modern web apps",
5
5
  "author": {
6
6
  "name": "Partha Preetham Krishna",