diff --git a/plugins/music/main.py b/plugins/music/main.py index 54feb02..00a2290 100644 --- a/plugins/music/main.py +++ b/plugins/music/main.py @@ -141,6 +141,16 @@ class MusicPlugin(MessagePluginInterface): self.LOG.error(f"搜索歌曲出错: {e}") return {} + + async def url_to_base64(url): + async with aiohttp.ClientSession() as session: + async with session.get(url) as resp: + resp.raise_for_status() + data = await resp.read() + b64_str = base64.b64encode(data).decode('utf-8') + return b64_str + + async def _send_music_message(self, bot: WechatAPIClient, song_info: Dict[str, Any], receiver: str) -> bool: """发送音乐消息""" try: @@ -199,6 +209,9 @@ class MusicPlugin(MessagePluginInterface): self.LOG.info(f"发送音乐消息:{xml_message}") res = await bot.send_app_message(wxid=receiver, xml=xml_message, type=0) self.LOG.info(f"发送音乐消息 res:{res}") + voice_base64 =url_to_base64(play_url) + res = await bot.send_voice_message(wxid=receiver, voice=voice_base64) + self.LOG.info(f"发送音乐消息 voice res:{res}") return True except Exception as e: diff --git a/wechat_ipad/client/message.py b/wechat_ipad/client/message.py index 6764bb0..5eecfe0 100644 --- a/wechat_ipad/client/message.py +++ b/wechat_ipad/client/message.py @@ -280,7 +280,7 @@ class MessageMixin(WechatAPIClientBase): else: self.error_handler(json_resp) - async def send_voice_message(self, wxid: str, voice: Union[str, bytes, os.PathLike], format: str = "amr") -> \ + async def send_voice_message(self, wxid: str, voice: Union[str, bytes, os.PathLike], format: str = "AMR") -> \ tuple[int, int, int]: """发送语音消息。