From 8cc5c62b1e2571096fe687c50d9da3d2682b32b5 Mon Sep 17 00:00:00 2001 From: liuwei Date: Thu, 29 May 2025 17:21:48 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E5=8F=91=E8=AF=AD=E9=9F=B3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- wechat_ipad/client/message.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/wechat_ipad/client/message.py b/wechat_ipad/client/message.py index 9e31c5a..c1b3109 100644 --- a/wechat_ipad/client/message.py +++ b/wechat_ipad/client/message.py @@ -332,21 +332,23 @@ class MessageMixin(WechatAPIClientBase): voice_byte = f.read() else: raise ValueError("voice should be str, bytes, or path") - + voice_type = 0 # get voice duration and b64 if format.lower() == "amr": audio = AudioSegment.from_file(BytesIO(voice_byte), format="amr") voice_base64 = base64.b64encode(voice_byte).decode() elif format.lower() == "wave": - audio = AudioSegment.from_file(BytesIO(voice_byte), format="wav").set_channels(1) + audio = AudioSegment.from_file(BytesIO(voice_byte), format="wav").set_channels(2) 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() + voice_type = 4 elif format.lower() == "mp3": - audio = AudioSegment.from_file(BytesIO(voice_byte), format="mp3").set_channels(1) + audio = AudioSegment.from_file(BytesIO(voice_byte), format="mp3").set_channels(2) 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() + voice_type = 4 else: raise ValueError("format must be one of amr, wav, mp3") @@ -362,7 +364,7 @@ class MessageMixin(WechatAPIClientBase): # } async with aiohttp.ClientSession() as session: json_param = {"Wxid": self.wxid, "ToWxid": wxid, "Base64": voice_base64, "VoiceTime": duration, - "Type": format_dict[format]} + "Type": voice_type} response = await session.post(f'http://{self.ip}:{self.port}/api/Msg/SendVoice', json=json_param) json_resp = await response.json()