dmed-voice-assistant 1.2.9 → 1.2.10

Sign up to get free protection for your applications and to get access to all the features.
@@ -90,6 +90,7 @@ const Recognition = _ref4 => {
90
90
  const languageList = ['Auto-Detect', 'English', 'Chinese (Simplified)'];
91
91
  const [selectedLanguage, setSelectedLanguage] = (0, _react.useState)(0);
92
92
  const recognitionBoxRef = (0, _react.useRef)(null);
93
+ const isClickedStopRef = (0, _react.useRef)(false);
93
94
  const recognitionRef = (0, _react.useRef)(null);
94
95
  const mediaRecorderRef = (0, _react.useRef)(null);
95
96
  const [result, setResult] = (0, _react.useState)([]);
@@ -166,6 +167,7 @@ const Recognition = _ref4 => {
166
167
  setRecordTime(prevCount => prevCount + 1);
167
168
  }, 1000);
168
169
  setIntervalId(id);
170
+ isClickedStopRef.current = false;
169
171
  recognitionRef.current.start();
170
172
  }
171
173
  } catch (error) {
@@ -174,6 +176,7 @@ const Recognition = _ref4 => {
174
176
  };
175
177
  const stopRecording = () => {
176
178
  if (recognitionRef.current && mediaRecorderRef.current) {
179
+ isClickedStopRef.current = true;
177
180
  recognitionRef.current.stop();
178
181
  if (onRecognitionStopEvent) {
179
182
  onRecognitionStopEvent();
@@ -249,8 +252,12 @@ const Recognition = _ref4 => {
249
252
  console.error('Speech recognition error:', event.error);
250
253
  };
251
254
  recognition.onend = () => {
252
- setIsStarted(false);
253
- clearInterval(intervalId);
255
+ if (!isClickedStopRef.current && recognitionRef.current) {
256
+ recognitionRef.current.start();
257
+ } else {
258
+ setIsStarted(false);
259
+ clearInterval(intervalId);
260
+ }
254
261
  console.log('Speech recognition ended');
255
262
  };
256
263
  recognitionRef.current = recognition;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dmed-voice-assistant",
3
- "version": "1.2.9",
3
+ "version": "1.2.10",
4
4
  "main": "dist/index.js",
5
5
  "files": [
6
6
  "dist"