wx2tg-puppet 2.1.6 → 2.1.8

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.
@@ -21,6 +21,7 @@ const EMOJI_1 = require("../core/EMOJI");
21
21
  const VOICE_1 = require("../core/VOICE");
22
22
  const ToolsApi_1 = require("../api/ToolsApi");
23
23
  const Message_1 = require("../core/Message");
24
+ const audioUtil_1 = require("../utils/audioUtil");
24
25
  // 检查是否是 Contact 类组成的数组
25
26
  function isArrayOfContact(arr) {
26
27
  // 先判断是否是数组
@@ -188,6 +189,15 @@ const say = (content, toWxid, ats) => __awaiter(void 0, void 0, void 0, function
188
189
  return new Message_1.ResponseMsg(res.data.Data);
189
190
  }
190
191
  else if (content instanceof VOICE_1.Voice) {
192
+ if (content.type === 2) {
193
+ const fileName = new Date().getTime();
194
+ const fb = file_box_1.FileBox.fromBase64(content.voiceBase64);
195
+ yield fb.toFile(fileName + '.mp3', true);
196
+ yield new audioUtil_1.SilkToMp3Converter().convertToSilk(fileName + '.mp3', fileName + '.silk');
197
+ const fbResult = file_box_1.FileBox.fromFile(fileName + '.silk');
198
+ content.voiceBase64 = yield fbResult.toBase64();
199
+ content.type = 4;
200
+ }
191
201
  const res = yield MsgApi_1.msgApi.SendVoice({
192
202
  "Base64": content.voiceBase64,
193
203
  "ToWxid": toWxid,
@@ -6,4 +6,11 @@ export declare class SilkToMp3Converter {
6
6
  * @returns A promise that resolves when the conversion is complete.
7
7
  */
8
8
  convertToMp3(inputFilePath: string, outputFilePath: string): Promise<void>;
9
+ /**
10
+ * Converts a Silk file to MP3 format.
11
+ * @param inputFilePath - The path to the Silk file.
12
+ * @param outputFilePath - The desired path for the MP3 file.
13
+ * @returns A promise that resolves when the conversion is complete.
14
+ */
15
+ convertToSilk(inputFilePath: string, outputFilePath: string): Promise<void>;
9
16
  }
@@ -15,5 +15,18 @@ class SilkToMp3Converter {
15
15
  voice.decode(inputFilePath, outputFilePath, { format: "mp3" }, (file) => resolve());
16
16
  });
17
17
  }
18
+ /**
19
+ * Converts a Silk file to MP3 format.
20
+ * @param inputFilePath - The path to the Silk file.
21
+ * @param outputFilePath - The desired path for the MP3 file.
22
+ * @returns A promise that resolves when the conversion is complete.
23
+ */
24
+ convertToSilk(inputFilePath, outputFilePath) {
25
+ return new Promise((resolve, reject) => {
26
+ const WxVoice = require('wx-voice');
27
+ const voice = new WxVoice();
28
+ voice.encode(inputFilePath, outputFilePath, { format: "silk" }, (file) => resolve());
29
+ });
30
+ }
18
31
  }
19
32
  exports.SilkToMp3Converter = SilkToMp3Converter;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "wx2tg-puppet",
3
- "version": "2.1.6",
3
+ "version": "2.1.8",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "files": [