dmed-voice-assistant 1.2.3 → 1.2.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,47 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.default = void 0;
8
+ var _react = _interopRequireDefault(require("react"));
9
+ var _material = require("@mui/material");
10
+ var _jsxRuntime = require("react/jsx-runtime");
11
+ const HistoryDropdownItem = _ref => {
12
+ let {
13
+ data,
14
+ setDate,
15
+ handlePopoverClose
16
+ } = _ref;
17
+ const handleClick = () => {
18
+ setDate(data.date);
19
+ handlePopoverClose();
20
+ };
21
+ return /*#__PURE__*/(0, _jsxRuntime.jsxs)(_material.Box, {
22
+ className: "flex items-center justify-between rounded-[5px] px-[10px] py-[3px] cursor-pointer",
23
+ sx: {
24
+ '&:hover': {
25
+ background: '#F6F6F6'
26
+ }
27
+ },
28
+ onClick: handleClick,
29
+ children: [/*#__PURE__*/(0, _jsxRuntime.jsxs)(_material.Box, {
30
+ className: "flex items-center space-x-1",
31
+ children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_material.Typography, {
32
+ className: "!font-bold !text-[14px]",
33
+ color: "#494A48",
34
+ children: data.count
35
+ }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_material.Typography, {
36
+ className: "!font-400 !text-[12px]",
37
+ color: "#494A48",
38
+ children: "words"
39
+ })]
40
+ }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_material.Typography, {
41
+ className: "!font-400 !text-[14px]",
42
+ color: "#494A48",
43
+ children: data.date
44
+ })]
45
+ });
46
+ };
47
+ var _default = exports.default = HistoryDropdownItem;
@@ -20,7 +20,7 @@ const RecognitionListItem = _ref => {
20
20
  children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_material.Typography, {
21
21
  className: "!font-bold !text-[14px]",
22
22
  color: "#494A48",
23
- children: data.result.length
23
+ children: data.voice_words?.split(",").length
24
24
  }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_material.Typography, {
25
25
  className: "!font-400 !text-[12px]",
26
26
  color: "#494A48",
@@ -29,7 +29,7 @@ const RecognitionListItem = _ref => {
29
29
  }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_material.Typography, {
30
30
  className: "px-[4px] !font-400 !text-[14px]",
31
31
  color: "#494A48",
32
- children: data.date.toLocaleTimeString('en-US', {
32
+ children: new Date(data.created_at * 1000).toLocaleTimeString('en-US', {
33
33
  hour: '2-digit',
34
34
  minute: '2-digit',
35
35
  hour12: true
@@ -41,7 +41,7 @@ const RecognitionListItem = _ref => {
41
41
  maxWidth: "387px",
42
42
  overflow: "hidden"
43
43
  },
44
- children: data.result.map((item, index) => {
44
+ children: data.voice_words?.split(",").map((item, index) => {
45
45
  return /*#__PURE__*/(0, _jsxRuntime.jsxs)(_material.Box, {
46
46
  className: "flex items-center",
47
47
  children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_material.Typography, {
@@ -51,7 +51,7 @@ const RecognitionListItem = _ref => {
51
51
  fontFamily: "Space Grotesk !important"
52
52
  },
53
53
  children: item
54
- }), index !== data.result.length - 1 && /*#__PURE__*/(0, _jsxRuntime.jsx)(_material.Typography, {
54
+ }), index !== data.voice_words?.split(",").length - 1 && /*#__PURE__*/(0, _jsxRuntime.jsx)(_material.Typography, {
55
55
  className: "!font-400 !text-[16px]",
56
56
  color: "#494A4880",
57
57
  sx: {
@@ -11,6 +11,7 @@ var _svgs = require("./components/svgs");
11
11
  var _RecognitionListItem = _interopRequireDefault(require("./components/RecognitionListItem"));
12
12
  var _recorderJs = _interopRequireDefault(require("recorder-js"));
13
13
  var _recorder = require("./recorder");
14
+ var _HistoryDropdownItem = _interopRequireDefault(require("./components/HistoryDropdownItem"));
14
15
  var _jsxRuntime = require("react/jsx-runtime");
15
16
  function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
16
17
  function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
@@ -58,6 +59,14 @@ const StyledTypography = (0, _material.styled)(_material.Typography)(_ref3 => {
58
59
  lineHeight: '15.59px'
59
60
  };
60
61
  });
62
+ const formatDate = date => {
63
+ const day = date.getDate().toString().padStart(2, '0');
64
+ const month = date.toLocaleString('en-US', {
65
+ month: 'short'
66
+ });
67
+ const year = date.getFullYear();
68
+ return `${day}.${month}.${year}`;
69
+ };
61
70
  const Recognition = _ref4 => {
62
71
  let {
63
72
  mode = 'recorder',
@@ -75,13 +84,16 @@ const Recognition = _ref4 => {
75
84
  const [selectedVoice, setSelectedVoice] = (0, _react.useState)("");
76
85
  const [voiceList, setVoiceList] = (0, _react.useState)([]);
77
86
  const languageList = ['Auto-Detect', 'English', 'Chinese (Simplified)'];
78
- const [selectedLanguage, setSelectedLanguage] = (0, _react.useState)("en-US");
87
+ const [selectedLanguage, setSelectedLanguage] = (0, _react.useState)(0);
79
88
  const recognitionRef = (0, _react.useRef)(null);
80
89
  const mediaRecorderRef = (0, _react.useRef)(null);
81
90
  const [result, setResult] = (0, _react.useState)([]);
82
91
  const [historyList, setHistoryList] = (0, _react.useState)(recognitionHistoryList);
92
+ const [filterHistoryList, setFilterHistoryList] = (0, _react.useState)([]);
93
+ const [dropdownList, setDropdownList] = (0, _react.useState)([]);
83
94
  const [recordTime, setRecordTime] = (0, _react.useState)(0);
84
95
  const [intervalId, setIntervalId] = (0, _react.useState)(null);
96
+ const [selectedDate, setSelectedDate] = (0, _react.useState)(formatDate(new Date()));
85
97
  const handleClickOpen = () => {
86
98
  setOpen(true);
87
99
  };
@@ -124,6 +136,7 @@ const Recognition = _ref4 => {
124
136
  const startRecording = async () => {
125
137
  try {
126
138
  if (recognitionRef.current) {
139
+ recognitionRef.current.lang = selectedLanguage === 0 || selectedLanguage === 1 ? "en-US" : "zh-TW";
127
140
  if (!mediaRecorderRef.current) {
128
141
  const stream = await navigator.mediaDevices.getUserMedia({
129
142
  audio: true
@@ -154,22 +167,34 @@ const Recognition = _ref4 => {
154
167
  let {
155
168
  blob
156
169
  } = _ref5;
157
- const audioBlob = blob;
158
- let temp = [...historyList];
159
- const newData = {
160
- fileName: (0, _recorder.getVoiceFileName)(new Date()),
161
- audioBlob,
162
- result,
163
- lang: selectedLanguage,
164
- date: new Date()
165
- };
166
- temp.push(newData);
167
- setHistoryList(temp);
168
- if (onNewRecognitionEvent) {
169
- onNewRecognitionEvent(newData);
170
- }
171
- if (onRecognitionDataChange) {
172
- onRecognitionDataChange(temp);
170
+ if (result.length > 0) {
171
+ let temp = [...historyList];
172
+ const newData = {
173
+ created_at: Math.floor(new Date().getTime() / 1000),
174
+ file_name: (0, _recorder.getVoiceFileName)(new Date()),
175
+ link_id: "",
176
+ union_id: "",
177
+ voice_duration: "",
178
+ voice_file: URL.createObjectURL(blob),
179
+ voice_id: "",
180
+ voice_size: "",
181
+ voice_words: result.join(',')
182
+ };
183
+ temp.push(newData);
184
+ setHistoryList(temp);
185
+ setSelectedDate(formatDate(new Date()));
186
+ if (onNewRecognitionEvent) {
187
+ onNewRecognitionEvent({
188
+ fileName: (0, _recorder.getVoiceFileName)(new Date()),
189
+ audioBlob: blob,
190
+ result,
191
+ lang: selectedLanguage === 0 || selectedLanguage === 1 ? "en-US" : "zh-TW",
192
+ date: new Date()
193
+ });
194
+ }
195
+ if (onRecognitionDataChange) {
196
+ onRecognitionDataChange(temp);
197
+ }
173
198
  }
174
199
  });
175
200
  }
@@ -180,9 +205,9 @@ const Recognition = _ref4 => {
180
205
  const recognition = new SpeechRecognition();
181
206
  recognition.continuous = true;
182
207
  recognition.interimResults = true;
183
- recognition.lang = 'en-US';
208
+ recognition.lang = selectedLanguage === 0 || selectedLanguage === 1 ? "en-US" : "zh-TW";
184
209
  recognition.onstart = () => {
185
- console.log('Recording started');
210
+ console.log('Speech recognition started');
186
211
  };
187
212
  recognition.onresult = event => {
188
213
  setResult(prevTranscript => {
@@ -209,6 +234,15 @@ const Recognition = _ref4 => {
209
234
  console.error('Speech recognition not supported');
210
235
  }
211
236
  };
237
+ function formatDateTimestamp(timestamp) {
238
+ const date = new Date(timestamp * 1000);
239
+ const day = date.getDate().toString().padStart(2, '0');
240
+ const month = date.toLocaleString('en-US', {
241
+ month: 'short'
242
+ });
243
+ const year = date.getFullYear();
244
+ return `${day}.${month}.${year}`;
245
+ }
212
246
  (0, _react.useEffect)(() => {
213
247
  const fetchAudioInputDevices = async () => {
214
248
  try {
@@ -231,6 +265,40 @@ const Recognition = _ref4 => {
231
265
  startSpeechRecognition();
232
266
  fetchAudioInputDevices();
233
267
  }, []);
268
+ (0, _react.useEffect)(() => {
269
+ const groupedData = historyList.reduce((acc, item) => {
270
+ const date = formatDateTimestamp(item.created_at);
271
+ if (!acc[date]) {
272
+ acc[date] = [];
273
+ }
274
+ acc[date].push(item);
275
+ return acc;
276
+ }, {});
277
+ const dropdown = Object.keys(groupedData).map(date => {
278
+ const totalCount = groupedData[date].reduce((sum, item) => {
279
+ if (item.voice_words) {
280
+ sum += item.voice_words.split(',').length;
281
+ }
282
+ return sum;
283
+ }, 0);
284
+ return {
285
+ date: date,
286
+ count: totalCount
287
+ };
288
+ });
289
+ setDropdownList(dropdown);
290
+ }, [historyList]);
291
+ (0, _react.useEffect)(() => {
292
+ const groupedData = historyList.reduce((acc, item) => {
293
+ const date = formatDateTimestamp(item.created_at);
294
+ if (!acc[date]) {
295
+ acc[date] = [];
296
+ }
297
+ acc[date].push(item);
298
+ return acc;
299
+ }, {});
300
+ setFilterHistoryList(groupedData[selectedDate] ? groupedData[selectedDate] : []);
301
+ }, [selectedDate, historyList]);
234
302
  return /*#__PURE__*/(0, _jsxRuntime.jsxs)(_material.Box, {
235
303
  className: "bg-white rounded-[5px] p-[20px] w-[440px]",
236
304
  sx: {
@@ -421,14 +489,14 @@ const Recognition = _ref4 => {
421
489
  textTransform: "none"
422
490
  },
423
491
  onClick: handlePopoverOpen,
424
- children: "02.July.2024"
492
+ children: selectedDate
425
493
  })]
426
494
  }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_material.Box, {
427
495
  className: "flex flex-col scrollableBox mt-1",
428
496
  sx: {
429
497
  maxHeight: "160px"
430
498
  },
431
- children: historyList.map((history, index) => {
499
+ children: filterHistoryList.map((history, index) => {
432
500
  return /*#__PURE__*/(0, _jsxRuntime.jsx)(_RecognitionListItem.default, {
433
501
  data: history
434
502
  }, index);
@@ -591,13 +659,13 @@ const Recognition = _ref4 => {
591
659
  }
592
660
  },
593
661
  children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_material.MenuItem, {
594
- value: "en-US",
662
+ value: 0,
595
663
  children: "Auto-Detect"
596
664
  }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_material.MenuItem, {
597
- value: "en-US",
665
+ value: 1,
598
666
  children: "English"
599
667
  }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_material.MenuItem, {
600
- value: "zh-TW",
668
+ value: 2,
601
669
  children: "Chinese (Simplified)"
602
670
  })]
603
671
  })]
@@ -961,47 +1029,18 @@ const Recognition = _ref4 => {
961
1029
  color: "#494A48B2",
962
1030
  children: "Data"
963
1031
  })
964
- }), /*#__PURE__*/(0, _jsxRuntime.jsxs)(_material.Box, {
965
- className: "flex items-center justify-between rounded-[5px] px-[10px] py-[3px] cursor-pointer",
1032
+ }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_material.Box, {
1033
+ className: "flex flex-col scrollableBox mt-1",
966
1034
  sx: {
967
- '&:hover': {
968
- background: '#F6F6F6'
969
- }
1035
+ maxHeight: "110px"
970
1036
  },
971
- children: [/*#__PURE__*/(0, _jsxRuntime.jsxs)(_material.Box, {
972
- className: "flex items-center space-x-1",
973
- children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_material.Typography, {
974
- className: "!font-bold !text-[14px]",
975
- color: "#494A48",
976
- children: "7"
977
- }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_material.Typography, {
978
- className: "!font-400 !text-[12px]",
979
- color: "#494A48",
980
- children: "words"
981
- })]
982
- }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_material.Typography, {
983
- className: "!font-400 !text-[14px]",
984
- color: "#494A48",
985
- children: "02.July.2024"
986
- })]
987
- }), /*#__PURE__*/(0, _jsxRuntime.jsxs)(_material.Box, {
988
- className: "flex items-center justify-between px-[10px] py-[3px]",
989
- children: [/*#__PURE__*/(0, _jsxRuntime.jsxs)(_material.Box, {
990
- className: "flex items-center space-x-1",
991
- children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_material.Typography, {
992
- className: "!font-bold !text-[14px]",
993
- color: "#494A48",
994
- children: "7"
995
- }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_material.Typography, {
996
- className: "!font-400 !text-[12px]",
997
- color: "#494A48",
998
- children: "words"
999
- })]
1000
- }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_material.Typography, {
1001
- className: "!font-400 !text-[14px]",
1002
- color: "#494A48",
1003
- children: "02.July.2024"
1004
- })]
1037
+ children: dropdownList.map((dropdown, index) => {
1038
+ return /*#__PURE__*/(0, _jsxRuntime.jsx)(_HistoryDropdownItem.default, {
1039
+ data: dropdown,
1040
+ setDate: setSelectedDate,
1041
+ handlePopoverClose: handlePopoverClose
1042
+ }, index);
1043
+ })
1005
1044
  })]
1006
1045
  })
1007
1046
  })]
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dmed-voice-assistant",
3
- "version": "1.2.3",
3
+ "version": "1.2.4",
4
4
  "main": "dist/index.js",
5
5
  "files": [
6
6
  "dist"