@dreamtree-org/twreact-ui 1.1.31 → 1.1.33

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,sFA2OE;kBAlPK,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();
@@ -16245,32 +16245,26 @@ var SpeechToText = /*#__PURE__*/forwardRef(function (_ref, ref) {
16245
16245
  if (!isMountedRef.current) return;
16246
16246
  setIsListening(true);
16247
16247
  setError(null);
16248
+ console.log("debuggin is oned");
16248
16249
  onStart();
16249
16250
  };
16250
16251
  recognition.onresult = function (event) {
16251
- console.log("event", {
16252
- event: event,
16253
- isMountedRef: isMountedRef
16254
- });
16255
16252
  if (!isMountedRef.current) return;
16256
- console.log("recognition.onresult");
16257
16253
  var interim = "";
16254
+ var finalChunk = "";
16258
16255
  for (var i = event.resultIndex; i < event.results.length; i++) {
16259
16256
  var _res$;
16260
16257
  var res = event.results[i];
16261
16258
  var text = ((_res$ = res[0]) === null || _res$ === void 0 ? void 0 : _res$.transcript) || "";
16262
16259
  if (res.isFinal) {
16263
- finalTranscriptRef.current = (finalTranscriptRef.current + " " + text).trim();
16260
+ finalChunk += text + " ";
16261
+ finalTranscriptRef.current += text + " ";
16264
16262
  } else {
16265
16263
  interim += text;
16266
16264
  }
16267
16265
  }
16268
16266
  if (interim) onSpeaking(interim.trim());
16269
- var finalTranscript = buildFinalTranscript();
16270
- if (finalTranscript && finalTranscript !== lastEmittedFinalRef.current) {
16271
- lastEmittedFinalRef.current = finalTranscript;
16272
- onSpeechComplete(finalTranscript);
16273
- }
16267
+ if (finalChunk) onSpeechComplete(finalChunk.trim());
16274
16268
  };
16275
16269
  recognition.onerror = function (event) {
16276
16270
  var err = new Error((event === null || event === void 0 ? void 0 : event.error) || "Speech recognition error");
@@ -16281,11 +16275,14 @@ var SpeechToText = /*#__PURE__*/forwardRef(function (_ref, ref) {
16281
16275
  recognition.onend = function () {
16282
16276
  if (!isMountedRef.current) return;
16283
16277
  setIsListening(false);
16284
- var finalTranscript = buildFinalTranscript();
16285
- if (finalTranscript && finalTranscript !== lastEmittedFinalRef.current) {
16286
- lastEmittedFinalRef.current = finalTranscript;
16287
- onSpeechComplete(finalTranscript);
16288
- }
16278
+ buildFinalTranscript();
16279
+ // if (
16280
+ // finalTranscript &&
16281
+ // finalTranscript !== lastEmittedFinalRef.current
16282
+ // ) {
16283
+ // lastEmittedFinalRef.current = finalTranscript;
16284
+ // onSpeechComplete(finalTranscript);
16285
+ // }
16289
16286
  onStop();
16290
16287
  };
16291
16288
  recognitionRef.current = recognition;
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();
@@ -16265,32 +16265,26 @@ var SpeechToText = /*#__PURE__*/React.forwardRef(function (_ref, ref) {
16265
16265
  if (!isMountedRef.current) return;
16266
16266
  setIsListening(true);
16267
16267
  setError(null);
16268
+ console.log("debuggin is oned");
16268
16269
  onStart();
16269
16270
  };
16270
16271
  recognition.onresult = function (event) {
16271
- console.log("event", {
16272
- event: event,
16273
- isMountedRef: isMountedRef
16274
- });
16275
16272
  if (!isMountedRef.current) return;
16276
- console.log("recognition.onresult");
16277
16273
  var interim = "";
16274
+ var finalChunk = "";
16278
16275
  for (var i = event.resultIndex; i < event.results.length; i++) {
16279
16276
  var _res$;
16280
16277
  var res = event.results[i];
16281
16278
  var text = ((_res$ = res[0]) === null || _res$ === void 0 ? void 0 : _res$.transcript) || "";
16282
16279
  if (res.isFinal) {
16283
- finalTranscriptRef.current = (finalTranscriptRef.current + " " + text).trim();
16280
+ finalChunk += text + " ";
16281
+ finalTranscriptRef.current += text + " ";
16284
16282
  } else {
16285
16283
  interim += text;
16286
16284
  }
16287
16285
  }
16288
16286
  if (interim) onSpeaking(interim.trim());
16289
- var finalTranscript = buildFinalTranscript();
16290
- if (finalTranscript && finalTranscript !== lastEmittedFinalRef.current) {
16291
- lastEmittedFinalRef.current = finalTranscript;
16292
- onSpeechComplete(finalTranscript);
16293
- }
16287
+ if (finalChunk) onSpeechComplete(finalChunk.trim());
16294
16288
  };
16295
16289
  recognition.onerror = function (event) {
16296
16290
  var err = new Error((event === null || event === void 0 ? void 0 : event.error) || "Speech recognition error");
@@ -16301,11 +16295,14 @@ var SpeechToText = /*#__PURE__*/React.forwardRef(function (_ref, ref) {
16301
16295
  recognition.onend = function () {
16302
16296
  if (!isMountedRef.current) return;
16303
16297
  setIsListening(false);
16304
- var finalTranscript = buildFinalTranscript();
16305
- if (finalTranscript && finalTranscript !== lastEmittedFinalRef.current) {
16306
- lastEmittedFinalRef.current = finalTranscript;
16307
- onSpeechComplete(finalTranscript);
16308
- }
16298
+ buildFinalTranscript();
16299
+ // if (
16300
+ // finalTranscript &&
16301
+ // finalTranscript !== lastEmittedFinalRef.current
16302
+ // ) {
16303
+ // lastEmittedFinalRef.current = finalTranscript;
16304
+ // onSpeechComplete(finalTranscript);
16305
+ // }
16309
16306
  onStop();
16310
16307
  };
16311
16308
  recognitionRef.current = recognition;
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.33",
4
4
  "description": "A comprehensive React + Tailwind components library for building modern web apps",
5
5
  "author": {
6
6
  "name": "Partha Preetham Krishna",