tanlie před 1 rokem
rodič
revize
2fe31b84c8
1 změnil soubory, kde provedl 9 přidání a 4 odebrání
  1. 9 4
      channel/wechatcom/wechatcomapp_channel.py

+ 9 - 4
channel/wechatcom/wechatcomapp_channel.py

@@ -19,7 +19,7 @@ from common.log import logger
 from common.singleton import singleton
 from common.singleton import singleton
 from common.utils import compress_imgfile, fsize, split_string_by_utf8_length
 from common.utils import compress_imgfile, fsize, split_string_by_utf8_length
 from config import conf, subscribe_msg
 from config import conf, subscribe_msg
-from voice.audio_convert import any_to_amr, split_audio
+from voice.audio_convert import any_to_amr, split_audio, any_to_mp3
 
 
 MAX_UTF8_LEN = 2048
 MAX_UTF8_LEN = 2048
 
 
@@ -37,7 +37,11 @@ class WechatComAppChannel(ChatChannel):
         self.aes_key = conf().get("wechatcomapp_aes_key")
         self.aes_key = conf().get("wechatcomapp_aes_key")
         print(self.corp_id, self.secret, self.agent_id, self.token, self.aes_key)
         print(self.corp_id, self.secret, self.agent_id, self.token, self.aes_key)
         logger.info(
         logger.info(
-            "[wechatcom] init: corp_id: {}, secret: {}, agent_id: {}, token: {}, aes_key: {}".format(self.corp_id, self.secret, self.agent_id, self.token, self.aes_key)
+            "[wechatcom] init: corp_id: {}, secret: {}, agent_id: {}, token: {}, aes_key: {}".format(self.corp_id,
+                                                                                                     self.secret,
+                                                                                                     self.agent_id,
+                                                                                                     self.token,
+                                                                                                     self.aes_key)
         )
         )
         self.crypto = WeChatCrypto(self.token, self.aes_key, self.corp_id)
         self.crypto = WeChatCrypto(self.token, self.aes_key, self.corp_id)
         self.client = WechatComAppClient(self.corp_id, self.secret)
         self.client = WechatComAppClient(self.corp_id, self.secret)
@@ -66,10 +70,11 @@ class WechatComAppChannel(ChatChannel):
                 media_ids = []
                 media_ids = []
                 file_path = reply.content
                 file_path = reply.content
                 amr_file = os.path.splitext(file_path)[0] + ".amr"
                 amr_file = os.path.splitext(file_path)[0] + ".amr"
-                any_to_amr(file_path, amr_file)
+                any_to_mp3(file_path, amr_file)
                 duration, files = split_audio(amr_file, 60 * 1000)
                 duration, files = split_audio(amr_file, 60 * 1000)
                 if len(files) > 1:
                 if len(files) > 1:
-                    logger.info("[wechatcom] voice too long {}s > 60s , split into {} parts".format(duration / 1000.0, len(files)))
+                    logger.info("[wechatcom] voice too long {}s > 60s , split into {} parts".format(duration / 1000.0,
+                                                                                                    len(files)))
                 for path in files:
                 for path in files:
                     response = self.client.media.upload("voice", open(path, "rb"))
                     response = self.client.media.upload("voice", open(path, "rb"))
                     logger.debug("[wechatcom] upload voice response: {}".format(response))
                     logger.debug("[wechatcom] upload voice response: {}".format(response))