From 25a847da108d7b9887c0d13dd3fa5efe73ec610c Mon Sep 17 00:00:00 2001 From: liuwei Date: Mon, 26 May 2025 15:02:57 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B5=8B=E8=AF=95=E9=9F=B3=E4=B9=90=E4=BF=A1?= =?UTF-8?q?=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- plugins/music/main.py | 2 +- wechat_ipad/client/message.py | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/plugins/music/main.py b/plugins/music/main.py index e004f78..a6131fd 100644 --- a/plugins/music/main.py +++ b/plugins/music/main.py @@ -212,7 +212,7 @@ class MusicPlugin(MessagePluginInterface): res = await bot.send_app_message(wxid=receiver, xml=xml_message, type=0) self.LOG.info(f"发送音乐消息 res:{res}") voice_base64 = await self.url_to_base64(play_url) - res = await bot.send_voice_message(wxid=receiver, voice=voice_base64) + res = await bot.send_voice_message(wxid=receiver, voice=voice_base64,format="AMR") self.LOG.info(f"发送音乐消息 voice res:{res}") return True diff --git a/wechat_ipad/client/message.py b/wechat_ipad/client/message.py index 5eecfe0..8c3d1f0 100644 --- a/wechat_ipad/client/message.py +++ b/wechat_ipad/client/message.py @@ -320,15 +320,15 @@ class MessageMixin(WechatAPIClientBase): raise ValueError("voice should be str, bytes, or path") # get voice duration and b64 - if format.lower() == "AMR": + if format.lower() == "amr": audio = AudioSegment.from_file(BytesIO(voice_byte), format="amr") voice_base64 = base64.b64encode(voice_byte).decode() - elif format.lower() == "WAVE": + elif format.lower() == "wave": audio = AudioSegment.from_file(BytesIO(voice_byte), format="wav").set_channels(1) audio = audio.set_frame_rate(self._get_closest_frame_rate(audio.frame_rate)) voice_base64 = base64.b64encode( await pysilk.async_encode(audio.raw_data, sample_rate=audio.frame_rate)).decode() - elif format.lower() == "MP3": + elif format.lower() == "mp3": audio = AudioSegment.from_file(BytesIO(voice_byte), format="mp3").set_channels(1) audio = audio.set_frame_rate(self._get_closest_frame_rate(audio.frame_rate)) voice_base64 = base64.b64encode( @@ -338,7 +338,7 @@ class MessageMixin(WechatAPIClientBase): duration = len(audio) # Type: AMR = 0, MP3 = 2, SILK = 4, SPEEX = 1, WAVE = 3 VoiceTime :音频长度 1000为一秒 - format_dict = {"AMR": 0, "WAVE": 3, "MP3": 2, "SILK": 4, "SPEEX": 1} + format_dict = {"amr": 0, "wave": 3, "mpe3": 2, "silk": 4, "speex": 1} # { # "Base64": "string", # "ToWxid": "string",