dmed-voice-assistant 1.2.6 → 1.2.8

Sign up to get free protection for your applications and to get access to all the features.
package/dist/index.js CHANGED
@@ -24,7 +24,10 @@ const VoiceAssistant = _ref => {
24
24
  onRecordDataChange,
25
25
  onNewRecognitionEvent,
26
26
  onRecognitionDataChange,
27
- onCloseRecognition
27
+ onCloseRecognition,
28
+ onRecognitionStartEvent,
29
+ onRecognitionStopEvent,
30
+ onRealTimeRecognitionCommandEvent
28
31
  } = _ref;
29
32
  const [mode, setMode] = (0, _react.useState)(!isOnlyRecognitionMode ? "recorder" : "recognition");
30
33
  return /*#__PURE__*/(0, _jsxRuntime.jsx)(_material.Box, {
@@ -41,10 +44,13 @@ const VoiceAssistant = _ref => {
41
44
  mode: mode,
42
45
  setMode: setMode,
43
46
  recognitionHistoryList: recognitionListValue,
47
+ onRealTimeRecognitionCommandEvent: onRealTimeRecognitionCommandEvent,
44
48
  onNewRecognitionEvent: onNewRecognitionEvent,
45
49
  onRecognitionDataChange: onRecognitionDataChange,
46
50
  isOnlyRecognitionMode: isOnlyRecognitionMode,
47
- onCloseRecognition: onCloseRecognition
51
+ onCloseRecognition: onCloseRecognition,
52
+ onRecognitionStartEvent: onRecognitionStartEvent,
53
+ onRecognitionStopEvent: onRecognitionStopEvent
48
54
  })]
49
55
  })
50
56
  });
@@ -75,7 +75,10 @@ const Recognition = _ref4 => {
75
75
  setMode,
76
76
  onNewRecognitionEvent,
77
77
  onRecognitionDataChange,
78
- onCloseRecognition
78
+ onCloseRecognition,
79
+ onRealTimeRecognitionCommandEvent,
80
+ onRecognitionStartEvent,
81
+ onRecognitionStopEvent
79
82
  } = _ref4;
80
83
  const [open, setOpen] = (0, _react.useState)(false);
81
84
  const [anchorEl, setAnchorEl] = (0, _react.useState)(null);
@@ -153,6 +156,9 @@ const Recognition = _ref4 => {
153
156
  mediaRecorderRef.current = newRecorder;
154
157
  }
155
158
  mediaRecorderRef.current.start();
159
+ if (onRecognitionStartEvent) {
160
+ onRecognitionStartEvent();
161
+ }
156
162
  setResult([]);
157
163
  setRecordTime(0);
158
164
  const id = setInterval(async () => {
@@ -168,6 +174,9 @@ const Recognition = _ref4 => {
168
174
  const stopRecording = () => {
169
175
  if (recognitionRef.current && mediaRecorderRef.current) {
170
176
  recognitionRef.current.stop();
177
+ if (onRecognitionStopEvent) {
178
+ onRecognitionStopEvent();
179
+ }
171
180
  clearInterval(intervalId);
172
181
  mediaRecorderRef.current.stop().then(async _ref5 => {
173
182
  let {
@@ -226,6 +235,14 @@ const Recognition = _ref4 => {
226
235
  }
227
236
  return updatedTranscript;
228
237
  });
238
+ for (let i = event.resultIndex; i < event.results.length; i++) {
239
+ if (event.results[i].isFinal) {
240
+ const resultArr = event.results[i][0].transcript.split(' ').filter(word => word.trim() !== '');
241
+ if (onRealTimeRecognitionCommandEvent) {
242
+ onRealTimeRecognitionCommandEvent(resultArr);
243
+ }
244
+ }
245
+ }
229
246
  };
230
247
  recognition.onerror = event => {
231
248
  console.error('Speech recognition error:', event.error);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dmed-voice-assistant",
3
- "version": "1.2.6",
3
+ "version": "1.2.8",
4
4
  "main": "dist/index.js",
5
5
  "files": [
6
6
  "dist"