tanlie 1 год назад
Родитель
Сommit
609ef22a64
1 измененных файлов с 4 добавлено и 13 удалено
  1. 4 13
      channel/wechatcom/wechatcomapp_channel.py

+ 4 - 13
channel/wechatcom/wechatcomapp_channel.py

@@ -69,27 +69,18 @@ class WechatComAppChannel(ChatChannel):
             try:
                 media_ids = []
                 file_path = reply.content
-                amr_file = os.path.splitext(file_path)[0] + ".amr"
-                any_to_mp3(file_path, amr_file)
-                duration, files = split_audio(amr_file, 60 * 1000)
-                if len(files) > 1:
-                    logger.info("[wechatcom] voice too long {}s > 60s , split into {} parts".format(duration / 1000.0,
-                                                                                                    len(files)))
-                for path in files:
-                    response = self.client.media.upload("voice", open(path, "rb"))
-                    logger.debug("[wechatcom] upload voice response: {}".format(response))
-                    media_ids.append(response["media_id"])
+                response = self.client.media.upload("file", open(file_path, "rb"))
+                logger.debug("[wechatcom] upload voice response: {}".format(response))
+                media_ids.append(response["media_id"])
             except WeChatClientException as e:
                 logger.error("[wechatcom] upload voice failed: {}".format(e))
                 return
             try:
                 os.remove(file_path)
-                if amr_file != file_path:
-                    os.remove(amr_file)
             except Exception:
                 pass
             for media_id in media_ids:
-                self.client.message.send_voice(self.agent_id, receiver, media_id)
+                self.client.message.send_file(self.agent_id, receiver, media_id)
                 time.sleep(1)
             logger.info("[wechatcom] sendVoice={}, receiver={}".format(reply.content, receiver))
         elif reply.type == ReplyType.IMAGE_URL:  # 从网络下载图片