mirror of
https://github.com/zhayujie/chatgpt-on-wechat.git
synced 2026-06-02 00:57:41 +08:00
feat(wechatcomapp): add support for splitting long audio files
This commit is contained in:
@@ -19,7 +19,7 @@ from common.log import logger
|
||||
from common.singleton import singleton
|
||||
from common.utils import compress_imgfile, fsize, split_string_by_utf8_length
|
||||
from config import conf, subscribe_msg
|
||||
from voice.audio_convert import any_to_amr
|
||||
from voice.audio_convert import any_to_amr, split_audio
|
||||
|
||||
MAX_UTF8_LEN = 2048
|
||||
|
||||
@@ -66,8 +66,12 @@ class WechatComAppChannel(ChatChannel):
|
||||
file_path = reply.content
|
||||
amr_file = os.path.splitext(file_path)[0] + ".amr"
|
||||
any_to_amr(file_path, amr_file)
|
||||
response = self.client.media.upload("voice", open(amr_file, "rb"))
|
||||
logger.debug("[wechatcom] upload voice response: {}".format(response))
|
||||
files = split_audio(amr_file, 60000)
|
||||
if len(files) > 1:
|
||||
logger.info("[wechatcom] voice too long, split into {} parts".format(len(files)))
|
||||
for path in files:
|
||||
response = self.client.media.upload("voice", open(path, "rb"))
|
||||
logger.debug("[wechatcom] upload voice response: {}".format(response))
|
||||
except WeChatClientException as e:
|
||||
logger.error("[wechatcom] upload voice failed: {}".format(e))
|
||||
return
|
||||
|
||||
Reference in New Issue
Block a user