51 lines
1.3 KiB
JavaScript
51 lines
1.3 KiB
JavaScript
"use strict";
|
|
const common_vendor = require("../../../../common/vendor.js");
|
|
const _Convertor = class _Convertor {
|
|
constructor() {
|
|
this.isUseCache = true;
|
|
this.convertCache = /* @__PURE__ */ new Map();
|
|
}
|
|
static getInstance() {
|
|
if (!_Convertor.instance) {
|
|
_Convertor.instance = new _Convertor();
|
|
}
|
|
return _Convertor.instance;
|
|
}
|
|
async get(message) {
|
|
if (this.isUseCache) {
|
|
const cache = this.convertCache.get(message.ID);
|
|
if (cache !== void 0) {
|
|
return cache;
|
|
}
|
|
}
|
|
const currentMessage = common_vendor.Jt.getMessageModel(message.ID);
|
|
if (!currentMessage) {
|
|
return Promise.reject("message not found");
|
|
}
|
|
const response = await common_vendor.Qt.convertVoiceToText({
|
|
message: currentMessage
|
|
});
|
|
let { data: { result } = {} } = response;
|
|
if (result) {
|
|
this.convertCache.set(currentMessage.ID, result);
|
|
} else {
|
|
result = "";
|
|
}
|
|
return result;
|
|
}
|
|
clear() {
|
|
this.convertCache.clear();
|
|
}
|
|
disableCache() {
|
|
this.isUseCache = false;
|
|
}
|
|
enableCache() {
|
|
this.isUseCache = true;
|
|
}
|
|
};
|
|
_Convertor.instance = void 0;
|
|
let Convertor = _Convertor;
|
|
const convertor = Convertor.getInstance();
|
|
exports.convertor = convertor;
|
|
//# sourceMappingURL=../../../../../.sourcemap/mp-weixin/TUIKit/components/TUIChat/utils/convertVoiceToText.js.map
|