From ca6cb60bdd3af5dd7354807964325adeb6e20e8c Mon Sep 17 00:00:00 2001 From: shockno1 <128016038+shockno1@users.noreply.github.com> Date: Wed, 26 Feb 2025 12:45:28 +0800 Subject: [PATCH] =?UTF-8?q?Update=20gewechat.py=20=E6=B7=BB=E5=8A=A0gewe?= =?UTF-8?q?=E5=BE=AE=E4=BF=A1=E6=8E=A5=E5=8F=A3=E4=B8=ADvoice=E8=AF=AD?= =?UTF-8?q?=E9=9F=B3=E7=9A=84=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 添加gewe微信接口中voice语音的处理 --- pkg/platform/sources/gewechat.py | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/pkg/platform/sources/gewechat.py b/pkg/platform/sources/gewechat.py index 1b620243..ddd88e1c 100644 --- a/pkg/platform/sources/gewechat.py +++ b/pkg/platform/sources/gewechat.py @@ -43,8 +43,11 @@ class GewechatMessageConverter(adapter.MessageConverter): elif isinstance(component, platform_message.Plain): content_list.append({"type": "text", "content": component.text}) elif isinstance(component, platform_message.Image): + content_list.append({"type": "image", "url": component.url}) # content_list.append({"type": "image", "image_id": component.image_id}) - pass + #pass + elif isinstance(component, platform_message.Voice): + content_list.append({"type": "voice", "url": component.url, "length": component.length}) elif isinstance(component, platform_message.Forward): for node in component.node_list: content_list.extend(await GewechatMessageConverter.yiri2target(node.message_chain)) @@ -103,7 +106,11 @@ class GewechatMessageConverter(adapter.MessageConverter): return platform_message.MessageChain([ platform_message.Plain(text="[图片处理失败]") ]) - + elif message["Data"]["MsgType"] == 34: + audio_base64 = message["Data"]["ImgBuf"]["buffer"] + return platform_message.MessageChain( + [platform_message.Voice(base64=f"data:audio/silk;base64,{audio_base64}")] + ) elif message["Data"]["MsgType"] == 49: # 支持微信聊天记录的消息类型,将 XML 内容转换为 MessageChain 传递 try: @@ -336,4 +343,4 @@ class GeWeChatAdapter(adapter.MessagePlatformAdapter): ) async def kill(self) -> bool: - pass \ No newline at end of file + pass