@myun/gimi-chat 0.8.5 → 0.8.7

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.
@@ -69,7 +69,7 @@ export interface StartMessageParams {
69
69
  pitch?: number;
70
70
  };
71
71
  }
72
- declare class VoiceRecorder {
72
+ export declare class VoiceRecorder {
73
73
  private mediaRecorder;
74
74
  private audioPlayer;
75
75
  private ws;
@@ -83,7 +83,7 @@ declare class VoiceRecorder {
83
83
  private unbindNetworkEvents;
84
84
  private initStreamingAudioPlayer;
85
85
  convertFloat32ToInt16(float32Array: Float32Array): Int16Array;
86
- connectHandler(modeType: HandlerModeType): Promise<void>;
86
+ connectHandler(modeType: HandlerModeType, token: string, baseUrl: string): Promise<void>;
87
87
  startHandler(modeType: HandlerModeType, msgPrams?: StartMessageParams | null): Promise<void>;
88
88
  toggleRecord(): Promise<void>;
89
89
  stopRecordingEvent(): Promise<void>;
@@ -95,7 +95,7 @@ declare class VoiceRecorder {
95
95
  recordAndRecognize: () => Promise<void>;
96
96
  recordingClick(data: {
97
97
  modeType?: string;
98
- }, msgPrams?: StartMessageParams | null, callBack?: () => void): Promise<void>;
98
+ }, msgPrams?: StartMessageParams | null, callBack?: () => void, token?: string, baseUrl?: string): Promise<void>;
99
99
  writeString(view: DataView, offset: number, string: string): void;
100
100
  /**
101
101
  * 创建标准 WAV 格式的 Blob
@@ -107,11 +107,11 @@ declare class VoiceRecorder {
107
107
  */
108
108
  createWavBlob(pcmData: Int16Array, sampleRate: number, numChannels: number, bitsPerSample: number): Blob;
109
109
  blobToBase64(blob: Blob): Promise<string>;
110
- toggleTencentRecord(configuration?: Configuration | null, onResult?: (result: any) => void): Promise<void>;
110
+ toggleTencentRecord(configuration?: Configuration | null, onResult?: (result: any) => void, token?: string, baseUrl?: string): Promise<void>;
111
111
  /** 清理tencentRecorder */
112
112
  clearTencentRecorder(): void;
113
- callTencentAsrApi(base64Data: string, configuration?: Configuration | null): Promise<any | null>;
114
- startTTS(text?: string, msgPrams?: StartMessageParams | null): Promise<void>;
113
+ callTencentAsrApi(base64Data: string, configuration: Configuration | null | undefined, token: string, baseUrl: string): Promise<any | null>;
114
+ startTTS(text: string | undefined, msgPrams: StartMessageParams | null, token: string, baseUrl: string): Promise<void>;
115
115
  resetTTSPlayer(): void;
116
116
  sendTextForTTS(text: string): Promise<void>;
117
117
  }
@@ -14,7 +14,6 @@ function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key i
14
14
  function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
15
15
  function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
16
16
  import { createFetch } from "../apis/fetch";
17
- import { store } from "../store";
18
17
 
19
18
  // 定义业务场景枚举
20
19
  var HandlerMode = /*#__PURE__*/function (HandlerMode) {
@@ -43,7 +42,7 @@ var tencentRecorder = {
43
42
  processor: null
44
43
  // isRecording: false
45
44
  };
46
- var VoiceRecorder = /*#__PURE__*/function () {
45
+ export var VoiceRecorder = /*#__PURE__*/function () {
47
46
  function VoiceRecorder() {
48
47
  var _this = this;
49
48
  _classCallCheck(this, VoiceRecorder);
@@ -329,7 +328,7 @@ var VoiceRecorder = /*#__PURE__*/function () {
329
328
  }, {
330
329
  key: "connectHandler",
331
330
  value: function () {
332
- var _connectHandler = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(modeType) {
331
+ var _connectHandler = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(modeType, token, baseUrl) {
333
332
  var _this2 = this;
334
333
  return _regeneratorRuntime().wrap(function _callee2$(_context2) {
335
334
  while (1) switch (_context2.prev = _context2.next) {
@@ -337,8 +336,6 @@ var VoiceRecorder = /*#__PURE__*/function () {
337
336
  return _context2.abrupt("return", new Promise(function (resolve, reject) {
338
337
  // eslint-disable-next-line no-promise-executor-return
339
338
  if (_this2.ws && _this2.ws.readyState === WebSocket.OPEN) return resolve();
340
- var token = store.getState().gimiMenu.token;
341
- var baseUrl = store.getState().gimiMenu.baseUrl;
342
339
  try {
343
340
  var ws = new WebSocket("wss://".concat(baseUrl, "/mbot-wss/ws/voice?token=").concat(token));
344
341
  _this2.ws = ws;
@@ -437,7 +434,7 @@ var VoiceRecorder = /*#__PURE__*/function () {
437
434
  }
438
435
  }, _callee2);
439
436
  }));
440
- function connectHandler(_x3) {
437
+ function connectHandler(_x3, _x4, _x5) {
441
438
  return _connectHandler.apply(this, arguments);
442
439
  }
443
440
  return connectHandler;
@@ -537,7 +534,7 @@ var VoiceRecorder = /*#__PURE__*/function () {
537
534
  }
538
535
  }, _callee3, null, [[0, 14]]);
539
536
  }));
540
- return function (_x4, _x5) {
537
+ return function (_x6, _x7) {
541
538
  return _ref2.apply(this, arguments);
542
539
  };
543
540
  }());
@@ -593,7 +590,7 @@ var VoiceRecorder = /*#__PURE__*/function () {
593
590
  }
594
591
  }, _callee4, null, [[0, 16]]);
595
592
  }));
596
- return function (_x6, _x7) {
593
+ return function (_x8, _x9) {
597
594
  return _ref3.apply(this, arguments);
598
595
  };
599
596
  }()));
@@ -724,7 +721,7 @@ var VoiceRecorder = /*#__PURE__*/function () {
724
721
  }
725
722
  }, _callee7, this, [[1, 18]]);
726
723
  }));
727
- function recordingCancel(_x8) {
724
+ function recordingCancel(_x10) {
728
725
  return _recordingCancel.apply(this, arguments);
729
726
  }
730
727
  return recordingCancel;
@@ -733,7 +730,7 @@ var VoiceRecorder = /*#__PURE__*/function () {
733
730
  key: "recordingClick",
734
731
  value: // 核心录入音频入口
735
732
  function () {
736
- var _recordingClick = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee8(data, msgPrams, callBack) {
733
+ var _recordingClick = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee8(data, msgPrams, callBack, token, baseUrl) {
737
734
  var _data$modeType2, modeType, error, err;
738
735
  return _regeneratorRuntime().wrap(function _callee8$(_context8) {
739
736
  while (1) switch (_context8.prev = _context8.next) {
@@ -745,7 +742,7 @@ var VoiceRecorder = /*#__PURE__*/function () {
745
742
  }
746
743
  _context8.prev = 2;
747
744
  _context8.next = 5;
748
- return this.connectHandler(modeType);
745
+ return this.connectHandler(modeType, token || '', baseUrl || '');
749
746
  case 5:
750
747
  _context8.next = 7;
751
748
  return this.startHandler(modeType, msgPrams);
@@ -789,7 +786,7 @@ var VoiceRecorder = /*#__PURE__*/function () {
789
786
  }
790
787
  }, _callee8, this, [[2, 11], [17, 23]]);
791
788
  }));
792
- function recordingClick(_x9, _x10, _x11) {
789
+ function recordingClick(_x11, _x12, _x13, _x14, _x15) {
793
790
  return _recordingClick.apply(this, arguments);
794
791
  }
795
792
  return recordingClick;
@@ -876,6 +873,8 @@ var VoiceRecorder = /*#__PURE__*/function () {
876
873
  var _toggleTencentRecord = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee9() {
877
874
  var configuration,
878
875
  onResult,
876
+ token,
877
+ baseUrl,
879
878
  stream,
880
879
  audioContext,
881
880
  processor,
@@ -895,19 +894,21 @@ var VoiceRecorder = /*#__PURE__*/function () {
895
894
  case 0:
896
895
  configuration = _args9.length > 0 && _args9[0] !== undefined ? _args9[0] : null;
897
896
  onResult = _args9.length > 1 ? _args9[1] : undefined;
897
+ token = _args9.length > 2 ? _args9[2] : undefined;
898
+ baseUrl = _args9.length > 3 ? _args9[3] : undefined;
898
899
  if (!(!tencentRecorder.stream || !tencentRecorder.audioContext)) {
899
- _context9.next = 4;
900
+ _context9.next = 6;
900
901
  break;
901
902
  }
902
903
  throw new Error('腾讯云录音未初始化,无法停止');
903
- case 4:
904
- _context9.prev = 4;
904
+ case 6:
905
+ _context9.prev = 6;
905
906
  stream = tencentRecorder.stream, audioContext = tencentRecorder.audioContext, processor = tencentRecorder.processor, source = tencentRecorder.source;
906
907
  source === null || source === void 0 || source.disconnect();
907
908
  processor === null || processor === void 0 || processor.disconnect();
908
- _context9.next = 10;
909
+ _context9.next = 12;
909
910
  return audioContext.close();
910
- case 10:
911
+ case 12:
911
912
  stream.getTracks().forEach(function (track) {
912
913
  return track.stop();
913
914
  });
@@ -932,30 +933,30 @@ var VoiceRecorder = /*#__PURE__*/function () {
932
933
  _iterator2.f();
933
934
  }
934
935
  wavBlob = this.createWavBlob(mergedPcm, 16000, 1, 16); // 转换为 Base64
935
- _context9.next = 19;
936
+ _context9.next = 21;
936
937
  return this.blobToBase64(wavBlob);
937
- case 19:
938
+ case 21:
938
939
  base64Data = _context9.sent;
939
- _context9.next = 22;
940
- return this.callTencentAsrApi(base64Data, configuration);
941
- case 22:
940
+ _context9.next = 24;
941
+ return this.callTencentAsrApi(base64Data, configuration, token || '', baseUrl || '');
942
+ case 24:
942
943
  _data2 = _context9.sent;
943
944
  if (onResult) {
944
945
  onResult(_data2);
945
946
  }
946
947
  this.clearTencentRecorder();
947
- _context9.next = 31;
948
+ _context9.next = 33;
948
949
  break;
949
- case 27:
950
- _context9.prev = 27;
951
- _context9.t0 = _context9["catch"](4);
950
+ case 29:
951
+ _context9.prev = 29;
952
+ _context9.t0 = _context9["catch"](6);
952
953
  this.clearTencentRecorder();
953
954
  throw new Error(_context9.t0.message);
954
- case 31:
955
+ case 33:
955
956
  case "end":
956
957
  return _context9.stop();
957
958
  }
958
- }, _callee9, this, [[4, 27]]);
959
+ }, _callee9, this, [[6, 29]]);
959
960
  }));
960
961
  function toggleTencentRecord() {
961
962
  return _toggleTencentRecord.apply(this, arguments);
@@ -979,13 +980,14 @@ var VoiceRecorder = /*#__PURE__*/function () {
979
980
  value: function () {
980
981
  var _callTencentAsrApi = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee10(base64Data) {
981
982
  var configuration,
983
+ token,
984
+ baseUrl,
982
985
  engineModel,
983
986
  filterDirty,
984
987
  filterModal,
985
988
  filterPunc,
986
989
  convertNum,
987
990
  requestData,
988
- baseUrl,
989
991
  api,
990
992
  response_data,
991
993
  _result,
@@ -995,6 +997,8 @@ var VoiceRecorder = /*#__PURE__*/function () {
995
997
  while (1) switch (_context10.prev = _context10.next) {
996
998
  case 0:
997
999
  configuration = _args10.length > 1 && _args10[1] !== undefined ? _args10[1] : null;
1000
+ token = _args10.length > 2 ? _args10[2] : undefined;
1001
+ baseUrl = _args10.length > 3 ? _args10[3] : undefined;
998
1002
  engineModel = null;
999
1003
  filterDirty = null;
1000
1004
  filterModal = null;
@@ -1016,50 +1020,49 @@ var VoiceRecorder = /*#__PURE__*/function () {
1016
1020
  filterPunc: filterPunc,
1017
1021
  convertNumMode: convertNum
1018
1022
  };
1019
- _context10.prev = 8;
1020
- baseUrl = store.getState().gimiMenu.baseUrl;
1023
+ _context10.prev = 10;
1021
1024
  api = createFetch({
1022
1025
  baseURL: baseUrl,
1023
1026
  timeout: 10000,
1024
1027
  headers: {
1025
- 'Authorization': 'Bearer ' + store.getState().gimiMenu.token,
1028
+ 'Authorization': 'Bearer ' + token,
1026
1029
  'Content-Type': 'application/json'
1027
1030
  }
1028
1031
  });
1029
- _context10.next = 13;
1032
+ _context10.next = 14;
1030
1033
  return api.post("/mbot/api/tencent/asr/recognize", requestData);
1031
- case 13:
1034
+ case 14:
1032
1035
  response_data = _context10.sent;
1033
1036
  if (!(response_data.status !== 0)) {
1034
- _context10.next = 16;
1037
+ _context10.next = 17;
1035
1038
  break;
1036
1039
  }
1037
1040
  throw new Error('HTTP ' + response_data.status);
1038
- case 16:
1041
+ case 17:
1039
1042
  if (!(response_data.status === 0 && response_data.result)) {
1040
- _context10.next = 21;
1043
+ _context10.next = 22;
1041
1044
  break;
1042
1045
  }
1043
1046
  _result = response_data.result;
1044
1047
  return _context10.abrupt("return", _result);
1045
- case 21:
1048
+ case 22:
1046
1049
  // 处理接口级别的错误
1047
1050
  errorMsg = response_data.message || '请求失败';
1048
1051
  throw new Error(errorMsg);
1049
- case 23:
1050
- _context10.next = 28;
1052
+ case 24:
1053
+ _context10.next = 29;
1051
1054
  break;
1052
- case 25:
1053
- _context10.prev = 25;
1054
- _context10.t0 = _context10["catch"](8);
1055
+ case 26:
1056
+ _context10.prev = 26;
1057
+ _context10.t0 = _context10["catch"](10);
1055
1058
  throw new Error(_context10.t0.message);
1056
- case 28:
1059
+ case 29:
1057
1060
  case "end":
1058
1061
  return _context10.stop();
1059
1062
  }
1060
- }, _callee10, null, [[8, 25]]);
1063
+ }, _callee10, null, [[10, 26]]);
1061
1064
  }));
1062
- function callTencentAsrApi(_x12) {
1065
+ function callTencentAsrApi(_x16) {
1063
1066
  return _callTencentAsrApi.apply(this, arguments);
1064
1067
  }
1065
1068
  return callTencentAsrApi;
@@ -1067,14 +1070,14 @@ var VoiceRecorder = /*#__PURE__*/function () {
1067
1070
  }, {
1068
1071
  key: "startTTS",
1069
1072
  value: function () {
1070
- var _startTTS = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee11(text, msgPrams) {
1073
+ var _startTTS = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee11(text, msgPrams, token, baseUrl) {
1071
1074
  return _regeneratorRuntime().wrap(function _callee11$(_context11) {
1072
1075
  while (1) switch (_context11.prev = _context11.next) {
1073
1076
  case 0:
1074
1077
  this.ttsSessionId++;
1075
1078
  _context11.prev = 1;
1076
1079
  _context11.next = 4;
1077
- return this.connectHandler(HandlerMode.TTS_ONLY);
1080
+ return this.connectHandler(HandlerMode.TTS_ONLY, token, baseUrl);
1078
1081
  case 4:
1079
1082
  _context11.next = 6;
1080
1083
  return this.startHandler(HandlerMode.TTS_ONLY, msgPrams);
@@ -1098,7 +1101,7 @@ var VoiceRecorder = /*#__PURE__*/function () {
1098
1101
  }
1099
1102
  }, _callee11, this, [[1, 11]]);
1100
1103
  }));
1101
- function startTTS(_x13, _x14) {
1104
+ function startTTS(_x17, _x18, _x19, _x20) {
1102
1105
  return _startTTS.apply(this, arguments);
1103
1106
  }
1104
1107
  return startTTS;
@@ -1150,7 +1153,7 @@ var VoiceRecorder = /*#__PURE__*/function () {
1150
1153
  }
1151
1154
  }, _callee12);
1152
1155
  }));
1153
- function sendTextForTTS(_x15) {
1156
+ function sendTextForTTS(_x21) {
1154
1157
  return _sendTextForTTS.apply(this, arguments);
1155
1158
  }
1156
1159
  return sendTextForTTS;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@myun/gimi-chat",
3
- "version": "0.8.5",
3
+ "version": "0.8.7",
4
4
  "description": "> TODO: description",
5
5
  "homepage": "",
6
6
  "license": "ISC",