Skip to content

Commit

Permalink
Merge pull request #1422 from scut-chenzk/chenzk
Browse files Browse the repository at this point in the history
修复接语音回复失效的问题
  • Loading branch information
zhayujie authored Sep 15, 2023
2 parents 5338106 + 652b786 commit 28be141
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 5 deletions.
6 changes: 4 additions & 2 deletions channel/chat_channel.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,8 +202,10 @@ def _generate_reply(self, context: Context, reply: Reply = Reply()) -> Reply:
reply = self._generate_reply(new_context)
else:
return
elif context.type == ContextType.IMAGE or context.type == ContextType.FUNCTION \
or context.type == ContextType.FILE: # 图片/文件消息及函数调用等,当前无默认逻辑
elif context.type == ContextType.IMAGE: # 图片消息,当前仅做下载保存到本地的逻辑
cmsg = context["msg"]
cmsg.prepare()
elif context.type == ContextType.FUNCTION or context.type == ContextType.FILE: # 文件消息及函数调用等,当前无默认逻辑
pass
else:
logger.error("[WX] unknown context type: {}".format(context.type))
Expand Down
3 changes: 3 additions & 0 deletions channel/wework/wework_channel.py
Original file line number Diff line number Diff line change
Expand Up @@ -319,5 +319,8 @@ def send(self, reply: Reply, context: Context):
wework.send_video(receiver, video_path)
logger.info("[WX] sendVideo, receiver={}".format(receiver))
elif reply.type == ReplyType.VOICE:
current_dir = os.getcwd()
voice_file = reply.content.split("/")[-1]
reply.content = os.path.join(current_dir, "tmp", voice_file)
wework.send_file(receiver, reply.content)
logger.info("[WX] sendFile={}, receiver={}".format(reply.content, receiver))
12 changes: 9 additions & 3 deletions channel/wework/wework_message.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,16 +39,16 @@ def get_room_info(wework, conversation_id):

def cdn_download(wework, message, file_name):
data = message["data"]
url = data["cdn"]["url"]
auth_key = data["cdn"]["auth_key"]
aes_key = data["cdn"]["aes_key"]
file_size = data["cdn"]["size"]
file_type = 2
file_id = data["cdn"]["file_id"]

# 获取当前工作目录,然后与文件名拼接得到保存路径
current_dir = os.getcwd()
save_path = os.path.join(current_dir, "tmp", file_name)

result = wework.wx_cdn_download(url, auth_key, aes_key, file_size, save_path)
result = wework.c2c_cdn_download(file_id, aes_key, file_size, file_type, save_path)
logger.debug(result)


Expand All @@ -69,6 +69,12 @@ def c2c_download_and_convert(wework, message, file_name):
wav_file = base_name + ".wav"
pilk.silk_to_wav(save_path, wav_file, rate=24000)

# 删除SILK文件
try:
os.remove(save_path)
except Exception as e:
pass


class WeworkMessage(ChatMessage):
def __init__(self, wework_msg, wework, is_group=False):
Expand Down

0 comments on commit 28be141

Please sign in to comment.